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 354adca3 Use try-with-resources and NIO 354adca3 is described below commit 354adca3a4ced5bab764d4383c7976303c80a2ab Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sat Jan 28 10:34:21 2023 -0500 Use try-with-resources and NIO --- .../archivers/jar/JarArchiveOutputStreamTest.java | 24 ++++++---------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java index d050865e..433f3371 100644 --- a/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java @@ -22,9 +22,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.time.Instant; import org.apache.commons.compress.AbstractTestCase; @@ -38,13 +38,9 @@ public class JarArchiveOutputStreamTest { @Test public void testJarMarker() throws IOException { - final File testArchive = File.createTempFile("jar-aostest", ".jar"); - testArchive.deleteOnExit(); - JarArchiveOutputStream out = null; - ZipFile zf = null; - try { - - out = new JarArchiveOutputStream(Files.newOutputStream(testArchive.toPath())); + final Path testArchive = Files.createTempFile("jar-aostest", ".jar"); + testArchive.toFile().deleteOnExit(); + try (JarArchiveOutputStream out = new JarArchiveOutputStream(Files.newOutputStream(testArchive))) { final ZipArchiveEntry ze1 = new ZipArchiveEntry("foo/"); // Ensure we won't accidentally add an Extra field. ze1.setTime(Instant.parse("2022-12-27T12:10:23Z").toEpochMilli()); @@ -56,10 +52,8 @@ public class JarArchiveOutputStreamTest { out.putArchiveEntry(ze2); out.closeArchiveEntry(); out.finish(); - out.close(); - out = null; - - zf = new ZipFile(testArchive); + } + try (ZipFile zf = new ZipFile(testArchive)) { ZipArchiveEntry ze = zf.getEntry("foo/"); assertNotNull(ze); ZipExtraField[] fes = ze.getExtraFields(); @@ -71,12 +65,6 @@ public class JarArchiveOutputStreamTest { fes = ze.getExtraFields(); assertEquals(0, fes.length); } finally { - if (out != null) { - try { - out.close(); - } catch (final IOException e) { /* swallow */ } - } - ZipFile.closeQuietly(zf); AbstractTestCase.tryHardToDelete(testArchive); } }