From b3196376eb5b5340769caba3c6dd93d740f47d35 Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Thu, 4 May 2023 13:03:28 +0300 Subject: [PATCH] Fix a bug, which caused the full-text files to never close. --- .../openaire/urls_controller/util/FileDecompressor.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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). } }