From 780663992de799ef0ce9308c27f9f4ce4484b1fb Mon Sep 17 00:00:00 2001 From: Rishikesh1159 Date: Thu, 22 Feb 2024 00:22:37 +0000 Subject: [PATCH] Refactor outputstream usage. Signed-off-by: Rishikesh1159 --- .../index/store/remote/utils/TransferManager.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/store/remote/utils/TransferManager.java b/server/src/main/java/org/opensearch/index/store/remote/utils/TransferManager.java index 01df121ccfcbf..8341b1dd2cf36 100644 --- a/server/src/main/java/org/opensearch/index/store/remote/utils/TransferManager.java +++ b/server/src/main/java/org/opensearch/index/store/remote/utils/TransferManager.java @@ -17,6 +17,7 @@ import org.opensearch.index.store.remote.filecache.FileCache; import org.opensearch.index.store.remote.filecache.FileCachedIndexInput; +import java.io.BufferedOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -29,8 +30,6 @@ import java.util.concurrent.CompletionException; import java.util.concurrent.atomic.AtomicBoolean; -import static java.nio.file.StandardOpenOption.APPEND; - /** * This acts as entry point to fetch {@link BlobFetchRequest} and return actual {@link IndexInput}. Utilizes the BlobContainer interface to * read snapshot files located within a repository. This basically adapts BlobContainer snapshots files into IndexInput @@ -87,11 +86,8 @@ private static FileCachedIndexInput createIndexInput(FileCache fileCache, BlobCo try { if (Files.exists(request.getFilePath()) == false) { try ( - // Create a new empty file in the specified path OutputStream fileOutputStream = Files.newOutputStream(request.getFilePath()); - - // All blob parts will be appended to file iteratively. - OutputStream localFileOutputStream = Files.newOutputStream(request.getFilePath(), APPEND) + OutputStream localFileOutputStream = new BufferedOutputStream(fileOutputStream) ) { for (BlobFetchRequest.BlobPart blobPart : request.blobParts()) { try (