This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git
The following commit(s) were added to refs/heads/master by this push: new 505a8756 Use try-with-resources. 505a8756 is described below commit 505a8756a5a1199a36479226023e928708d66a2b Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Thu May 5 16:20:45 2022 -0400 Use try-with-resources. --- .../archivers/tar/TarArchiveInputStreamTest.java | 37 +++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java index c4fbd2e6..d94267b2 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java @@ -325,30 +325,29 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { // ----------------------- final String fileName = "/" + dirDirectory + "/" + subDir; final File tarF = new File(rootPath + "/tar" + i + ".tar"); - final OutputStream dest = Files.newOutputStream(tarF.toPath()); - final TarArchiveOutputStream out = new TarArchiveOutputStream(new BufferedOutputStream(dest)); - out.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR); - out.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); - - final File file = new File(rootPath, fileName); - final TarArchiveEntry entry = new TarArchiveEntry(file); - entry.setName(fileName); - out.putArchiveEntry(entry); - out.closeArchiveEntry(); - out.flush(); - out.close(); + try (final OutputStream dest = Files.newOutputStream(tarF.toPath())) { + final TarArchiveOutputStream out = new TarArchiveOutputStream(new BufferedOutputStream(dest)); + out.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR); + out.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); + + final File file = new File(rootPath, fileName); + final TarArchiveEntry entry = new TarArchiveEntry(file); + entry.setName(fileName); + out.putArchiveEntry(entry); + out.closeArchiveEntry(); + out.flush(); + } // ----------------------- // untar these tars // ----------------------- - final InputStream is = Files.newInputStream(tarF.toPath()); - final TarArchiveInputStream debInputStream = (TarArchiveInputStream) ArchiveStreamFactory.DEFAULT - .createArchiveInputStream("tar", is); - TarArchiveEntry outEntry; - while ((outEntry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) { - assertTrue(outEntry.getName().endsWith("/")); + try (final InputStream is = Files.newInputStream(tarF.toPath()); + final TarArchiveInputStream debInputStream = (TarArchiveInputStream) ArchiveStreamFactory.DEFAULT.createArchiveInputStream("tar", is)) { + TarArchiveEntry outEntry; + while ((outEntry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) { + assertTrue(outEntry.getName(), outEntry.getName().endsWith("/")); + } } - debInputStream.close(); } }