From 82bce4f1055f79f387e79ec39eebb675d148c6fb Mon Sep 17 00:00:00 2001 From: Amogh Jahagirdar Date: Mon, 25 Sep 2023 11:34:27 -0700 Subject: [PATCH] AWS: Replace FileOutputStream/InputStream constructor with NIO Files APIs (#8626) --- .../apache/iceberg/aws/s3/S3OutputStream.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/aws/src/main/java/org/apache/iceberg/aws/s3/S3OutputStream.java b/aws/src/main/java/org/apache/iceberg/aws/s3/S3OutputStream.java index f66c9b7f3533..046abdb61e13 100644 --- a/aws/src/main/java/org/apache/iceberg/aws/s3/S3OutputStream.java +++ b/aws/src/main/java/org/apache/iceberg/aws/s3/S3OutputStream.java @@ -22,10 +22,9 @@ import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.io.SequenceInputStream; import java.io.UncheckedIOException; import java.nio.file.Files; @@ -228,6 +227,7 @@ private void newStream() throws IOException { } stagingFiles.add(new FileAndDigest(currentStagingFile, currentPartMessageDigest)); + OutputStream outputStream = Files.newOutputStream(currentStagingFile.toPath()); if (isChecksumEnabled) { DigestOutputStream digestOutputStream; @@ -236,22 +236,18 @@ private void newStream() throws IOException { if (multipartUploadId != null) { digestOutputStream = new DigestOutputStream( - new BufferedOutputStream(new FileOutputStream(currentStagingFile)), - currentPartMessageDigest); + new BufferedOutputStream(outputStream), currentPartMessageDigest); } else { digestOutputStream = new DigestOutputStream( new DigestOutputStream( - new BufferedOutputStream(new FileOutputStream(currentStagingFile)), - currentPartMessageDigest), + new BufferedOutputStream(outputStream), currentPartMessageDigest), completeMessageDigest); } stream = new CountingOutputStream(digestOutputStream); } else { - stream = - new CountingOutputStream( - new BufferedOutputStream(new FileOutputStream(currentStagingFile))); + stream = new CountingOutputStream(new BufferedOutputStream(outputStream)); } } @@ -451,7 +447,7 @@ private void completeUploads() { private static InputStream uncheckedInputStream(File file) { try { - return new FileInputStream(file); + return Files.newInputStream(file.toPath()); } catch (IOException e) { throw new UncheckedIOException(e); }