You can get the contents of the file with blob.getContent, but it will be a problem if the file size is large.
Bucket bucket = getBucket(bucketName);
Storage.BlobListOption option = Storage.BlobListOption.prefix(directory);
Page<Blob> blobs = bucket.list(option);
Iterator<Blob> iterator = blobs.iterateAll().iterator();
List<String> csvList = new ArrayList<>();
while (iterator.hasNext()) {
Blob blob = iterator.next();
byte[] content = blob.getContent(Blob.BlobSourceOption.generationMatch());
csvList.add(new String(content));
}
for (String csv : csvList) {
// process...
}
Instead of getContent, you can read and process line by line as follows
ReadChannel readChannel = blob.reader();
BufferedReader br = new BufferedReader(Channels.newReader(readChannel, "UTF-8"));
String line;
while((line = br.readLine()) != null){
// process...
}
Recommended Posts