diff --git a/libraries-apache-commons-2/src/main/java/com/baeldung/commons/untar/impl/TarExtractorVfs.java b/libraries-apache-commons-2/src/main/java/com/baeldung/commons/untar/impl/TarExtractorVfs.java index add009aae0..2932b9c3bc 100644 --- a/libraries-apache-commons-2/src/main/java/com/baeldung/commons/untar/impl/TarExtractorVfs.java +++ b/libraries-apache-commons-2/src/main/java/com/baeldung/commons/untar/impl/TarExtractorVfs.java @@ -41,11 +41,9 @@ public class TarExtractorVfs extends TarExtractor { if (entry.isReadable() && entry.getType() == FileType.FILE) { Files.createDirectories(extractTo.getParent()); - try (FileContent fc = entry.getContent(); InputStream stream = fc.getInputStream()) { + try (FileContent content = entry.getContent(); InputStream stream = content.getInputStream()) { Files.copy(stream, extractTo, StandardCopyOption.REPLACE_EXISTING); } - } else { - Files.createDirectories(extractTo); } } diff --git a/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/Resources.java b/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/Resources.java index 3336a3ec39..5b9b022d7f 100644 --- a/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/Resources.java +++ b/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/Resources.java @@ -3,6 +3,12 @@ package com.baeldung.commons.untar; import java.io.InputStream; public interface Resources { - InputStream TAR_FILE = Resources.class.getResourceAsStream("/untar/test.tar"); - InputStream TAR_GZ_FILE = Resources.class.getResourceAsStream("/untar/test.tar.gz"); + + static InputStream tarFile() { + return Resources.class.getResourceAsStream("/untar/test.tar"); + } + + static InputStream tarGzFile() { + return Resources.class.getResourceAsStream("/untar/test.tar.gz"); + } } diff --git a/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/TarExtractorAntUnitTest.java b/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/TarExtractorAntUnitTest.java index 01b4866a04..80b8fda104 100644 --- a/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/TarExtractorAntUnitTest.java +++ b/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/TarExtractorAntUnitTest.java @@ -17,7 +17,7 @@ public class TarExtractorAntUnitTest { public void givenTarFile_whenUntar_thenExtractedToDestination() throws IOException { Path destination = Paths.get("/tmp/ant"); - new TarExtractorAnt(Resources.TAR_FILE, false, destination).untar(); + new TarExtractorAnt(Resources.tarFile(), false, destination).untar(); assertTrue(Files.list(destination) .findFirst() @@ -28,7 +28,7 @@ public class TarExtractorAntUnitTest { public void givenTarGzFile_whenUntar_thenExtractedToDestination() throws IOException { Path destination = Paths.get("/tmp/ant-gz"); - new TarExtractorAnt(Resources.TAR_GZ_FILE, true, destination).untar(); + new TarExtractorAnt(Resources.tarGzFile(), true, destination).untar(); assertTrue(Files.list(destination) .findFirst() diff --git a/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/TarExtractorCommonsCompressUnitTest.java b/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/TarExtractorCommonsCompressUnitTest.java index b43a437a64..bea67ea3f5 100644 --- a/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/TarExtractorCommonsCompressUnitTest.java +++ b/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/TarExtractorCommonsCompressUnitTest.java @@ -17,7 +17,7 @@ public class TarExtractorCommonsCompressUnitTest { public void givenTarFile_whenUntar_thenExtractedToDestination() throws IOException { Path destination = Paths.get("/tmp/commons-compress"); - new TarExtractorCommonsCompress(Resources.TAR_FILE, false, destination).untar(); + new TarExtractorCommonsCompress(Resources.tarFile(), false, destination).untar(); assertTrue(Files.list(destination) .findFirst() @@ -28,7 +28,7 @@ public class TarExtractorCommonsCompressUnitTest { public void givenTarGzFile_whenUntar_thenExtractedToDestination() throws IOException { Path destination = Paths.get("/tmp/commons-compress-gz"); - new TarExtractorCommonsCompress(Resources.TAR_GZ_FILE, true, destination).untar(); + new TarExtractorCommonsCompress(Resources.tarGzFile(), true, destination).untar(); assertTrue(Files.list(destination) .findFirst() diff --git a/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/TarExtractorVfsUnitTest.java b/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/TarExtractorVfsUnitTest.java index 8f513055ae..9a00fd7e56 100644 --- a/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/TarExtractorVfsUnitTest.java +++ b/libraries-apache-commons-2/src/test/java/com/baeldung/commons/untar/TarExtractorVfsUnitTest.java @@ -17,7 +17,7 @@ public class TarExtractorVfsUnitTest { public void givenTarFile_whenUntar_thenExtractedToDestination() throws IOException { Path destination = Paths.get("/tmp/vfs"); - new TarExtractorVfs(Resources.TAR_FILE, false, destination).untar(); + new TarExtractorVfs(Resources.tarFile(), false, destination).untar(); assertTrue(Files.list(destination) .findFirst() @@ -28,7 +28,7 @@ public class TarExtractorVfsUnitTest { public void givenTarGzFile_whenUntar_thenExtractedToDestination() throws IOException { Path destination = Paths.get("/tmp/vfs-gz"); - new TarExtractorVfs(Resources.TAR_GZ_FILE, true, destination).untar(); + new TarExtractorVfs(Resources.tarGzFile(), true, destination).untar(); assertTrue(Files.list(destination) .findFirst()