use of com.mongodb.MongoGridFSException in project mongo-java-driver by mongodb.
the class SyncGridFSBucket method inputStreamToFlux.
@SuppressWarnings("BlockingMethodInNonBlockingContext")
private Flux<ByteBuffer> inputStreamToFlux(final InputStream source, final GridFSUploadOptions options) {
List<ByteBuffer> byteBuffers = new ArrayList<>();
int chunkSize = options.getChunkSizeBytes() == null ? wrapped.getChunkSizeBytes() : options.getChunkSizeBytes();
byte[] buffer = new byte[chunkSize];
try {
int len;
while ((len = source.read(buffer)) != -1) {
byteBuffers.add(ByteBuffer.wrap(buffer, 0, len));
buffer = new byte[chunkSize];
}
return Flux.fromIterable(byteBuffers);
} catch (IOException e) {
throw new MongoGridFSException("IOException when reading from the InputStream", e);
}
}
use of com.mongodb.MongoGridFSException in project mongo-java-driver by mongodb.
the class SyncGridFSBucket method toOutputStream.
private void toOutputStream(final GridFSDownloadPublisher downloadPublisher, final OutputStream destination) {
Flux.from(downloadPublisher).toStream().forEach(byteBuffer -> {
try {
byte[] bytes = new byte[byteBuffer.remaining()];
byteBuffer.get(bytes);
destination.write(bytes);
} catch (IOException e) {
throw new MongoGridFSException("IOException when reading from the OutputStream", e);
}
});
}
Aggregations