Skip to content

Commit

Permalink
Use InputStream#transferTo instead of readAllBytes (#6477)
Browse files Browse the repository at this point in the history
InputStream#transferTo has been available since Java 9 and provides a
built in method to drain an InputStream to an OutputStream without
requiring loading the entire contents of the stream into memory.

Signed-off-by: Andrew Ross <[email protected]>
  • Loading branch information
andrross authored Feb 24, 2023
1 parent 95bd076 commit 261f22c
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private IndexInput downloadBlockLocally(BlobFetchRequest blobFetchRequest) throw
OutputStream fileOutputStream = Files.newOutputStream(blobFetchRequest.getFilePath());
OutputStream localFileOutputStream = new BufferedOutputStream(fileOutputStream);
) {
localFileOutputStream.write(snapshotFileInputStream.readAllBytes());
snapshotFileInputStream.transferTo(localFileOutputStream);
}
return blobFetchRequest.getDirectory().openInput(blobFetchRequest.getFileName(), IOContext.READ);
}
Expand Down

0 comments on commit 261f22c

Please sign in to comment.