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
commit 46eab6b1e90d9dd6c4f7898f41ff4a05ef68b0da Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Mar 5 16:05:16 2021 -0500 Use try-with-resources. --- .../apache/commons/compress/ArchiveReadTest.java | 16 ++++++++-------- .../apache/commons/compress/ChainingTestCase.java | 22 ++++++++++++---------- .../archivers/ArchiveStreamFactoryTest.java | 4 ++-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/test/java/org/apache/commons/compress/ArchiveReadTest.java b/src/test/java/org/apache/commons/compress/ArchiveReadTest.java index bfe543f..669a084 100644 --- a/src/test/java/org/apache/commons/compress/ArchiveReadTest.java +++ b/src/test/java/org/apache/commons/compress/ArchiveReadTest.java @@ -68,16 +68,16 @@ public class ArchiveReadTest extends AbstractTestCase { @BeforeClass public static void setUpFileList() throws Exception { assertTrue(ARCDIR.exists()); - final File listing= new File(ARCDIR,"files.txt"); - assertTrue("files.txt is readable",listing.canRead()); - final BufferedReader br = new BufferedReader(new FileReader(listing)); - String line; - while ((line=br.readLine())!=null){ - if (!line.startsWith("#")){ - FILELIST.add(line); + final File listing = new File(ARCDIR, "files.txt"); + assertTrue("files.txt is readable", listing.canRead()); + try (final BufferedReader br = new BufferedReader(new FileReader(listing))) { + String line; + while ((line = br.readLine()) != null) { + if (!line.startsWith("#")) { + FILELIST.add(line); + } } } - br.close(); } @Parameters(name = "file={0}") diff --git a/src/test/java/org/apache/commons/compress/ChainingTestCase.java b/src/test/java/org/apache/commons/compress/ChainingTestCase.java index f6cad8b..10a10d4 100644 --- a/src/test/java/org/apache/commons/compress/ChainingTestCase.java +++ b/src/test/java/org/apache/commons/compress/ChainingTestCase.java @@ -36,20 +36,22 @@ public class ChainingTestCase extends AbstractTestCase { @Test public void testTarGzip() throws Exception { final File file = getFile("bla.tgz"); - final TarArchiveInputStream is = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(file))); - final TarArchiveEntry entry = (TarArchiveEntry)is.getNextEntry(); - assertNotNull(entry); - assertEquals("test1.xml", entry.getName()); - is.close(); + try (final TarArchiveInputStream is = new TarArchiveInputStream( + new GzipCompressorInputStream(new FileInputStream(file)))) { + final TarArchiveEntry entry = (TarArchiveEntry) is.getNextEntry(); + assertNotNull(entry); + assertEquals("test1.xml", entry.getName()); + } } @Test public void testTarBzip2() throws Exception { final File file = getFile("bla.tar.bz2"); - final TarArchiveInputStream is = new TarArchiveInputStream(new BZip2CompressorInputStream(new FileInputStream(file))); - final TarArchiveEntry entry = (TarArchiveEntry)is.getNextEntry(); - assertNotNull(entry); - assertEquals("test1.xml", entry.getName()); - is.close(); + try (final TarArchiveInputStream is = new TarArchiveInputStream( + new BZip2CompressorInputStream(new FileInputStream(file)))) { + final TarArchiveEntry entry = (TarArchiveEntry) is.getNextEntry(); + assertNotNull(entry); + assertEquals("test1.xml", entry.getName()); + } } } diff --git a/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java b/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java index e5b53b0..822df9b 100644 --- a/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java @@ -50,7 +50,7 @@ public class ArchiveStreamFactoryTest { * see https://issues.apache.org/jira/browse/COMPRESS-171 */ @Test - public void shortTextFilesAreNoTARs() throws Exception { + public void shortTextFilesAreNoTARs() { try { ArchiveStreamFactory.DEFAULT .createArchiveInputStream(new ByteArrayInputStream("This certainly is not a tar archive, really, no kidding".getBytes())); @@ -428,7 +428,7 @@ public class ArchiveStreamFactoryTest { } private ArchiveOutputStream getOutputStreamFor(final String type, final ArchiveStreamFactory factory) - throws IOException, ArchiveException { + throws ArchiveException { return factory.createArchiveOutputStream(type, new ByteArrayOutputStream()); } }