You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/01/25 16:55:30 UTC

[commons-compress] branch master updated (a19262d -> 6eec951)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git.


    from a19262d  typo
     new 9ede8ae  Reuse own CloseShieldFilterInputStream instead of creating an anonymous inner class.
     new ea129b4  Format tweaks.
     new 75775f9  Javadoc.
     new 81b0b1b  Reuse own CloseShieldFilterInputStream instead of creating an anonymous inner class.
     new 11b8034  Fix some tests that leak resources when failing. There is a lot more to do in this area.
     new 6eec951  Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-compress.git

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../archivers/zip/ExplodingInputStream.java        | 15 ++---
 .../pack200/Pack200CompressorInputStream.java      | 12 ++--
 .../compress/utils/CountingInputStream.java        |  5 +-
 .../archivers/ar/ArArchiveInputStreamTest.java     | 23 ++++----
 .../archivers/arj/ArjArchiveInputStreamTest.java   | 61 ++++++++++-----------
 .../archivers/cpio/CpioArchiveInputStreamTest.java | 51 +++++++++--------
 .../compress/archivers/examples/ExpanderTest.java  |  4 --
 .../compress/archivers/sevenz/SevenZFileTest.java  | 64 +++++++++++-----------
 .../archivers/sevenz/SevenZNativeHeapTest.java     | 29 +++++-----
 .../archivers/sevenz/SevenZOutputFileTest.java     | 14 ++---
 10 files changed, 132 insertions(+), 146 deletions(-)


[commons-compress] 03/06: Javadoc.

Posted by gg...@apache.org.
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 75775f9eaf50838779571a0494b68e8d0d417689
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jan 25 11:27:57 2020 -0500

    Javadoc.
---
 .../java/org/apache/commons/compress/utils/CountingInputStream.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/compress/utils/CountingInputStream.java b/src/main/java/org/apache/commons/compress/utils/CountingInputStream.java
index 4f59a9e..cd6478c 100644
--- a/src/main/java/org/apache/commons/compress/utils/CountingInputStream.java
+++ b/src/main/java/org/apache/commons/compress/utils/CountingInputStream.java
@@ -23,7 +23,7 @@ import java.io.IOException;
 import java.io.InputStream;
 
 /**
- * Stream that tracks the number of bytes read.
+ * Input stream that tracks the number of bytes read.
  * @since 1.3
  * @NotThreadSafe
  */


[commons-compress] 02/06: Format tweaks.

Posted by gg...@apache.org.
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 ea129b4a677c3f1f40a3c183f82188f770c52c6c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jan 25 11:24:24 2020 -0500

    Format tweaks.
---
 .../java/org/apache/commons/compress/utils/CountingInputStream.java    | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/main/java/org/apache/commons/compress/utils/CountingInputStream.java b/src/main/java/org/apache/commons/compress/utils/CountingInputStream.java
index 2184564..4f59a9e 100644
--- a/src/main/java/org/apache/commons/compress/utils/CountingInputStream.java
+++ b/src/main/java/org/apache/commons/compress/utils/CountingInputStream.java
@@ -42,10 +42,12 @@ public class CountingInputStream extends FilterInputStream {
         }
         return r;
     }
+
     @Override
     public int read(final byte[] b) throws IOException {
         return read(b, 0, b.length);
     }
+
     @Override
     public int read(final byte[] b, final int off, final int len) throws IOException {
         if (len == 0) {
@@ -57,6 +59,7 @@ public class CountingInputStream extends FilterInputStream {
         }
         return r;
     }
+
     /**
      * Increments the counter of already read bytes.
      * Doesn't increment if the EOF has been hit (read == -1)


[commons-compress] 06/06: Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-compress.git

Posted by gg...@apache.org.
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 6eec951cf160b526e5bc51921650ad6166485ebe
Merge: 11b8034 a19262d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jan 25 11:55:15 2020 -0500

    Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-compress.git

 .../apache/commons/compress/archivers/tar/TarArchiveSparseEntry.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[commons-compress] 05/06: Fix some tests that leak resources when failing. There is a lot more to do in this area.

Posted by gg...@apache.org.
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 11b803476f4776c463f0a62516ed3b688be91260
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jan 25 11:55:05 2020 -0500

    Fix some tests that leak resources when failing. There is a lot more to
    do in this area.
    
    Remove unused imports.
---
 .../archivers/ar/ArArchiveInputStreamTest.java     | 23 ++++----
 .../archivers/arj/ArjArchiveInputStreamTest.java   | 61 ++++++++++-----------
 .../archivers/cpio/CpioArchiveInputStreamTest.java | 51 +++++++++--------
 .../compress/archivers/examples/ExpanderTest.java  |  4 --
 .../compress/archivers/sevenz/SevenZFileTest.java  | 64 +++++++++++-----------
 .../archivers/sevenz/SevenZNativeHeapTest.java     | 29 +++++-----
 .../archivers/sevenz/SevenZOutputFileTest.java     | 14 ++---
 7 files changed, 118 insertions(+), 128 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java
index 14c4315..f620a6b 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java
@@ -97,17 +97,18 @@ public class ArArchiveInputStreamTest extends AbstractTestCase {
                 }
             };
 
-            ArArchiveInputStream archiveInputStream = new ArArchiveInputStream(simpleInputStream);
-            ArArchiveEntry entry1 = archiveInputStream.getNextArEntry();
-            assertThat(entry1, not(nullValue()));
-            assertThat(entry1.getName(), equalTo("test1.xml"));
-            assertThat(entry1.getLength(), equalTo(610L));
-
-            ArArchiveEntry entry2 = archiveInputStream.getNextArEntry();
-            assertThat(entry2.getName(), equalTo("test2.xml"));
-            assertThat(entry2.getLength(), equalTo(82L));
-
-            assertThat(archiveInputStream.getNextArEntry(), nullValue());
+            try (ArArchiveInputStream archiveInputStream = new ArArchiveInputStream(simpleInputStream)) {
+                ArArchiveEntry entry1 = archiveInputStream.getNextArEntry();
+                assertThat(entry1, not(nullValue()));
+                assertThat(entry1.getName(), equalTo("test1.xml"));
+                assertThat(entry1.getLength(), equalTo(610L));
+
+                ArArchiveEntry entry2 = archiveInputStream.getNextArEntry();
+                assertThat(entry2.getName(), equalTo("test2.xml"));
+                assertThat(entry2.getLength(), equalTo(82L));
+
+                assertThat(archiveInputStream.getNextArEntry(), nullValue());
+            }
         }
     }
 
diff --git a/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java
index 70a8b1f..6c0950c 100644
--- a/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java
@@ -39,49 +39,48 @@ public class ArjArchiveInputStreamTest extends AbstractTestCase {
         expected.append("<empty/>test2.xml<?xml version=\"1.0\"?>\n");
         expected.append("<empty/>\n");
 
-
-        final ArjArchiveInputStream in = new ArjArchiveInputStream(new FileInputStream(getFile("bla.arj")));
-        ArjArchiveEntry entry;
-
         final StringBuilder result = new StringBuilder();
-        while ((entry = in.getNextEntry()) != null) {
-            result.append(entry.getName());
-            int tmp;
-            while ((tmp = in.read()) != -1) {
-                result.append((char) tmp);
+        try (final ArjArchiveInputStream in = new ArjArchiveInputStream(new FileInputStream(getFile("bla.arj")))) {
+            ArjArchiveEntry entry;
+
+            while ((entry = in.getNextEntry()) != null) {
+                result.append(entry.getName());
+                int tmp;
+                while ((tmp = in.read()) != -1) {
+                    result.append((char) tmp);
+                }
+                assertFalse(entry.isDirectory());
             }
-            assertFalse(entry.isDirectory());
         }
-        in.close();
         assertEquals(result.toString(), expected.toString());
     }
 
     @Test
     public void testReadingOfAttributesDosVersion() throws Exception {
-        final ArjArchiveInputStream in = new ArjArchiveInputStream(new FileInputStream(getFile("bla.arj")));
-        final ArjArchiveEntry entry = in.getNextEntry();
-        assertEquals("test1.xml", entry.getName());
-        assertEquals(30, entry.getSize());
-        assertEquals(0, entry.getUnixMode());
-        final Calendar cal = Calendar.getInstance();
-        cal.set(2008, 9, 6, 23, 50, 52);
-        cal.set(Calendar.MILLISECOND, 0);
-        assertEquals(cal.getTime(), entry.getLastModifiedDate());
-        in.close();
+        try (final ArjArchiveInputStream in = new ArjArchiveInputStream(new FileInputStream(getFile("bla.arj")))) {
+            final ArjArchiveEntry entry = in.getNextEntry();
+            assertEquals("test1.xml", entry.getName());
+            assertEquals(30, entry.getSize());
+            assertEquals(0, entry.getUnixMode());
+            final Calendar cal = Calendar.getInstance();
+            cal.set(2008, 9, 6, 23, 50, 52);
+            cal.set(Calendar.MILLISECOND, 0);
+            assertEquals(cal.getTime(), entry.getLastModifiedDate());
+        }
     }
 
     @Test
     public void testReadingOfAttributesUnixVersion() throws Exception {
-        final ArjArchiveInputStream in = new ArjArchiveInputStream(new FileInputStream(getFile("bla.unix.arj")));
-        final ArjArchiveEntry entry = in.getNextEntry();
-        assertEquals("test1.xml", entry.getName());
-        assertEquals(30, entry.getSize());
-        assertEquals(0664, entry.getUnixMode() & 07777 /* UnixStat.PERM_MASK */);
-        final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+0000"));
-        cal.set(2008, 9, 6, 21, 50, 52);
-        cal.set(Calendar.MILLISECOND, 0);
-        assertEquals(cal.getTime(), entry.getLastModifiedDate());
-        in.close();
+        try (final ArjArchiveInputStream in = new ArjArchiveInputStream(new FileInputStream(getFile("bla.unix.arj")))) {
+            final ArjArchiveEntry entry = in.getNextEntry();
+            assertEquals("test1.xml", entry.getName());
+            assertEquals(30, entry.getSize());
+            assertEquals(0664, entry.getUnixMode() & 07777 /* UnixStat.PERM_MASK */);
+            final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+0000"));
+            cal.set(2008, 9, 6, 21, 50, 52);
+            cal.set(Calendar.MILLISECOND, 0);
+            assertEquals(cal.getTime(), entry.getLastModifiedDate());
+        }
     }
 
     @Test
diff --git a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java
index 55a9f75..efb5394 100644
--- a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java
@@ -36,50 +36,49 @@ public class CpioArchiveInputStreamTest extends AbstractTestCase {
         expected.append("<empty/>./test2.xml<?xml version=\"1.0\"?>\n");
         expected.append("<empty/>\n");
 
-
-        final CpioArchiveInputStream in = new CpioArchiveInputStream(new FileInputStream(getFile("bla.cpio")));
-        CpioArchiveEntry entry;
-
         final StringBuilder result = new StringBuilder();
-        while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) {
-            result.append(entry.getName());
-            int tmp;
-            while ((tmp = in.read()) != -1) {
-                result.append((char) tmp);
+        try (final CpioArchiveInputStream in = new CpioArchiveInputStream(new FileInputStream(getFile("bla.cpio")))) {
+            CpioArchiveEntry entry;
+
+            while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) {
+                result.append(entry.getName());
+                int tmp;
+                while ((tmp = in.read()) != -1) {
+                    result.append((char) tmp);
+                }
             }
         }
-        in.close();
         assertEquals(result.toString(), expected.toString());
     }
 
     @Test
     public void testCpioUnarchiveCreatedByRedlineRpm() throws Exception {
-        final CpioArchiveInputStream in =
-            new CpioArchiveInputStream(new FileInputStream(getFile("redline.cpio")));
-        CpioArchiveEntry entry= null;
-
         int count = 0;
-        while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) {
-            count++;
-            assertNotNull(entry);
+        try (final CpioArchiveInputStream in = new CpioArchiveInputStream(
+            new FileInputStream(getFile("redline.cpio")))) {
+            CpioArchiveEntry entry = null;
+
+            while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) {
+                count++;
+                assertNotNull(entry);
+            }
         }
-        in.close();
 
         assertEquals(count, 1);
     }
 
     @Test
     public void testCpioUnarchiveMultibyteCharName() throws Exception {
-        final CpioArchiveInputStream in =
-            new CpioArchiveInputStream(new FileInputStream(getFile("COMPRESS-459.cpio")), "UTF-8");
-        CpioArchiveEntry entry= null;
-
         int count = 0;
-        while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) {
-            count++;
-            assertNotNull(entry);
+        try (final CpioArchiveInputStream in = new CpioArchiveInputStream(
+            new FileInputStream(getFile("COMPRESS-459.cpio")), "UTF-8")) {
+            CpioArchiveEntry entry = null;
+
+            while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) {
+                count++;
+                assertNotNull(entry);
+            }
         }
-        in.close();
 
         assertEquals(2, count);
     }
diff --git a/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java b/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java
index 15791b6..304777c 100644
--- a/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java
@@ -28,13 +28,9 @@ import java.nio.channels.SeekableByteChannel;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.StandardOpenOption;
-import java.util.Arrays;
-import java.util.Collection;
 
 import org.apache.commons.compress.AbstractTestCase;
-import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveException;
-import org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.ArchiveOutputStream;
 import org.apache.commons.compress.archivers.ArchiveStreamFactory;
 import org.apache.commons.compress.archivers.StreamingNotSupportedException;
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
index b37184b..3fb99ce 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
@@ -56,14 +56,14 @@ public class SevenZFileTest extends AbstractTestCase {
     public void testRandomlySkippingEntries() throws Exception {
         // Read sequential reference.
         final Map<String, byte[]> entriesByName = new HashMap<>();
-        SevenZFile archive = new SevenZFile(getFile("COMPRESS-320/Copy.7z"));
-        SevenZArchiveEntry entry;
-        while ((entry = archive.getNextEntry()) != null) {
-            if (entry.hasStream()) {
-                entriesByName.put(entry.getName(), readFully(archive));
+        try (SevenZFile archive = new SevenZFile(getFile("COMPRESS-320/Copy.7z"))) {
+            SevenZArchiveEntry entry;
+            while ((entry = archive.getNextEntry()) != null) {
+                if (entry.hasStream()) {
+                    entriesByName.put(entry.getName(), readFully(archive));
+                }
             }
         }
-        archive.close();
 
         final String[] variants = {
             "BZip2-solid.7z",
@@ -81,26 +81,27 @@ public class SevenZFileTest extends AbstractTestCase {
             // "PPMd.7z",
         };
 
-        // TODO: use randomizedtesting for predictable, but different, randomness.
+        // TODO: use randomized testing for predictable, but different, randomness.
         final Random rnd = new Random(0xdeadbeef);
         for (final String fileName : variants) {
-            archive = new SevenZFile(getFile("COMPRESS-320/" + fileName));
+            try (SevenZFile archive = new SevenZFile(getFile("COMPRESS-320/" + fileName))) {
 
-            while ((entry = archive.getNextEntry()) != null) {
-                // Sometimes skip reading entries.
-                if (rnd.nextBoolean()) {
-                    continue;
-                }
+                SevenZArchiveEntry entry;
+                while ((entry = archive.getNextEntry()) != null) {
+                    // Sometimes skip reading entries.
+                    if (rnd.nextBoolean()) {
+                        continue;
+                    }
 
-                if (entry.hasStream()) {
-                    assertTrue(entriesByName.containsKey(entry.getName()));
-                    final byte [] content = readFully(archive);
-                    assertTrue("Content mismatch on: " + fileName + "!" + entry.getName(),
-                               Arrays.equals(content, entriesByName.get(entry.getName())));
+                    if (entry.hasStream()) {
+                        assertTrue(entriesByName.containsKey(entry.getName()));
+                        final byte[] content = readFully(archive);
+                        assertTrue("Content mismatch on: " + fileName + "!" + entry.getName(),
+                            Arrays.equals(content, entriesByName.get(entry.getName())));
+                    }
                 }
-            }
 
-            archive.close();
+            }
         }
     }
 
@@ -534,23 +535,24 @@ public class SevenZFileTest extends AbstractTestCase {
             sevenZFile.getNextEntry();
             // skip all the entries and jump backwards
             byte[] contents = new byte[(int) testTxtEntry.getSize()];
-            InputStream inputStream = sevenZFile.getInputStream(testTxtEntry);
-            int off = 0;
-            while (off < contents.length) {
-                final int bytesRead = inputStream.read(contents, off, contents.length - off);
-                assert (bytesRead >= 0);
-                off += bytesRead;
+            try (InputStream inputStream = sevenZFile.getInputStream(testTxtEntry)) {
+                int off = 0;
+                while (off < contents.length) {
+                    final int bytesRead = inputStream.read(contents, off, contents.length - off);
+                    assert (bytesRead >= 0);
+                    off += bytesRead;
+                }
+                assertEquals(SevenZMethod.LZMA2, testTxtEntry.getContentMethods().iterator().next().getMethod());
+                assertEquals(testTxtContents, new String(contents, "UTF-8"));
             }
-            assertEquals(SevenZMethod.LZMA2, testTxtEntry.getContentMethods().iterator().next().getMethod());
-            assertEquals(testTxtContents, new String(contents, "UTF-8"));
         }
     }
 
     @Test
     public void extractNonExistSpecifiedFile() throws Exception {
-        try (SevenZFile sevenZFile = new SevenZFile(getFile("COMPRESS-256.7z"))) {
-            SevenZFile anotherSevenZFile = new SevenZFile(getFile("bla.7z"));
-            for(SevenZArchiveEntry nonExistEntry : anotherSevenZFile.getEntries()) {
+        try (SevenZFile sevenZFile = new SevenZFile(getFile("COMPRESS-256.7z"));
+            SevenZFile anotherSevenZFile = new SevenZFile(getFile("bla.7z"))) {
+            for (SevenZArchiveEntry nonExistEntry : anotherSevenZFile.getEntries()) {
                 thrown.expect(IllegalArgumentException.class);
                 sevenZFile.getInputStream(nonExistEntry);
             }
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZNativeHeapTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZNativeHeapTest.java
index 70adec0..04065c0 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZNativeHeapTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZNativeHeapTest.java
@@ -33,29 +33,28 @@ import org.junit.Test;
 
 public class SevenZNativeHeapTest extends AbstractTestCase {
 
-
     @Test
     public void testEndDeflaterOnCloseStream() throws Exception {
-        Coders.DeflateDecoder deflateDecoder = new DeflateDecoder();
-
-        final DeflateDecoderOutputStream outputStream =
-            (DeflateDecoderOutputStream) deflateDecoder.encode(new ByteArrayOutputStream(), 9);
-        DelegatingDeflater delegatingDeflater = new DelegatingDeflater(outputStream.deflater);
-        outputStream.deflater = delegatingDeflater;
-        outputStream.close();
+        final Coders.DeflateDecoder deflateDecoder = new DeflateDecoder();
+        final DelegatingDeflater delegatingDeflater;
+        try (final DeflateDecoderOutputStream outputStream = (DeflateDecoderOutputStream) deflateDecoder
+            .encode(new ByteArrayOutputStream(), 9)) {
+            delegatingDeflater = new DelegatingDeflater(outputStream.deflater);
+            outputStream.deflater = delegatingDeflater;
+        }
         assertTrue(delegatingDeflater.isEnded.get());
 
     }
 
     @Test
     public void testEndInflaterOnCloseStream() throws Exception {
-        Coders.DeflateDecoder deflateDecoder = new DeflateDecoder();
-        final DeflateDecoderInputStream inputStream =
-                (DeflateDecoderInputStream) deflateDecoder
-                        .decode("dummy", new ByteArrayInputStream(new byte[0]), 0, null, null, Integer.MAX_VALUE);
-        DelegatingInflater delegatingInflater = new DelegatingInflater(inputStream.inflater);
-        inputStream.inflater = delegatingInflater;
-        inputStream.close();
+        final Coders.DeflateDecoder deflateDecoder = new DeflateDecoder();
+        final DelegatingInflater delegatingInflater;
+        try (final DeflateDecoderInputStream inputStream = (DeflateDecoderInputStream) deflateDecoder.decode("dummy",
+            new ByteArrayInputStream(new byte[0]), 0, null, null, Integer.MAX_VALUE)) {
+            delegatingInflater = new DelegatingInflater(inputStream.inflater);
+            inputStream.inflater = delegatingInflater;
+        }
 
         assertTrue(delegatingInflater.isEnded.get());
     }
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java
index 7139ec3..63836ae 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java
@@ -479,12 +479,9 @@ public class SevenZOutputFileTest extends AbstractTestCase {
     }
 
     private void createAndReadBack(final File output, final Iterable<SevenZMethodConfiguration> methods) throws Exception {
-        final SevenZOutputFile outArchive = new SevenZOutputFile(output);
-        outArchive.setContentMethods(methods);
-        try {
+        try (final SevenZOutputFile outArchive = new SevenZOutputFile(output)) {
+            outArchive.setContentMethods(methods);
             addFile(outArchive, 0, true);
-        } finally {
-            outArchive.close();
         }
 
         try (SevenZFile archive = new SevenZFile(output)) {
@@ -493,12 +490,9 @@ public class SevenZOutputFileTest extends AbstractTestCase {
     }
 
     private void createAndReadBack(final SeekableInMemoryByteChannel output, final Iterable<SevenZMethodConfiguration> methods) throws Exception {
-        final SevenZOutputFile outArchive = new SevenZOutputFile(output);
-        outArchive.setContentMethods(methods);
-        try {
+        try (final SevenZOutputFile outArchive = new SevenZOutputFile(output)) {
+            outArchive.setContentMethods(methods);
             addFile(outArchive, 0, true);
-        } finally {
-            outArchive.close();
         }
         try (SevenZFile archive =
              new SevenZFile(new SeekableInMemoryByteChannel(output.array()), "in memory")) {


[commons-compress] 01/06: Reuse own CloseShieldFilterInputStream instead of creating an anonymous inner class.

Posted by gg...@apache.org.
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 9ede8aec5fd9a6a856bedd5246810d3a82b5a17c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jan 25 11:23:56 2020 -0500

    Reuse own CloseShieldFilterInputStream instead of creating an anonymous
    inner class.
---
 .../compressors/pack200/Pack200CompressorInputStream.java    | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200CompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200CompressorInputStream.java
index a669e6e..1d849a3 100644
--- a/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200CompressorInputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200CompressorInputStream.java
@@ -20,7 +20,6 @@
 package org.apache.commons.compress.compressors.pack200;
 
 import java.io.File;
-import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Map;
@@ -28,6 +27,7 @@ import java.util.jar.JarOutputStream;
 import java.util.jar.Pack200;
 
 import org.apache.commons.compress.compressors.CompressorInputStream;
+import org.apache.commons.compress.utils.CloseShieldFilterInputStream;
 import org.apache.commons.compress.utils.IOUtils;
 
 /**
@@ -178,13 +178,9 @@ public class Pack200CompressorInputStream extends CompressorInputStream {
                 u.properties().putAll(props);
             }
             if (f == null) {
-                u.unpack(new FilterInputStream(in) {
-                    @Override
-                    public void close() {
-                        // unpack would close this stream but we
-                        // want to give the user code more control
-                    }
-                }, jarOut);
+                // unpack would close this stream but we
+                // want to give the user code more control
+                u.unpack(new CloseShieldFilterInputStream(in), jarOut);
             } else {
                 u.unpack(f, jarOut);
             }


[commons-compress] 04/06: Reuse own CloseShieldFilterInputStream instead of creating an anonymous inner class.

Posted by gg...@apache.org.
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 81b0b1bad8c64f80f73148c16a00674f1ea997bf
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jan 25 11:29:33 2020 -0500

    Reuse own CloseShieldFilterInputStream instead of creating an anonymous
    inner class.
---
 .../compress/archivers/zip/ExplodingInputStream.java      | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ExplodingInputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ExplodingInputStream.java
index 0c899f9..24a0920 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ExplodingInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ExplodingInputStream.java
@@ -19,12 +19,13 @@
 
 package org.apache.commons.compress.archivers.zip;
 
-import org.apache.commons.compress.utils.CountingInputStream;
-import org.apache.commons.compress.utils.InputStreamStatistics;
-
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.commons.compress.utils.CloseShieldFilterInputStream;
+import org.apache.commons.compress.utils.CountingInputStream;
+import org.apache.commons.compress.utils.InputStreamStatistics;
+
 /**
  * The implode compression method was added to PKZIP 1.01 released in 1989.
  * It was then dropped from PKZIP 2.0 released in 1993 in favor of the deflate
@@ -97,12 +98,8 @@ class ExplodingInputStream extends InputStream implements InputStreamStatistics
      */
     private void init() throws IOException {
         if (bits == null) {
-            try (CountingInputStream i = new CountingInputStream(in) {
-                    @Override
-                    public void close() {
-                        // we do not want to close in
-                    }
-                }) {
+            // we do not want to close in
+            try (CountingInputStream i = new CountingInputStream(new CloseShieldFilterInputStream(in))) {
                 if (numberOfTrees == 3) {
                     literalTree = BinaryTree.decode(i, 256);
                 }