I have on bucket XLS
file and I have to pull the file and read the data on the stream and work with data. I worked with CSV
file and this is my code:
try (ReadChannel reader = storage.reader(bucketName, fileName)) {
ByteBuffer bytes = ByteBuffer.allocate(BUFFER_SIZE);
while (reader.read(bytes) > 0) {
bytes.flip();
// outChannel.write(bytes);
set(new String(bytes.array(), "UTF-8"), fileName);
bytes.clear();
}
}
I think this might be what you are looking for. GCS Input Channel
GcsService gcsService = GcsServiceFactory.createGcsService();
GcsFilename fileName = new GcsFilename("TestBucket", "Test1.xlsx");
GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(fileName, 0, BUFFER_SIZE);
InputStream inputStream = Channels.newInputStream(readChannel);
I've also found an interesting workaround that might help you, in this answer you have a piece of code that converts all the excel files to CSV to let you manipulate them as normal if you wish to.
EDIT: The error was there because it was not initialized. Have a look at my code edit.
In your case as far as I understood you might need to use " OutputChannel " not "InputChannel" but it's the same concept.
Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.