Skip to content

Commit

Permalink
AWS: Replace FileOutputStream/InputStream constructor with NIO Files …
Browse files Browse the repository at this point in the history
…APIs (apache#8626)
  • Loading branch information
amogh-jahagirdar authored Sep 25, 2023
1 parent 8a1f50a commit 82bce4f
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions aws/src/main/java/org/apache/iceberg/aws/s3/S3OutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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));
}
}

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 82bce4f

Please sign in to comment.