You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by el...@apache.org on 2021/02/24 08:45:51 UTC

[ozone] 02/27: close input stream when untar

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

elek pushed a commit to branch HDDS-3816-ec
in repository https://gitbox.apache.org/repos/asf/ozone.git

commit 792b04fcae83ac360835ec1a02d385a096a7eb65
Author: Elek Márton <el...@apache.org>
AuthorDate: Wed Jan 13 15:45:45 2021 +0100

    close input stream when untar
---
 .../container/keyvalue/TarContainerPacker.java     | 40 +++++++++++-----------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/TarContainerPacker.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/TarContainerPacker.java
index 025cadf..a3cb873 100644
--- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/TarContainerPacker.java
+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/TarContainerPacker.java
@@ -74,32 +74,32 @@ public class TarContainerPacker
     Path dbRoot = containerData.getDbFile().toPath();
     Path chunksRoot = Paths.get(containerData.getChunksPath());
 
-    ArchiveInputStream archiveInput = untar(input);
-
-    ArchiveEntry entry = archiveInput.getNextEntry();
-    while (entry != null) {
-      String name = entry.getName();
-      long size = entry.getSize();
-      if (name.startsWith(DB_DIR_NAME + "/")) {
-        Path destinationPath = dbRoot
-            .resolve(name.substring(DB_DIR_NAME.length() + 1));
-        extractEntry(archiveInput, size, dbRoot, destinationPath);
-      } else if (name.startsWith(CHUNKS_DIR_NAME + "/")) {
+    try (ArchiveInputStream archiveInput = untar(input)) {
+
+      ArchiveEntry entry = archiveInput.getNextEntry();
+      while (entry != null) {
+        String name = entry.getName();
+        long size = entry.getSize();
+        if (name.startsWith(DB_DIR_NAME + "/")) {
+          Path destinationPath = dbRoot
+              .resolve(name.substring(DB_DIR_NAME.length() + 1));
+          extractEntry(archiveInput, size, dbRoot, destinationPath);
+        } else if (name.startsWith(CHUNKS_DIR_NAME + "/")) {
           Path destinationPath = chunksRoot
               .resolve(name.substring(CHUNKS_DIR_NAME.length() + 1));
           extractEntry(archiveInput, size, chunksRoot, destinationPath);
         } else if (CONTAINER_FILE_NAME.equals(name)) {
-        //Don't do anything. Container file should be unpacked in a
-        //separated step by unpackContainerDescriptor call.
-        descriptorFileContent = readEntry(archiveInput, size);
-      } else {
-        throw new IllegalArgumentException(
-            "Unknown entry in the tar file: " + "" + name);
+          //Don't do anything. Container file should be unpacked in a
+          //separated step by unpackContainerDescriptor call.
+          descriptorFileContent = readEntry(archiveInput, size);
+        } else {
+          throw new IllegalArgumentException(
+              "Unknown entry in the tar file: " + "" + name);
+        }
+        entry = archiveInput.getNextEntry();
       }
-      entry = archiveInput.getNextEntry();
+      return descriptorFileContent;
     }
-    return descriptorFileContent;
-
   }
 
   private void extractEntry(InputStream input, long size,


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ozone.apache.org
For additional commands, e-mail: commits-help@ozone.apache.org