This is an automated email from the ASF dual-hosted git repository.

amoghj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new 82bce4f105 AWS: Replace FileOutputStream/InputStream constructor with 
NIO Files APIs (#8626)
82bce4f105 is described below

commit 82bce4f1055f79f387e79ec39eebb675d148c6fb
Author: Amogh Jahagirdar <[email protected]>
AuthorDate: Mon Sep 25 11:34:27 2023 -0700

    AWS: Replace FileOutputStream/InputStream constructor with NIO Files APIs 
(#8626)
---
 .../java/org/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 f66c9b7f35..046abdb61e 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.BufferedInputStream;
 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 @@ class S3OutputStream extends PositionOutputStream {
     }
 
     stagingFiles.add(new FileAndDigest(currentStagingFile, 
currentPartMessageDigest));
+    OutputStream outputStream = 
Files.newOutputStream(currentStagingFile.toPath());
 
     if (isChecksumEnabled) {
       DigestOutputStream digestOutputStream;
@@ -236,22 +236,18 @@ class S3OutputStream extends PositionOutputStream {
       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 @@ class S3OutputStream extends PositionOutputStream {
 
   private static InputStream uncheckedInputStream(File file) {
     try {
-      return new FileInputStream(file);
+      return Files.newInputStream(file.toPath());
     } catch (IOException e) {
       throw new UncheckedIOException(e);
     }

Reply via email to