piotrpo
piotrpo

Reputation: 12636

GAE Blob service - how to process uploaded file

My app allows to upload csv file with some data. I want to extract those data and upload them into datastore, but let's assume for this question, that I just want to count lines in text file. What is the best approach to make that task done. Could you give me some code sniplet?

public int countLines(BlobKey key){
  //mising code
}

Upvotes: 1

Views: 346

Answers (1)

Kal
Kal

Reputation: 24910

The BlobstoreInputStream extends InputStream so you can do something like this --

public int countLines(BlobKey key) throws Exception {
          BlobstoreInputStream bsis = new BlobstoreInputStream(key);
          BufferedReader br = new BufferedReader(new InputStreamReader(bsis));

          int lineCount = 0;
          while ( br.readLine() != null ) 
                 lineCount++;

          return lineCount;
}

Upvotes: 3

Related Questions