diff --git a/src/main/java/eu/openaire/urls_controller/util/FileDecompressor.java b/src/main/java/eu/openaire/urls_controller/util/FileDecompressor.java index 6876690..1ec746a 100644 --- a/src/main/java/eu/openaire/urls_controller/util/FileDecompressor.java +++ b/src/main/java/eu/openaire/urls_controller/util/FileDecompressor.java @@ -40,10 +40,11 @@ public class FileDecompressor { while ( ((entry = (TarArchiveEntry) tarInput.getNextEntry()) != null) ) { // Copy an individual entry. - BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(Files.newOutputStream(targetDir.resolve(entry.getName())), FileUtils.tenMb); - while ( (readByte = tarInput.read()) != -1 ) - bufferedOutputStream.write(readByte); - // No need to close the tarEntry. + try ( BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(Files.newOutputStream(targetDir.resolve(entry.getName())), FileUtils.tenMb) ) { + while ( (readByte = tarInput.read()) != -1 ) + bufferedOutputStream.write(readByte); + } // The exception will be given to the caller method. + // No need to close the tarEntry (no "close()" method is provided). } }