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 2023/11/02 22:17:25 UTC

(commons-compress) 01/02: Use try-with-resources

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 4c26741cb97c9ff67c90bb0a8c08a54df6c298be
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Nov 2 18:16:25 2023 -0400

    Use try-with-resources
---
 src/changes/changes.xml                            |   1 +
 .../compress/archivers/ArchiveStreamFactory.java   | 174 ++++++-------
 .../compress/archivers/ArchiveStreamProvider.java  |   8 +-
 .../apache/commons/compress/archivers/Lister.java  |   9 +-
 .../archivers/cpio/CpioArchiveInputStream.java     |   1 -
 .../compress/archivers/examples/Archiver.java      |  38 ++-
 .../compress/archivers/examples/Expander.java      |  10 +-
 .../apache/commons/compress/AbstractTestCase.java  |  18 +-
 .../apache/commons/compress/ChainingTestCase.java  |   4 +-
 .../commons/compress/DetectArchiverTestCase.java   |  36 +--
 .../org/apache/commons/compress/IOMethodsTest.java |  26 +-
 .../commons/compress/archivers/ArTestCase.java     |  29 +--
 .../archivers/ArchiveOutputStreamTest.java         | 102 ++++----
 .../archivers/ArchiveStreamFactoryTest.java        |  31 ++-
 .../commons/compress/archivers/CpioTestCase.java   | 102 ++++----
 .../commons/compress/archivers/DumpTestCase.java   |   2 +-
 .../commons/compress/archivers/JarTestCase.java    |  13 +-
 .../commons/compress/archivers/LongPathTest.java   |   2 +-
 .../compress/archivers/LongSymLinkTest.java        |   2 +-
 .../commons/compress/archivers/TarTestCase.java    | 153 +++++-------
 .../archivers/TestArchiveStreamProvider.java       |   6 +-
 .../commons/compress/archivers/ZipTestCase.java    |  26 +-
 .../archivers/cpio/CpioArchiveInputStreamTest.java |   6 +-
 .../compress/archivers/cpio/CpioArchiveTest.java   |   2 +-
 .../compress/archivers/examples/ExpanderTest.java  |   9 +-
 .../examples/ParameterizedArchiverTest.java        |   4 +-
 .../examples/ParameterizedExpanderTest.java        |   6 +-
 .../archivers/tar/TarArchiveInputStreamTest.java   |   4 +-
 .../archivers/tar/TarArchiveOutputStreamTest.java  |   3 +-
 .../archivers/tar/TarMemoryFileSystemTest.java     |   9 +-
 .../compress/archivers/zip/Zip64SupportIT.java     |   7 +-
 .../archivers/zip/ZipArchiveInputStreamTest.java   |   3 +-
 .../archivers/zip/ZipMemoryFileSystemTest.java     | 272 +++++++++++----------
 .../compress/compressors/Pack200TestCase.java      |   8 +-
 .../bzip2/BZip2CompressorInputStreamTest.java      |   3 +-
 .../Deflate64CompressorInputStreamTest.java        |   3 +-
 .../compressors/pack200/Pack200UtilsTest.java      |   4 +-
 37 files changed, 548 insertions(+), 588 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 47df2630..5db064fb 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -65,6 +65,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipUtils.isCompressedFileName(String) and deprecate isCompressedFilename(String).</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add SevenZOutputFile.putArchiveEntry(SevenZArchiveEntry) and deprecate putArchiveEntry(ArchiveEntry).</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add generics to ChangeSet and ChangeSetPerformer.</action>
+      <action type="add" dev="ggregory" due-to="Gary Gregory">Add generics to ArchiveStreamProvider and friends.</action>
       <!-- FIX -->
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Precompile regular expression in ArArchiveInputStream.isBSDLongName(String).</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Precompile regular expression in ArArchiveInputStream.isGNULongName(String).</action>
diff --git a/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java b/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
index 309668cc..9c2ef9dc 100644
--- a/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
+++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
@@ -48,10 +48,8 @@ import org.apache.commons.compress.utils.IOUtils;
 import org.apache.commons.compress.utils.Sets;
 
 /**
- * Factory to create Archive[In|Out]putStreams from names or the first bytes of
- * the InputStream. In order to add other implementations, you should extend
- * ArchiveStreamFactory and override the appropriate methods (and call their
- * implementation from super of course).
+ * Factory to create Archive[In|Out]putStreams from names or the first bytes of the InputStream. In order to add other implementations, you should extend
+ * ArchiveStreamFactory and override the appropriate methods (and call their implementation from super of course).
  *
  * Compressing a ZIP-File:
  *
@@ -80,6 +78,7 @@ import org.apache.commons.compress.utils.Sets;
  * out.close();
  * in.close();
  * </pre>
+ * 
  * @Immutable provided that the deprecated method setEntryEncoding is not used.
  * @ThreadSafe even if the deprecated method setEntryEncoding is used
  */
@@ -93,6 +92,7 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
 
     /**
      * The singleton instance using the platform default encoding.
+     * 
      * @since 1.21
      */
     public static final ArchiveStreamFactory DEFAULT = new ArchiveStreamFactory();
@@ -139,50 +139,56 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
 
     /**
      * Constant (value {@value}) used to identify the AR archive format.
+     * 
      * @since 1.1
      */
     public static final String AR = "ar";
 
     /**
-     * Constant (value {@value}) used to identify the ARJ archive format.
-     * Not supported as an output stream type.
+     * Constant (value {@value}) used to identify the ARJ archive format. Not supported as an output stream type.
+     * 
      * @since 1.6
      */
     public static final String ARJ = "arj";
 
     /**
      * Constant (value {@value}) used to identify the CPIO archive format.
+     * 
      * @since 1.1
      */
     public static final String CPIO = "cpio";
 
     /**
-     * Constant (value {@value}) used to identify the Unix DUMP archive format.
-     * Not supported as an output stream type.
+     * Constant (value {@value}) used to identify the Unix DUMP archive format. Not supported as an output stream type.
+     * 
      * @since 1.3
      */
     public static final String DUMP = "dump";
 
     /**
      * Constant (value {@value}) used to identify the JAR archive format.
+     * 
      * @since 1.1
      */
     public static final String JAR = "jar";
 
     /**
      * Constant used to identify the TAR archive format.
+     * 
      * @since 1.1
      */
     public static final String TAR = "tar";
 
     /**
      * Constant (value {@value}) used to identify the ZIP archive format.
+     * 
      * @since 1.1
      */
     public static final String ZIP = "zip";
 
     /**
      * Constant (value {@value}) used to identify the 7z archive format.
+     * 
      * @since 1.8
      */
     public static final String SEVEN_Z = "7z";
@@ -193,6 +199,7 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
 
     /**
      * Try to determine the type of Archiver
+     * 
      * @param in input stream
      * @return type of archiver if found
      * @throws ArchiveException if an archiver cannot be detected in the stream
@@ -280,27 +287,20 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
     }
 
     /**
-     * Constructs a new sorted map from input stream provider names to provider
-     * objects.
+     * Constructs a new sorted map from input stream provider names to provider objects.
      *
      * <p>
-     * The map returned by this method will have one entry for each provider for
-     * which support is available in the current Java virtual machine. If two or
-     * more supported provider have the same name then the resulting map will
-     * contain just one of them; which one it will contain is not specified.
+     * The map returned by this method will have one entry for each provider for which support is available in the current Java virtual machine. If two or more
+     * supported provider have the same name then the resulting map will contain just one of them; which one it will contain is not specified.
      * </p>
      *
      * <p>
-     * The invocation of this method, and the subsequent use of the resulting
-     * map, may cause time-consuming disk or network I/O operations to occur.
-     * This method is provided for applications that need to enumerate all of
-     * the available providers, for example to allow user provider selection.
+     * The invocation of this method, and the subsequent use of the resulting map, may cause time-consuming disk or network I/O operations to occur. This method
+     * is provided for applications that need to enumerate all of the available providers, for example to allow user provider selection.
      * </p>
      *
      * <p>
-     * This method may return different results at different times if new
-     * providers are dynamically made available to the current Java virtual
-     * machine.
+     * This method may return different results at different times if new providers are dynamically made available to the current Java virtual machine.
      * </p>
      *
      * @return An immutable, map from names to provider objects
@@ -316,27 +316,20 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
     }
 
     /**
-     * Constructs a new sorted map from output stream provider names to provider
-     * objects.
+     * Constructs a new sorted map from output stream provider names to provider objects.
      *
      * <p>
-     * The map returned by this method will have one entry for each provider for
-     * which support is available in the current Java virtual machine. If two or
-     * more supported provider have the same name then the resulting map will
-     * contain just one of them; which one it will contain is not specified.
+     * The map returned by this method will have one entry for each provider for which support is available in the current Java virtual machine. If two or more
+     * supported provider have the same name then the resulting map will contain just one of them; which one it will contain is not specified.
      * </p>
      *
      * <p>
-     * The invocation of this method, and the subsequent use of the resulting
-     * map, may cause time-consuming disk or network I/O operations to occur.
-     * This method is provided for applications that need to enumerate all of
-     * the available providers, for example to allow user provider selection.
+     * The invocation of this method, and the subsequent use of the resulting map, may cause time-consuming disk or network I/O operations to occur. This method
+     * is provided for applications that need to enumerate all of the available providers, for example to allow user provider selection.
      * </p>
      *
      * <p>
-     * This method may return different results at different times if new
-     * providers are dynamically made available to the current Java virtual
-     * machine.
+     * This method may return different results at different times if new providers are dynamically made available to the current Java virtual machine.
      * </p>
      *
      * @return An immutable, map from names to provider objects
@@ -394,40 +387,40 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
     }
 
     /**
-     * Create an archive input stream from an input stream, autodetecting
-     * the archive type from the first few bytes of the stream. The InputStream
-     * must support marks, like BufferedInputStream.
+     * Create an archive input stream from an input stream, autodetecting the archive type from the first few bytes of the stream. The InputStream must support
+     * marks, like BufferedInputStream.
      *
-     * @param in the input stream
+     * @param <I> The {@link ArchiveInputStream} type.
+     * @param in  the input stream
      * @return the archive input stream
-     * @throws ArchiveException if the archiver name is not known
-     * @throws StreamingNotSupportedException if the format cannot be
-     * read from a stream
-     * @throws IllegalArgumentException if the stream is null or does not support mark
+     * @throws ArchiveException               if the archiver name is not known
+     * @throws StreamingNotSupportedException if the format cannot be read from a stream
+     * @throws IllegalArgumentException       if the stream is null or does not support mark
      */
-    public ArchiveInputStream createArchiveInputStream(final InputStream in)
-            throws ArchiveException {
+    public <I extends ArchiveInputStream<? extends ArchiveEntry>> I createArchiveInputStream(final InputStream in) throws ArchiveException {
         return createArchiveInputStream(detect(in), in);
     }
 
     /**
      * Creates an archive input stream from an archiver name and an input stream.
      *
-     * @param archiverName the archive name,
-     * i.e. {@value #AR}, {@value #ARJ}, {@value #ZIP}, {@value #TAR}, {@value #JAR}, {@value #CPIO}, {@value #DUMP} or {@value #SEVEN_Z}
-     * @param in the input stream
+     * @param <I>          The {@link ArchiveInputStream} type.
+     * @param archiverName the archive name, i.e. {@value #AR}, {@value #ARJ}, {@value #ZIP}, {@value #TAR}, {@value #JAR}, {@value #CPIO}, {@value #DUMP} or
+     *                     {@value #SEVEN_Z}
+     * @param in           the input stream
      * @return the archive input stream
-     * @throws ArchiveException if the archiver name is not known
-     * @throws StreamingNotSupportedException if the format cannot be
-     * read from a stream
-     * @throws IllegalArgumentException if the archiver name or stream is null
+     * @throws ArchiveException               if the archiver name is not known
+     * @throws StreamingNotSupportedException if the format cannot be read from a stream
+     * @throws IllegalArgumentException       if the archiver name or stream is null
      */
-    public ArchiveInputStream createArchiveInputStream(final String archiverName, final InputStream in) throws ArchiveException {
+    public <I extends ArchiveInputStream<? extends ArchiveEntry>> I createArchiveInputStream(final String archiverName, final InputStream in)
+            throws ArchiveException {
         return createArchiveInputStream(archiverName, in, entryEncoding);
     }
 
+    @SuppressWarnings("unchecked")
     @Override
-    public ArchiveInputStream createArchiveInputStream(final String archiverName, final InputStream in,
+    public <I extends ArchiveInputStream<? extends ArchiveEntry>> I createArchiveInputStream(final String archiverName, final InputStream in,
             final String actualEncoding) throws ArchiveException {
 
         if (archiverName == null) {
@@ -439,43 +432,43 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
         }
 
         if (AR.equalsIgnoreCase(archiverName)) {
-            return new ArArchiveInputStream(in);
+            return (I) new ArArchiveInputStream(in);
         }
         if (ARJ.equalsIgnoreCase(archiverName)) {
             if (actualEncoding != null) {
-                return new ArjArchiveInputStream(in, actualEncoding);
+                return (I) new ArjArchiveInputStream(in, actualEncoding);
             }
-            return new ArjArchiveInputStream(in);
+            return (I) new ArjArchiveInputStream(in);
         }
         if (ZIP.equalsIgnoreCase(archiverName)) {
             if (actualEncoding != null) {
-                return new ZipArchiveInputStream(in, actualEncoding);
+                return (I) new ZipArchiveInputStream(in, actualEncoding);
             }
-            return new ZipArchiveInputStream(in);
+            return (I) new ZipArchiveInputStream(in);
         }
         if (TAR.equalsIgnoreCase(archiverName)) {
             if (actualEncoding != null) {
-                return new TarArchiveInputStream(in, actualEncoding);
+                return (I) new TarArchiveInputStream(in, actualEncoding);
             }
-            return new TarArchiveInputStream(in);
+            return (I) new TarArchiveInputStream(in);
         }
         if (JAR.equalsIgnoreCase(archiverName) || APK.equalsIgnoreCase(archiverName)) {
             if (actualEncoding != null) {
-                return new JarArchiveInputStream(in, actualEncoding);
+                return (I) new JarArchiveInputStream(in, actualEncoding);
             }
-            return new JarArchiveInputStream(in);
+            return (I) new JarArchiveInputStream(in);
         }
         if (CPIO.equalsIgnoreCase(archiverName)) {
             if (actualEncoding != null) {
-                return new CpioArchiveInputStream(in, actualEncoding);
+                return (I) new CpioArchiveInputStream(in, actualEncoding);
             }
-            return new CpioArchiveInputStream(in);
+            return (I) new CpioArchiveInputStream(in);
         }
         if (DUMP.equalsIgnoreCase(archiverName)) {
             if (actualEncoding != null) {
-                return new DumpArchiveInputStream(in, actualEncoding);
+                return (I) new DumpArchiveInputStream(in, actualEncoding);
             }
-            return new DumpArchiveInputStream(in);
+            return (I) new DumpArchiveInputStream(in);
         }
         if (SEVEN_Z.equalsIgnoreCase(archiverName)) {
             throw new StreamingNotSupportedException(SEVEN_Z);
@@ -492,24 +485,23 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
     /**
      * Creates an archive output stream from an archiver name and an output stream.
      *
-     * @param archiverName the archive name,
-     * i.e. {@value #AR}, {@value #ZIP}, {@value #TAR}, {@value #JAR} or {@value #CPIO}
-     * @param out the output stream
+     * @param <O>          The {@link ArchiveOutputStream} type.
+     * @param archiverName the archive name, i.e. {@value #AR}, {@value #ZIP}, {@value #TAR}, {@value #JAR} or {@value #CPIO}
+     * @param out          the output stream
      * @return the archive output stream
-     * @throws ArchiveException if the archiver name is not known
-     * @throws StreamingNotSupportedException if the format cannot be
-     * written to a stream
-     * @throws IllegalArgumentException if the archiver name or stream is null
+     * @throws ArchiveException               if the archiver name is not known
+     * @throws StreamingNotSupportedException if the format cannot be written to a stream
+     * @throws IllegalArgumentException       if the archiver name or stream is null
      */
-    public ArchiveOutputStream createArchiveOutputStream(final String archiverName, final OutputStream out)
+    public <O extends ArchiveOutputStream<? extends ArchiveEntry>> O createArchiveOutputStream(final String archiverName, final OutputStream out)
             throws ArchiveException {
         return createArchiveOutputStream(archiverName, out, entryEncoding);
     }
 
+    @SuppressWarnings("unchecked")
     @Override
-    public ArchiveOutputStream createArchiveOutputStream(
-            final String archiverName, final OutputStream out, final String actualEncoding)
-            throws ArchiveException {
+    public <O extends ArchiveOutputStream<? extends ArchiveEntry>> O createArchiveOutputStream(final String archiverName, final OutputStream out,
+            final String actualEncoding) throws ArchiveException {
         if (archiverName == null) {
             throw new IllegalArgumentException("Archiver name must not be null.");
         }
@@ -518,32 +510,32 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
         }
 
         if (AR.equalsIgnoreCase(archiverName)) {
-            return new ArArchiveOutputStream(out);
+            return (O) new ArArchiveOutputStream(out);
         }
         if (ZIP.equalsIgnoreCase(archiverName)) {
             final ZipArchiveOutputStream zip = new ZipArchiveOutputStream(out);
             if (actualEncoding != null) {
                 zip.setEncoding(actualEncoding);
             }
-            return zip;
+            return (O) zip;
         }
         if (TAR.equalsIgnoreCase(archiverName)) {
             if (actualEncoding != null) {
-                return new TarArchiveOutputStream(out, actualEncoding);
+                return (O) new TarArchiveOutputStream(out, actualEncoding);
             }
-            return new TarArchiveOutputStream(out);
+            return (O) new TarArchiveOutputStream(out);
         }
         if (JAR.equalsIgnoreCase(archiverName)) {
             if (actualEncoding != null) {
-                return new JarArchiveOutputStream(out, actualEncoding);
+                return (O) new JarArchiveOutputStream(out, actualEncoding);
             }
-            return new JarArchiveOutputStream(out);
+            return (O) new JarArchiveOutputStream(out);
         }
         if (CPIO.equalsIgnoreCase(archiverName)) {
             if (actualEncoding != null) {
-                return new CpioArchiveOutputStream(out, actualEncoding);
+                return (O) new CpioArchiveOutputStream(out, actualEncoding);
             }
-            return new CpioArchiveOutputStream(out);
+            return (O) new CpioArchiveOutputStream(out);
         }
         if (SEVEN_Z.equalsIgnoreCase(archiverName)) {
             throw new StreamingNotSupportedException(SEVEN_Z);
@@ -559,23 +551,20 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
 
     public SortedMap<String, ArchiveStreamProvider> getArchiveInputStreamProviders() {
         if (archiveInputStreamProviders == null) {
-            archiveInputStreamProviders = Collections
-                    .unmodifiableSortedMap(findAvailableArchiveInputStreamProviders());
+            archiveInputStreamProviders = Collections.unmodifiableSortedMap(findAvailableArchiveInputStreamProviders());
         }
         return archiveInputStreamProviders;
     }
 
     public SortedMap<String, ArchiveStreamProvider> getArchiveOutputStreamProviders() {
         if (archiveOutputStreamProviders == null) {
-            archiveOutputStreamProviders = Collections
-                    .unmodifiableSortedMap(findAvailableArchiveOutputStreamProviders());
+            archiveOutputStreamProviders = Collections.unmodifiableSortedMap(findAvailableArchiveOutputStreamProviders());
         }
         return archiveOutputStreamProviders;
     }
 
     /**
-     * Gets the encoding to use for arj, jar, ZIP, dump, cpio and tar
-     * files, or null for the archiver default.
+     * Gets the encoding to use for arj, jar, ZIP, dump, cpio and tar files, or null for the archiver default.
      *
      * @return entry encoding, or null for the archiver default
      * @since 1.5
@@ -600,8 +589,7 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
      * @param entryEncoding the entry encoding, null uses the archiver default.
      * @since 1.5
      * @deprecated 1.10 use {@link #ArchiveStreamFactory(String)} to specify the encoding
-     * @throws IllegalStateException if the constructor {@link #ArchiveStreamFactory(String)}
-     * was used to specify the factory encoding.
+     * @throws IllegalStateException if the constructor {@link #ArchiveStreamFactory(String)} was used to specify the factory encoding.
      */
     @Deprecated
     public void setEntryEncoding(final String entryEncoding) {
diff --git a/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamProvider.java b/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamProvider.java
index 16ef4d2c..2ceff0ca 100644
--- a/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamProvider.java
+++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamProvider.java
@@ -33,6 +33,7 @@ public interface ArchiveStreamProvider {
     /**
      * Creates an archive input stream from an archiver name and an input stream.
      *
+     * @param <I>          The {@link ArchiveInputStream} type.
      * @param archiverName the archiver name, i.e. {@value org.apache.commons.compress.archivers.ArchiveStreamFactory#AR},
      *                     {@value org.apache.commons.compress.archivers.ArchiveStreamFactory#ARJ},
      *                     {@value org.apache.commons.compress.archivers.ArchiveStreamFactory#ZIP},
@@ -48,11 +49,13 @@ public interface ArchiveStreamProvider {
      * @throws StreamingNotSupportedException if the format cannot be read from a stream
      * @throws IllegalArgumentException       if the archiver name or stream is null
      */
-    ArchiveInputStream createArchiveInputStream(final String archiverName, final InputStream inputStream, final String encoding) throws ArchiveException;
+    <I extends ArchiveInputStream<? extends ArchiveEntry>> I createArchiveInputStream(final String archiverName, final InputStream inputStream,
+            final String encoding) throws ArchiveException;
 
     /**
      * Creates an archive output stream from an archiver name and an output stream.
      *
+     * @param <O>          The {@link ArchiveInputStream} type.
      * @param archiverName the archiver name, i.e. {@value org.apache.commons.compress.archivers.ArchiveStreamFactory#AR},
      *                     {@value org.apache.commons.compress.archivers.ArchiveStreamFactory#ZIP},
      *                     {@value org.apache.commons.compress.archivers.ArchiveStreamFactory#TAR},
@@ -65,7 +68,8 @@ public interface ArchiveStreamProvider {
      * @throws StreamingNotSupportedException if the format cannot be written to a stream
      * @throws IllegalArgumentException       if the archiver name or stream is null
      */
-    ArchiveOutputStream createArchiveOutputStream(final String archiverName, final OutputStream outputStream, final String encoding) throws ArchiveException;
+    <O extends ArchiveOutputStream<? extends ArchiveEntry>> O createArchiveOutputStream(final String archiverName, final OutputStream outputStream,
+            final String encoding) throws ArchiveException;
 
     /**
      * Gets all the input stream archive names for this provider
diff --git a/src/main/java/org/apache/commons/compress/archivers/Lister.java b/src/main/java/org/apache/commons/compress/archivers/Lister.java
index c769534b..b4ce7d25 100644
--- a/src/main/java/org/apache/commons/compress/archivers/Lister.java
+++ b/src/main/java/org/apache/commons/compress/archivers/Lister.java
@@ -46,7 +46,8 @@ public final class Lister {
 
     private static final ArchiveStreamFactory FACTORY = ArchiveStreamFactory.DEFAULT;
 
-    private static ArchiveInputStream createArchiveInputStream(final String[] args, final InputStream inputStream) throws ArchiveException {
+    private static <T extends ArchiveInputStream<? extends E>, E extends ArchiveEntry> T createArchiveInputStream(final String[] args,
+            final InputStream inputStream) throws ArchiveException {
         if (args.length > 1) {
             return FACTORY.createArchiveInputStream(args[1], inputStream);
         }
@@ -54,8 +55,8 @@ public final class Lister {
     }
 
     private static String detectFormat(final File file) throws ArchiveException, IOException {
-        try (final InputStream fis = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
-            return ArchiveStreamFactory.detect(fis);
+        try (final InputStream inputStream = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
+            return ArchiveStreamFactory.detect(inputStream);
         }
     }
 
@@ -72,7 +73,7 @@ public final class Lister {
 
     private static void listStream(final File file, final String[] args) throws ArchiveException, IOException {
         try (final InputStream inputStream = new BufferedInputStream(Files.newInputStream(file.toPath()));
-                final ArchiveInputStream archiveInputStream = createArchiveInputStream(args, inputStream)) {
+                final ArchiveInputStream<?> archiveInputStream = createArchiveInputStream(args, inputStream)) {
             System.out.println("Created " + archiveInputStream.toString());
             ArchiveEntry entry;
             while ((entry = archiveInputStream.getNextEntry()) != null) {
diff --git a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
index ca6f2934..806e8443 100644
--- a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
@@ -22,7 +22,6 @@ import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.zip.ZipEncoding;
 import org.apache.commons.compress.archivers.zip.ZipEncodingHelper;
diff --git a/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java b/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java
index 5c595d81..c80409f7 100644
--- a/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java
+++ b/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java
@@ -52,14 +52,13 @@ import org.apache.commons.compress.utils.IOUtils;
  */
 public class Archiver {
 
-    private static class ArchiverFileVisitor extends SimpleFileVisitor<Path> {
+    private static class ArchiverFileVisitor<O extends ArchiveOutputStream<E>, E extends ArchiveEntry> extends SimpleFileVisitor<Path> {
 
-        private final ArchiveOutputStream target;
+        private final O target;
         private final Path directory;
         private final LinkOption[] linkOptions;
 
-        private ArchiverFileVisitor(final ArchiveOutputStream target, final Path directory,
-            final LinkOption... linkOptions) {
+        private ArchiverFileVisitor(final O target, final Path directory, final LinkOption... linkOptions) {
             this.target = target;
             this.directory = directory;
             this.linkOptions = linkOptions == null ? IOUtils.EMPTY_LINK_OPTIONS : linkOptions.clone();
@@ -70,14 +69,12 @@ public class Archiver {
             return visit(dir, attrs, false);
         }
 
-        protected FileVisitResult visit(final Path path, final BasicFileAttributes attrs, final boolean isFile)
-            throws IOException {
+        protected FileVisitResult visit(final Path path, final BasicFileAttributes attrs, final boolean isFile) throws IOException {
             Objects.requireNonNull(path);
             Objects.requireNonNull(attrs);
             final String name = directory.relativize(path).toString().replace('\\', '/');
             if (!name.isEmpty()) {
-                final ArchiveEntry archiveEntry = target.createArchiveEntry(path,
-                    isFile || name.endsWith("/") ? name : name + "/", linkOptions);
+                final E archiveEntry = target.createArchiveEntry(path, isFile || name.endsWith("/") ? name : name + "/", linkOptions);
                 target.putArchiveEntry(archiveEntry);
                 if (isFile) {
                     // Refactor this as a BiConsumer on Java 8
@@ -106,7 +103,7 @@ public class Archiver {
      * @param directory the directory that contains the files to archive.
      * @throws IOException if an I/O error occurs
      */
-    public void create(final ArchiveOutputStream target, final File directory) throws IOException {
+    public void create(final ArchiveOutputStream<?> target, final File directory) throws IOException {
         create(target, directory.toPath(), EMPTY_FileVisitOption);
     }
 
@@ -118,7 +115,7 @@ public class Archiver {
      * @throws IOException if an I/O error occurs or the archive cannot be created for other reasons.
      * @since 1.21
      */
-    public void create(final ArchiveOutputStream target, final Path directory) throws IOException {
+    public void create(final ArchiveOutputStream<?> target, final Path directory) throws IOException {
         create(target, directory, EMPTY_FileVisitOption);
     }
 
@@ -132,10 +129,9 @@ public class Archiver {
      * @throws IOException if an I/O error occurs or the archive cannot be created for other reasons.
      * @since 1.21
      */
-    public void create(final ArchiveOutputStream target, final Path directory,
-        final EnumSet<FileVisitOption> fileVisitOptions, final LinkOption... linkOptions) throws IOException {
-        Files.walkFileTree(directory, fileVisitOptions, Integer.MAX_VALUE,
-            new ArchiverFileVisitor(target, directory, linkOptions));
+    public void create(final ArchiveOutputStream<?> target, final Path directory,
+            final EnumSet<FileVisitOption> fileVisitOptions, final LinkOption... linkOptions) throws IOException {
+        Files.walkFileTree(directory, fileVisitOptions, Integer.MAX_VALUE, new ArchiverFileVisitor<>(target, directory, linkOptions));
         target.finish();
     }
 
@@ -244,7 +240,8 @@ public class Archiver {
     public void create(final String format, final OutputStream target, final File directory,
         final CloseableConsumer closeableConsumer) throws IOException, ArchiveException {
         try (CloseableConsumerAdapter c = new CloseableConsumerAdapter(closeableConsumer)) {
-            create(c.track(ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(format, target)), directory);
+            ArchiveOutputStream<? extends ArchiveEntry> archiveOutputStream = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(format, target);
+            create(c.track(archiveOutputStream), directory);
         }
     }
 
@@ -260,17 +257,16 @@ public class Archiver {
      * @since 1.21
      */
     public void create(final String format, final Path target, final Path directory)
-        throws IOException, ArchiveException {
+            throws IOException, ArchiveException {
         if (prefersSeekableByteChannel(format)) {
-            try (SeekableByteChannel channel = FileChannel.open(target, StandardOpenOption.WRITE,
-                StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
+            try (SeekableByteChannel channel = FileChannel.open(target, StandardOpenOption.WRITE, StandardOpenOption.CREATE,
+                    StandardOpenOption.TRUNCATE_EXISTING)) {
                 create(format, channel, directory);
                 return;
             }
         }
         try (@SuppressWarnings("resource") // ArchiveOutputStream wraps newOutputStream result
-        ArchiveOutputStream outputStream = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(format,
-            Files.newOutputStream(target))) {
+        ArchiveOutputStream<?> outputStream = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(format, Files.newOutputStream(target))) {
             create(outputStream, directory, EMPTY_FileVisitOption);
         }
     }
@@ -348,7 +344,7 @@ public class Archiver {
                 create(sevenZFile, directory);
             }
         } else if (ArchiveStreamFactory.ZIP.equalsIgnoreCase(format)) {
-            try (ArchiveOutputStream archiveOutputStream = new ZipArchiveOutputStream(target)) {
+            try (ZipArchiveOutputStream archiveOutputStream = new ZipArchiveOutputStream(target)) {
                 create(archiveOutputStream, directory, EMPTY_FileVisitOption);
             }
         } else {
diff --git a/src/main/java/org/apache/commons/compress/archivers/examples/Expander.java b/src/main/java/org/apache/commons/compress/archivers/examples/Expander.java
index 1f388882..b44d33f6 100644
--- a/src/main/java/org/apache/commons/compress/archivers/examples/Expander.java
+++ b/src/main/java/org/apache/commons/compress/archivers/examples/Expander.java
@@ -102,7 +102,7 @@ public class Expander {
      * @param targetDirectory the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
      * @throws IOException if an I/O error occurs
      */
-    public void expand(final ArchiveInputStream archive, final File targetDirectory) throws IOException {
+    public void expand(final ArchiveInputStream<?> archive, final File targetDirectory) throws IOException {
         expand(archive, toPath(targetDirectory));
     }
 
@@ -114,7 +114,7 @@ public class Expander {
      * @throws IOException if an I/O error occurs
      * @since 1.22
      */
-    public void expand(final ArchiveInputStream archive, final Path targetDirectory) throws IOException {
+    public void expand(final ArchiveInputStream<?> archive, final Path targetDirectory) throws IOException {
         expand(() -> {
             ArchiveEntry next = archive.getNextEntry();
             while (next != null && !archive.canReadEntryData(next)) {
@@ -315,10 +315,10 @@ public class Expander {
      * @since 1.22
      */
     public void expand(final String format, final InputStream archive, final Path targetDirectory, final CloseableConsumer closeableConsumer)
-        throws IOException, ArchiveException {
+            throws IOException, ArchiveException {
         try (CloseableConsumerAdapter c = new CloseableConsumerAdapter(closeableConsumer)) {
-            expand(c.track(ArchiveStreamFactory.DEFAULT.createArchiveInputStream(format, archive)),
-                targetDirectory);
+            ArchiveInputStream<?> archiveInputStream = ArchiveStreamFactory.DEFAULT.createArchiveInputStream(format, archive);
+            expand(c.track(archiveInputStream), targetDirectory);
         }
     }
 
diff --git a/src/test/java/org/apache/commons/compress/AbstractTestCase.java b/src/test/java/org/apache/commons/compress/AbstractTestCase.java
index 00971851..e481a0b6 100644
--- a/src/test/java/org/apache/commons/compress/AbstractTestCase.java
+++ b/src/test/java/org/apache/commons/compress/AbstractTestCase.java
@@ -130,9 +130,9 @@ public abstract class AbstractTestCase {
      * @throws IOException
      * @throws FileNotFoundException
      */
-    private void addArchiveEntry(final ArchiveOutputStream outputStream, final String fileName, final File inputFile)
+    private <O extends ArchiveOutputStream<E>, E extends ArchiveEntry> void addArchiveEntry(final O outputStream, final String fileName, final File inputFile)
             throws IOException, FileNotFoundException {
-        final ArchiveEntry entry = outputStream.createArchiveEntry(inputFile, fileName);
+        final E entry = outputStream.createArchiveEntry(inputFile, fileName);
         outputStream.putArchiveEntry(entry);
         Files.copy(inputFile.toPath(), outputStream);
         outputStream.closeArchiveEntry();
@@ -146,7 +146,7 @@ public abstract class AbstractTestCase {
      * @param expected list of expected entries or {@code null} if no check of names desired
      * @throws Exception
      */
-    protected void checkArchiveContent(final ArchiveInputStream inputStream, final List<String> expected)
+    protected void checkArchiveContent(final ArchiveInputStream<?> inputStream, final List<String> expected)
             throws Exception {
         checkArchiveContent(inputStream, expected, true);
     }
@@ -160,7 +160,7 @@ public abstract class AbstractTestCase {
      * @return returns the created result file if cleanUp = false, or null otherwise
      * @throws Exception
      */
-    protected File checkArchiveContent(final ArchiveInputStream inputStream, final List<String> expected, final boolean cleanUp)
+    protected File checkArchiveContent(final ArchiveInputStream<?> inputStream, final List<String> expected, final boolean cleanUp)
             throws Exception {
         final File result = mkdir("dir-result");
         result.deleteOnExit();
@@ -223,7 +223,7 @@ public abstract class AbstractTestCase {
      */
     protected void checkArchiveContent(final Path archive, final List<String> expected) throws Exception {
         try (InputStream inputStream = Files.newInputStream(archive);
-                ArchiveInputStream archiveInputStream = factory.createArchiveInputStream(new BufferedInputStream(inputStream))) {
+                ArchiveInputStream<?> archiveInputStream = factory.createArchiveInputStream(new BufferedInputStream(inputStream))) {
             checkArchiveContent(archiveInputStream, expected);
         }
     }
@@ -261,7 +261,7 @@ public abstract class AbstractTestCase {
         archivePath.toFile().deleteOnExit();
         archiveList = new ArrayList<>();
         try (OutputStream outputStream = Files.newOutputStream(archivePath);
-                ArchiveOutputStream archiveOutputStream = factory.createArchiveOutputStream(archiveName, outputStream)) {
+                ArchiveOutputStream<ArchiveEntry> archiveOutputStream = factory.createArchiveOutputStream(archiveName, outputStream)) {
             setLongFileMode(archiveOutputStream);
             final File file1 = getFile("test1.xml");
             final File file2 = getFile("test2.xml");
@@ -296,7 +296,7 @@ public abstract class AbstractTestCase {
         archivePath = Files.createTempFile("empty", "." + archiveName);
         archivePath.toFile().deleteOnExit();
         try (OutputStream outputStream = Files.newOutputStream(archivePath);
-                ArchiveOutputStream archiveOutputStream = factory.createArchiveOutputStream(archiveName, outputStream)) {
+                ArchiveOutputStream<?> archiveOutputStream = factory.createArchiveOutputStream(archiveName, outputStream)) {
             archiveOutputStream.finish();
         }
         return archivePath;
@@ -314,7 +314,7 @@ public abstract class AbstractTestCase {
         archivePath = Files.createTempFile("empty", "." + archiveName);
         archivePath.toFile().deleteOnExit();
         try (OutputStream outputStream = Files.newOutputStream(archivePath);
-                ArchiveOutputStream archiveOutputStream = factory.createArchiveOutputStream(archiveName, outputStream)) {
+                ArchiveOutputStream<?> archiveOutputStream = factory.createArchiveOutputStream(archiveName, outputStream)) {
             // Use short file name so does not cause problems for ar
             addArchiveEntry(archiveOutputStream, "test1.xml", getFile("test1.xml"));
             archiveOutputStream.finish();
@@ -357,7 +357,7 @@ public abstract class AbstractTestCase {
         return entry.getName();
     }
 
-    protected void setLongFileMode(final ArchiveOutputStream outputStream) {
+    protected void setLongFileMode(final ArchiveOutputStream<?> outputStream) {
         if (outputStream instanceof ArArchiveOutputStream) {
             ((ArArchiveOutputStream) outputStream).setLongFileMode(ArArchiveOutputStream.LONGFILE_BSD);
         }
diff --git a/src/test/java/org/apache/commons/compress/ChainingTestCase.java b/src/test/java/org/apache/commons/compress/ChainingTestCase.java
index 49ca63fd..de0e1f55 100644
--- a/src/test/java/org/apache/commons/compress/ChainingTestCase.java
+++ b/src/test/java/org/apache/commons/compress/ChainingTestCase.java
@@ -32,7 +32,7 @@ public class ChainingTestCase extends AbstractTestCase {
     @Test
     public void testTarBzip2() throws Exception {
         try (final TarArchiveInputStream is = new TarArchiveInputStream(new BZip2CompressorInputStream(newInputStream("bla.tar.bz2")))) {
-            final TarArchiveEntry entry = (TarArchiveEntry) is.getNextEntry();
+            final TarArchiveEntry entry = is.getNextEntry();
             assertNotNull(entry);
             assertEquals("test1.xml", entry.getName());
             assertEquals(TarConstants.LF_NORMAL, entry.getLinkFlag());
@@ -42,7 +42,7 @@ public class ChainingTestCase extends AbstractTestCase {
     @Test
     public void testTarGzip() throws Exception {
         try (final TarArchiveInputStream is = new TarArchiveInputStream(new GzipCompressorInputStream(newInputStream("bla.tgz")))) {
-            final TarArchiveEntry entry = (TarArchiveEntry) is.getNextEntry();
+            final TarArchiveEntry entry = is.getNextEntry();
             assertNotNull(entry);
             assertEquals("test1.xml", entry.getName());
             assertEquals(TarConstants.LF_NORMAL, entry.getLinkFlag());
diff --git a/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java b/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java
index 8b373eb6..c06cf54e 100644
--- a/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java
+++ b/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java
@@ -28,6 +28,7 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 
+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.ar.ArArchiveInputStream;
@@ -41,31 +42,34 @@ public final class DetectArchiverTestCase extends AbstractTestCase {
 
     final ClassLoader classLoader = getClass().getClassLoader();
 
-    private void checkEmptyArchive(final String type) throws Exception{
+    private void checkEmptyArchive(final String type) throws Exception {
         final Path ar = createEmptyArchive(type); // will be deleted by tearDown()
         ar.toFile().deleteOnExit(); // Just in case file cannot be deleted
         assertDoesNotThrow(() -> {
-            try (BufferedInputStream in = new BufferedInputStream(Files.newInputStream(ar));
-                 ArchiveInputStream ais = factory.createArchiveInputStream(in)) {
+            try (BufferedInputStream inputStream = new BufferedInputStream(Files.newInputStream(ar));
+                    ArchiveInputStream<?> ais = factory.createArchiveInputStream(inputStream)) {
+                // empty
             }
         }, "Should have recognized empty archive for " + type);
     }
 
-    private ArchiveInputStream getStreamFor(final String resource)
+    @SuppressWarnings("resource") // Caller closes
+    private <T extends ArchiveInputStream<? extends E>, E extends ArchiveEntry> T createArchiveInputStream(final String resource)
             throws ArchiveException, IOException {
         return factory.createArchiveInputStream(new BufferedInputStream(newInputStream(resource)));
     }
 
     @Test
     public void testCOMPRESS_117() throws Exception {
-        final ArchiveInputStream tar = getStreamFor("COMPRESS-117.tar");
-        assertNotNull(tar);
-        assertTrue(tar instanceof TarArchiveInputStream);
+        try (ArchiveInputStream<?> tar = createArchiveInputStream("COMPRESS-117.tar")) {
+            assertNotNull(tar);
+            assertTrue(tar instanceof TarArchiveInputStream);
+        }
     }
 
     @Test
     public void testCOMPRESS_335() throws Exception {
-        try (final ArchiveInputStream tar = getStreamFor("COMPRESS-335.tar")) {
+        try (ArchiveInputStream<?> tar = createArchiveInputStream("COMPRESS-335.tar")) {
             assertNotNull(tar);
             assertTrue(tar instanceof TarArchiveInputStream);
         }
@@ -74,38 +78,38 @@ public final class DetectArchiverTestCase extends AbstractTestCase {
     @Test
     public void testDetection() throws Exception {
 
-        try (final ArchiveInputStream ar = getStreamFor("bla.ar")) {
+        try (ArchiveInputStream<?> ar = createArchiveInputStream("bla.ar")) {
             assertNotNull(ar);
             assertTrue(ar instanceof ArArchiveInputStream);
         }
 
-        try (final ArchiveInputStream tar = getStreamFor("bla.tar")) {
+        try (ArchiveInputStream<?> tar = createArchiveInputStream("bla.tar")) {
             assertNotNull(tar);
             assertTrue(tar instanceof TarArchiveInputStream);
         }
 
-        try (final ArchiveInputStream zip = getStreamFor("bla.zip")) {
+        try (ArchiveInputStream<?> zip = createArchiveInputStream("bla.zip")) {
             assertNotNull(zip);
             assertTrue(zip instanceof ZipArchiveInputStream);
         }
 
-        try (final ArchiveInputStream jar = getStreamFor("bla.jar")) {
+        try (ArchiveInputStream<?> jar = createArchiveInputStream("bla.jar")) {
             assertNotNull(jar);
             assertTrue(jar instanceof ZipArchiveInputStream);
         }
 
-        try (final ArchiveInputStream cpio = getStreamFor("bla.cpio")) {
+        try (ArchiveInputStream<?> cpio = createArchiveInputStream("bla.cpio")) {
             assertNotNull(cpio);
             assertTrue(cpio instanceof CpioArchiveInputStream);
         }
 
-        try (final ArchiveInputStream arj = getStreamFor("bla.arj")) {
+        try (ArchiveInputStream<?> arj = createArchiveInputStream("bla.arj")) {
             assertNotNull(arj);
             assertTrue(arj instanceof ArjArchiveInputStream);
         }
 
 // Not yet implemented
-//        final ArchiveInputStream tgz = getStreamFor("bla.tgz");
+//        final ArchiveInputStream<?> tgz = getStreamFor("bla.tgz");
 //        assertNotNull(tgz);
 //        assertTrue(tgz instanceof TarArchiveInputStream);
 
@@ -120,7 +124,7 @@ public final class DetectArchiverTestCase extends AbstractTestCase {
 
     @Test
     public void testDetectionNotArchive() {
-        assertThrows(ArchiveException.class, () -> getStreamFor("test.txt"));
+        assertThrows(ArchiveException.class, () -> createArchiveInputStream("test.txt"));
     }
 
     @Test
diff --git a/src/test/java/org/apache/commons/compress/IOMethodsTest.java b/src/test/java/org/apache/commons/compress/IOMethodsTest.java
index 290c2b76..cda9acc2 100644
--- a/src/test/java/org/apache/commons/compress/IOMethodsTest.java
+++ b/src/test/java/org/apache/commons/compress/IOMethodsTest.java
@@ -46,9 +46,9 @@ public class IOMethodsTest extends AbstractTestCase {
     private static final int bytesToTest = 50;
     private static final byte[] byteTest = new byte[bytesToTest];
     static {
-        for(int i=0; i < byteTest.length ;) {
-            byteTest[i]=(byte) i;
-            byteTest[i+1]=(byte) -i;
+        for (int i = 0; i < byteTest.length;) {
+            byteTest[i] = (byte) i;
+            byteTest[i + 1] = (byte) -i;
             i += 2;
         }
     }
@@ -61,41 +61,41 @@ public class IOMethodsTest extends AbstractTestCase {
         file.toFile().deleteOnExit();
 
         final InputStream is1 = Files.newInputStream(file);
-        final ArchiveInputStream ais1 = factory.createArchiveInputStream(archiverName, is1);
+        final ArchiveInputStream<?> ais1 = factory.createArchiveInputStream(archiverName, is1);
         final ArchiveEntry nextEntry = ais1.getNextEntry();
         assertNotNull(nextEntry);
 
-        final byte [] buff = new byte[10]; // small so multiple reads are needed;
+        final byte[] buff = new byte[10]; // small so multiple reads are needed;
         final long size = nextEntry.getSize();
         if (size != ArchiveEntry.SIZE_UNKNOWN) {
             assertTrue(size > 0, "Size should be > 0, found: " + size);
         }
 
         final InputStream is2 = Files.newInputStream(file);
-        final ArchiveInputStream ais2 = factory.createArchiveInputStream(archiverName, is2);
+        final ArchiveInputStream<?> ais2 = factory.createArchiveInputStream(archiverName, is2);
         final ArchiveEntry nextEntry2 = ais2.getNextEntry();
         assertNotNull(nextEntry2);
         assertEquals(size, nextEntry2.getSize(), "Expected same entry size");
 
         final InputStream is3 = Files.newInputStream(file);
-        final ArchiveInputStream ais3 = factory.createArchiveInputStream(archiverName, is3);
+        final ArchiveInputStream<?> ais3 = factory.createArchiveInputStream(archiverName, is3);
         final ArchiveEntry nextEntry3 = ais3.getNextEntry();
         assertNotNull(nextEntry3);
         assertEquals(size, nextEntry3.getSize(), "Expected same entry size");
 
         int b;
-        while((b=ais1.read()) != -1){
+        while ((b = ais1.read()) != -1) {
             out1.write(b);
         }
         ais1.close();
 
         int bytes;
-        while((bytes = ais2.read(buff)) > 0){
+        while ((bytes = ais2.read(buff)) > 0) {
             out2.write(buff, 0, bytes);
         }
         ais2.close();
 
-        while((bytes=ais3.read(buff, 0 , buff.length)) > 0){
+        while ((bytes = ais3.read(buff, 0, buff.length)) > 0) {
             out3.write(buff, 0, bytes);
         }
         ais3.close();
@@ -110,11 +110,11 @@ public class IOMethodsTest extends AbstractTestCase {
         final OutputStream out1 = new ByteArrayOutputStream();
         final OutputStream out2 = new ByteArrayOutputStream();
         final OutputStream out3 = new ByteArrayOutputStream();
-        final ArchiveOutputStream aos1 = factory.createArchiveOutputStream(archiverName, out1);
+        final ArchiveOutputStream<ArchiveEntry> aos1 = factory.createArchiveOutputStream(archiverName, out1);
         aos1.putArchiveEntry(entry);
-        final ArchiveOutputStream aos2 = factory.createArchiveOutputStream(archiverName, out2);
+        final ArchiveOutputStream<ArchiveEntry> aos2 = factory.createArchiveOutputStream(archiverName, out2);
         aos2.putArchiveEntry(entry);
-        final ArchiveOutputStream aos3 = factory.createArchiveOutputStream(archiverName, out3);
+        final ArchiveOutputStream<ArchiveEntry> aos3 = factory.createArchiveOutputStream(archiverName, out3);
         aos3.putArchiveEntry(entry);
         for (final byte element : byteTest) {
             aos1.write(element);
diff --git a/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java b/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
index a90d88ed..150684de 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
@@ -48,7 +48,7 @@ public final class ArTestCase extends AbstractTestCase {
         final File file2 = getFile("test2.xml");
 
         try (final OutputStream out = Files.newOutputStream(output.toPath());
-                ArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("ar", out)) {
+                ArArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("ar", out)) {
             os.putArchiveEntry(new ArArchiveEntry("test1.xml", file1.length()));
             Files.copy(file1.toPath(), os);
             os.closeArchiveEntry();
@@ -68,7 +68,7 @@ public final class ArTestCase extends AbstractTestCase {
         {
             // create
             try (OutputStream out = Files.newOutputStream(output.toPath());
-                    ArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("ar", out)) {
+                    ArchiveOutputStream<ArArchiveEntry> os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("ar", out)) {
                 os.putArchiveEntry(new ArArchiveEntry("test1.xml", file1.length()));
                 Files.copy(file1.toPath(), os);
                 os.closeArchiveEntry();
@@ -90,10 +90,10 @@ public final class ArTestCase extends AbstractTestCase {
 
         try (OutputStream os = Files.newOutputStream(output2.toPath());
                 InputStream is = Files.newInputStream(output.toPath());
-                ArchiveOutputStream aos = new ArchiveStreamFactory().createArchiveOutputStream("ar", os);
-                ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(is))) {
+                ArchiveOutputStream<ArArchiveEntry> aos = new ArchiveStreamFactory().createArchiveOutputStream("ar", os);
+                ArchiveInputStream<ArArchiveEntry> ais = new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(is))) {
             while (true) {
-                final ArArchiveEntry entry = (ArArchiveEntry) ais.getNextEntry();
+                final ArArchiveEntry entry = ais.getNextEntry();
                 if (entry == null) {
                     break;
                 }
@@ -107,7 +107,6 @@ public final class ArTestCase extends AbstractTestCase {
                     IOUtils.copy(ais, new ByteArrayOutputStream());
                     deleted++;
                 }
-
             }
         }
 
@@ -120,9 +119,9 @@ public final class ArTestCase extends AbstractTestCase {
 
         {
             try (InputStream is = Files.newInputStream(output2.toPath());
-                    ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(is))) {
+                    ArchiveInputStream<ArArchiveEntry> ais = new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(is))) {
                 while (true) {
-                    final ArArchiveEntry entry = (ArArchiveEntry) ais.getNextEntry();
+                    final ArArchiveEntry entry = ais.getNextEntry();
                     if (entry == null) {
                         break;
                     }
@@ -147,7 +146,7 @@ public final class ArTestCase extends AbstractTestCase {
             final File file2 = getFile("test2.xml");
 
             try (OutputStream out = Files.newOutputStream(output.toPath());
-                    ArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("ar", out)) {
+                    ArchiveOutputStream<ArArchiveEntry> os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("ar", out)) {
                 os.putArchiveEntry(new ArArchiveEntry("test1.xml", file1.length()));
                 Files.copy(file1.toPath(), os);
                 os.closeArchiveEntry();
@@ -160,9 +159,8 @@ public final class ArTestCase extends AbstractTestCase {
 
         // UnArArchive Operation
         try (final InputStream is = Files.newInputStream(output.toPath());
-             final ArchiveInputStream in = new ArchiveStreamFactory()
-                        .createArchiveInputStream(new BufferedInputStream(is))) {
-            final ArArchiveEntry entry = (ArArchiveEntry) in.getNextEntry();
+                final ArchiveInputStream<ArArchiveEntry> in = new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(is))) {
+            final ArArchiveEntry entry = in.getNextEntry();
 
             final File target = new File(dir, entry.getName());
             Files.copy(in, target.toPath());
@@ -180,9 +178,7 @@ public final class ArTestCase extends AbstractTestCase {
             archive = File.createTempFile("test.", ".ar", tmp[0]);
             archive.deleteOnExit();
             aos = new ArArchiveOutputStream(Files.newOutputStream(archive.toPath()));
-            final ArArchiveEntry in = new ArArchiveEntry("foo", tmp[1].length(),
-                                                   0, 0, 0,
-                                                   tmp[1].lastModified() / 1000);
+            final ArArchiveEntry in = new ArArchiveEntry("foo", tmp[1].length(), 0, 0, 0, tmp[1].lastModified() / 1000);
             aos.putArchiveEntry(in);
             final byte[] b = new byte[(int) tmp[1].length()];
             fis = Files.newInputStream(tmp[1].toPath());
@@ -201,8 +197,7 @@ public final class ArTestCase extends AbstractTestCase {
             assertNotNull(out);
             assertEquals("foo", out.getName());
             assertEquals(tmp[1].length(), out.getSize());
-            assertEquals(tmp[1].lastModified() / 1000,
-                         out.getLastModifiedDate().getTime() / 1000);
+            assertEquals(tmp[1].lastModified() / 1000, out.getLastModifiedDate().getTime() / 1000);
             assertFalse(out.isDirectory());
         } finally {
             if (ais != null) {
diff --git a/src/test/java/org/apache/commons/compress/archivers/ArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/ArchiveOutputStreamTest.java
index d51ba4eb..a0d1f040 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ArchiveOutputStreamTest.java
@@ -34,11 +34,10 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 import org.junit.jupiter.api.Test;
 
-public class ArchiveOutputStreamTest extends AbstractTestCase {
+public class ArchiveOutputStreamTest<O extends ArchiveOutputStream<E>, E extends ArchiveEntry> extends AbstractTestCase {
 
-    private ArchiveOutputStream createArchiveWithDummyEntry(final String archiveType, final OutputStream out1, final File dummy)
-        throws Exception {
-        final ArchiveOutputStream aos1 = factory.createArchiveOutputStream(archiveType, out1);
+    private O createArchiveWithDummyEntry(final String archiveType, final OutputStream out1, final File dummy) throws Exception {
+        final O aos1 = factory.createArchiveOutputStream(archiveType, out1);
         aos1.putArchiveEntry(aos1.createArchiveEntry(dummy, "dummy"));
         Files.copy(dummy.toPath(), aos1);
         return aos1;
@@ -48,7 +47,7 @@ public class ArchiveOutputStreamTest extends AbstractTestCase {
         final OutputStream out1 = new ByteArrayOutputStream();
         final File dummy = getFile("test1.xml"); // need a real file
 
-        final ArchiveOutputStream aos1 = factory.createArchiveOutputStream(archiveType, out1);
+        final O aos1 = factory.createArchiveOutputStream(archiveType, out1);
         aos1.putArchiveEntry(aos1.createArchiveEntry(dummy, "dummy"));
         Files.copy(dummy.toPath(), aos1);
         aos1.closeArchiveEntry();
@@ -56,55 +55,50 @@ public class ArchiveOutputStreamTest extends AbstractTestCase {
 
         // TODO - check if archives ensure that data has been written to the stream?
 
-        final ArchiveOutputStream aos2 = factory.createArchiveOutputStream(archiveType, out1);
-        assertThrows(IOException.class, aos2::closeArchiveEntry,
-                "Should have raised IOException - closeArchiveEntry() called before putArchiveEntry()");
+        final O aos2 = factory.createArchiveOutputStream(archiveType, out1);
+        assertThrows(IOException.class, aos2::closeArchiveEntry, "Should have raised IOException - closeArchiveEntry() called before putArchiveEntry()");
 
         aos2.putArchiveEntry(aos2.createArchiveEntry(dummy, "dummy"));
         Files.copy(dummy.toPath(), aos2);
 
         // TODO check if second putArchiveEntry() can follow without closeAE?
 
-        assertThrows(IOException.class, aos2::finish,
-                "Should have raised IOException - finish() called before closeArchiveEntry()");
-        assertThrows(IOException.class, aos2::close,
-                "Should have raised IOException - close() called before closeArchiveEntry()");
+        assertThrows(IOException.class, aos2::finish, "Should have raised IOException - finish() called before closeArchiveEntry()");
+        assertThrows(IOException.class, aos2::close, "Should have raised IOException - close() called before closeArchiveEntry()");
 
-        final ArchiveOutputStream aos3 = createArchiveWithDummyEntry(archiveType, out1, dummy);
+        final O aos3 = createArchiveWithDummyEntry(archiveType, out1, dummy);
         aos3.closeArchiveEntry();
-        assertThrows(IOException.class, aos3::closeArchiveEntry,
-                "Should have raised IOException - closeArchiveEntry() called with no open entry");
+        assertThrows(IOException.class, aos3::closeArchiveEntry, "Should have raised IOException - closeArchiveEntry() called with no open entry");
 
-        final ArchiveOutputStream aos4 = createArchiveWithDummyEntry(archiveType, out1, dummy);
+        final O aos4 = createArchiveWithDummyEntry(archiveType, out1, dummy);
         aos4.closeArchiveEntry();
         aos4.finish();
         aos4.close();
-        assertThrows(IOException.class, aos4::finish,
-                "Should have raised IOException - finish() called after close()");
+        assertThrows(IOException.class, aos4::finish, "Should have raised IOException - finish() called after close()");
     }
 
     @Test
-    public void testCallSequenceAr() throws Exception{
+    public void testCallSequenceAr() throws Exception {
         doCallSequence("Ar");
     }
 
     @Test
-    public void testCallSequenceCpio() throws Exception{
+    public void testCallSequenceCpio() throws Exception {
         doCallSequence("Cpio");
     }
 
     @Test
-    public void testCallSequenceJar() throws Exception{
+    public void testCallSequenceJar() throws Exception {
         doCallSequence("Jar");
     }
 
     @Test
-    public void testCallSequenceTar() throws Exception{
+    public void testCallSequenceTar() throws Exception {
         doCallSequence("Tar");
     }
 
     @Test
-    public void testCallSequenceZip() throws Exception{
+    public void testCallSequenceZip() throws Exception {
         doCallSequence("Zip");
     }
 
@@ -112,49 +106,53 @@ public class ArchiveOutputStreamTest extends AbstractTestCase {
     public void testFinish() throws Exception {
         final OutputStream out1 = new ByteArrayOutputStream();
 
-        final ArchiveOutputStream aos1 = factory.createArchiveOutputStream("zip", out1);
-        aos1.putArchiveEntry(new ZipArchiveEntry("dummy"));
-        assertThrows(IOException.class, () -> aos1.finish(),
-                "After putArchive should follow closeArchive");
-
-        final ArchiveOutputStream aos2 = factory.createArchiveOutputStream("jar", out1);
-        aos2.putArchiveEntry(new JarArchiveEntry("dummy"));
-        assertThrows(IOException.class, () -> aos2.finish(),
-                "After putArchive should follow closeArchive");
-
-        final ArchiveOutputStream aos3 = factory.createArchiveOutputStream("ar", out1);
-        aos3.putArchiveEntry(new ArArchiveEntry("dummy", 100));
-        assertThrows(IOException.class, () -> aos3.finish(),
-                "After putArchive should follow closeArchive");
-
-        final ArchiveOutputStream aos4 = factory.createArchiveOutputStream("cpio", out1);
-        aos4.putArchiveEntry(new CpioArchiveEntry("dummy"));
-        assertThrows(IOException.class, () -> aos4.finish(),
-                "After putArchive should follow closeArchive");
-
-        final ArchiveOutputStream aos5 = factory.createArchiveOutputStream("tar", out1);
-        aos5.putArchiveEntry(new TarArchiveEntry("dummy"));
-        assertThrows(IOException.class, () -> aos5.finish(),
-                "After putArchive should follow closeArchive");
+        try (ArchiveOutputStream<? super ArchiveEntry> aios = factory.createArchiveOutputStream("zip", out1)) {
+            aios.putArchiveEntry(new ZipArchiveEntry("dummy"));
+            assertThrows(IOException.class, () -> aios.finish(), "After putArchiveEntry() should follow closeArchiveEntry()");
+            aios.closeArchiveEntry();
+        }
+
+        try (ArchiveOutputStream<JarArchiveEntry> aios = factory.createArchiveOutputStream("jar", out1)) {
+            aios.putArchiveEntry(new JarArchiveEntry("dummy"));
+            assertThrows(IOException.class, () -> aios.finish(), "After putArchiveEntry() should follow closeArchiveEntry()");
+            aios.closeArchiveEntry();
+        }
+
+        try (ArchiveOutputStream<ArArchiveEntry> aios = factory.createArchiveOutputStream("ar", out1)) {
+            aios.putArchiveEntry(new ArArchiveEntry("dummy", 100));
+            assertThrows(IOException.class, () -> aios.finish(), "After putArchiveEntry() should follow closeArchiveEntry()");
+            aios.closeArchiveEntry();
+        }
+
+        try (ArchiveOutputStream<CpioArchiveEntry> aios = factory.createArchiveOutputStream("cpio", out1)) {
+            aios.putArchiveEntry(new CpioArchiveEntry("dummy"));
+            assertThrows(IOException.class, () -> aios.finish(), "After putArchiveEntry() should follow closeArchiveEntry()");
+            aios.closeArchiveEntry();
+        }
+
+        try (ArchiveOutputStream<TarArchiveEntry> aios = factory.createArchiveOutputStream("tar", out1)) {
+            aios.putArchiveEntry(new TarArchiveEntry("dummy"));
+            assertThrows(IOException.class, () -> aios.finish(), "After putArchiveEntry() should follow closeArchiveEntry()");
+            aios.closeArchiveEntry();
+        }
     }
 
     @Test
     public void testOptionalFinish() throws Exception {
         final OutputStream out1 = new ByteArrayOutputStream();
 
-        try (ArchiveOutputStream aos1 = factory.createArchiveOutputStream("zip", out1)) {
+        try (ArchiveOutputStream<ZipArchiveEntry> aos1 = factory.createArchiveOutputStream("zip", out1)) {
             aos1.putArchiveEntry(new ZipArchiveEntry("dummy"));
             aos1.closeArchiveEntry();
         }
 
-        final ArchiveOutputStream finishTest;
-        try (ArchiveOutputStream aos1 = factory.createArchiveOutputStream("jar", out1)) {
+        final ArchiveOutputStream<JarArchiveEntry> finishTest;
+        try (ArchiveOutputStream<JarArchiveEntry> aos1 = factory.createArchiveOutputStream("jar", out1)) {
             finishTest = aos1;
             aos1.putArchiveEntry(new JarArchiveEntry("dummy"));
             aos1.closeArchiveEntry();
         }
-        assertThrows(IOException.class, () -> finishTest.finish(),
-                "finish() cannot follow close()");
+        assertThrows(IOException.class, () -> finishTest.finish(), "finish() cannot follow close()");
         finishTest.close();
     }
 }
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 fbe4ff12..ab604edc 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java
@@ -238,17 +238,19 @@ public class ArchiveStreamFactoryTest extends AbstractTestCase {
         }
     }
 
-    private ArchiveInputStream getInputStreamFor(final String resource, final ArchiveStreamFactory factory)
+    @SuppressWarnings("resource")
+    private <T extends ArchiveInputStream<? extends E>, E extends ArchiveEntry> T getInputStream(final String resource, final ArchiveStreamFactory factory)
             throws IOException, ArchiveException {
         return factory.createArchiveInputStream(new BufferedInputStream(newInputStream(resource)));
     }
 
-    private ArchiveInputStream getInputStreamFor(final String type, final String resource, final ArchiveStreamFactory factory)
-            throws IOException, ArchiveException {
+    @SuppressWarnings("resource")
+    private <T extends ArchiveInputStream<? extends E>, E extends ArchiveEntry> T getInputStream(final String type, final String resource,
+            final ArchiveStreamFactory factory) throws IOException, ArchiveException {
         return factory.createArchiveInputStream(type, new BufferedInputStream(newInputStream(resource)));
     }
 
-    private ArchiveOutputStream getOutputStreamFor(final String type, final ArchiveStreamFactory factory)
+    private <T extends ArchiveOutputStream<? extends E>, E extends ArchiveEntry> T getOutputStream(final String type, final ArchiveStreamFactory factory)
             throws ArchiveException {
         return factory.createArchiveOutputStream(type, new ByteArrayOutputStream());
     }
@@ -272,7 +274,7 @@ public class ArchiveStreamFactoryTest extends AbstractTestCase {
     public void skipsPK00Prefix() throws Exception {
         try (InputStream fis = newInputStream("COMPRESS-208.zip")) {
             try (InputStream bis = new BufferedInputStream(fis)) {
-                try (ArchiveInputStream ais = ArchiveStreamFactory.DEFAULT.createArchiveInputStream(bis)) {
+                try (ArchiveInputStream<?> ais = ArchiveStreamFactory.DEFAULT.createArchiveInputStream(bis)) {
                     assertTrue(ais instanceof ZipArchiveInputStream);
                 }
             }
@@ -348,11 +350,10 @@ public class ArchiveStreamFactoryTest extends AbstractTestCase {
         int failed = 0;
         for (int i = 1; i <= TESTS.length; i++) {
             final TestData test = TESTS[i - 1];
-            try (final ArchiveInputStream ais = getInputStreamFor(test.type, test.testFile, test.fac)) {
+            try (final ArchiveInputStream<?> ais = getInputStream(test.type, test.testFile, test.fac)) {
                 final String field = getField(ais, test.fieldName);
                 if (!eq(test.expectedEncoding, field)) {
-                    System.out.println("Failed test " + i + ". expected: " + test.expectedEncoding + " actual: " + field
-                            + " type: " + test.type);
+                    System.err.println("Failed test " + i + ". expected: " + test.expectedEncoding + " actual: " + field + " type: " + test.type);
                     failed++;
                 }
             }
@@ -367,11 +368,10 @@ public class ArchiveStreamFactoryTest extends AbstractTestCase {
         int failed = 0;
         for (int i = 1; i <= TESTS.length; i++) {
             final TestData test = TESTS[i - 1];
-            try (final ArchiveInputStream ais = getInputStreamFor(test.testFile, test.fac)) {
+            try (final ArchiveInputStream<?> ais = getInputStream(test.testFile, test.fac)) {
                 final String field = getField(ais, test.fieldName);
                 if (!eq(test.expectedEncoding, field)) {
-                    System.out.println("Failed test " + i + ". expected: " + test.expectedEncoding + " actual: " + field
-                            + " type: " + test.type);
+                    System.err.println("Failed test " + i + ". expected: " + test.expectedEncoding + " actual: " + field + " type: " + test.type);
                     failed++;
                 }
             }
@@ -384,14 +384,13 @@ public class ArchiveStreamFactoryTest extends AbstractTestCase {
     @Test
     public void testEncodingOutputStream() throws Exception {
         int failed = 0;
-        for(int i = 1; i <= TESTS.length; i++) {
-            final TestData test = TESTS[i-1];
+        for (int i = 1; i <= TESTS.length; i++) {
+            final TestData test = TESTS[i - 1];
             if (test.hasOutputStream) {
-                try (final ArchiveOutputStream ais = getOutputStreamFor(test.type, test.fac)) {
+                try (final ArchiveOutputStream<?> ais = getOutputStream(test.type, test.fac)) {
                     final String field = getField(ais, test.fieldName);
                     if (!eq(test.expectedEncoding, field)) {
-                        System.out.println("Failed test " + i + ". expected: " + test.expectedEncoding + " actual: "
-                                + field + " type: " + test.type);
+                        System.err.println("Failed test " + i + ". expected: " + test.expectedEncoding + " actual: " + field + " type: " + test.type);
                         failed++;
                     }
                 }
diff --git a/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java b/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java
index 989e914a..2730336e 100644
--- a/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java
@@ -46,18 +46,17 @@ public final class CpioTestCase extends AbstractTestCase {
         final File file1 = getFile("test1.xml");
         final File file2 = getFile("test2.xml");
 
-        final OutputStream out = Files.newOutputStream(output.toPath());
-        final ArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("cpio", out);
-        os.putArchiveEntry(new CpioArchiveEntry("test1.xml", file1.length()));
-        Files.copy(file1.toPath(), os);
-        os.closeArchiveEntry();
+        try (OutputStream outputStream = Files.newOutputStream(output.toPath());
+                final ArchiveOutputStream<CpioArchiveEntry> archiveOutputStream = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("cpio",
+                        outputStream)) {
+            archiveOutputStream.putArchiveEntry(new CpioArchiveEntry("test1.xml", file1.length()));
+            Files.copy(file1.toPath(), archiveOutputStream);
+            archiveOutputStream.closeArchiveEntry();
 
-        os.putArchiveEntry(new CpioArchiveEntry("test2.xml", file2.length()));
-        Files.copy(file2.toPath(), os);
-        os.closeArchiveEntry();
-
-        os.close();
-        out.close();
+            archiveOutputStream.putArchiveEntry(new CpioArchiveEntry("test2.xml", file2.length()));
+            Files.copy(file2.toPath(), archiveOutputStream);
+            archiveOutputStream.closeArchiveEntry();
+        }
     }
 
     @Test
@@ -68,76 +67,69 @@ public final class CpioTestCase extends AbstractTestCase {
         final long file1Length = file1.length();
         final long file2Length = file2.length();
 
-        {
-            final OutputStream out = Files.newOutputStream(output.toPath());
-            final ArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("cpio", out);
+        try (OutputStream outputStream = Files.newOutputStream(output.toPath());
+                ArchiveOutputStream<CpioArchiveEntry> archiveOutputStream = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("cpio", outputStream)) {
             CpioArchiveEntry entry = new CpioArchiveEntry("test1.xml", file1Length);
             entry.setMode(CpioConstants.C_ISREG);
-            os.putArchiveEntry(entry);
-            Files.copy(file1.toPath(), os);
-            os.closeArchiveEntry();
+            archiveOutputStream.putArchiveEntry(entry);
+            Files.copy(file1.toPath(), archiveOutputStream);
+            archiveOutputStream.closeArchiveEntry();
 
             entry = new CpioArchiveEntry("test2.xml", file2Length);
             entry.setMode(CpioConstants.C_ISREG);
-            os.putArchiveEntry(entry);
-            Files.copy(file2.toPath(), os);
-            os.closeArchiveEntry();
-            os.finish();
-            os.close();
-            out.close();
+            archiveOutputStream.putArchiveEntry(entry);
+            Files.copy(file2.toPath(), archiveOutputStream);
+            archiveOutputStream.closeArchiveEntry();
+            archiveOutputStream.finish();
+            archiveOutputStream.close();
+            outputStream.close();
         }
 
         // Unarchive Operation
-        final InputStream is = Files.newInputStream(output.toPath());
-        final ArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("cpio", is);
-
-
         final Map<String, File> result = new HashMap<>();
-        ArchiveEntry entry;
-        while ((entry = in.getNextEntry()) != null) {
-            final File cpioget = new File(dir, entry.getName());
-            Files.copy(in, cpioget.toPath());
-            result.put(entry.getName(), cpioget);
+        try (InputStream inputStream = Files.newInputStream(output.toPath());
+                ArchiveInputStream<?> archiveInputStream = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("cpio", inputStream)) {
+            ArchiveEntry entry;
+            while ((entry = archiveInputStream.getNextEntry()) != null) {
+                final File cpioget = new File(dir, entry.getName());
+                Files.copy(archiveInputStream, cpioget.toPath());
+                result.put(entry.getName(), cpioget);
+            }
         }
-        in.close();
-        is.close();
 
-        File t = result.get("test1.xml");
-        assertTrue(t.exists(), "Expected " + t.getAbsolutePath() + " to exist");
-        assertEquals(file1Length, t.length(), "length of " + t.getAbsolutePath());
+        File testFile = result.get("test1.xml");
+        assertTrue(testFile.exists(), "Expected " + testFile.getAbsolutePath() + " to exist");
+        assertEquals(file1Length, testFile.length(), "length of " + testFile.getAbsolutePath());
 
-        t = result.get("test2.xml");
-        assertTrue(t.exists(), "Expected " + t.getAbsolutePath() + " to exist");
-        assertEquals(file2Length, t.length(), "length of " + t.getAbsolutePath());
+        testFile = result.get("test2.xml");
+        assertTrue(testFile.exists(), "Expected " + testFile.getAbsolutePath() + " to exist");
+        assertEquals(file2Length, testFile.length(), "length of " + testFile.getAbsolutePath());
     }
 
     @Test
     public void testDirectoryEntryFromFile() throws Exception {
         final File[] tmp = createTempDirAndFile();
         File archive = null;
-        CpioArchiveOutputStream tos = null;
-        CpioArchiveInputStream tis = null;
+        archive = File.createTempFile("test.", ".cpio", tmp[0]);
+        archive.deleteOnExit();
+        CpioArchiveOutputStream tos = new CpioArchiveOutputStream(Files.newOutputStream(archive.toPath()));
+        CpioArchiveInputStream tis = new CpioArchiveInputStream(Files.newInputStream(archive.toPath()));
         try {
-            archive = File.createTempFile("test.", ".cpio", tmp[0]);
-            archive.deleteOnExit();
-            tos = new CpioArchiveOutputStream(Files.newOutputStream(archive.toPath()));
             final long beforeArchiveWrite = tmp[0].lastModified();
-            final CpioArchiveEntry in = new CpioArchiveEntry(tmp[0], "foo");
-            tos.putArchiveEntry(in);
+            final CpioArchiveEntry entryIn = new CpioArchiveEntry(tmp[0], "foo");
+            tos.putArchiveEntry(entryIn);
             tos.closeArchiveEntry();
             tos.close();
             tos = null;
-            tis = new CpioArchiveInputStream(Files.newInputStream(archive.toPath()));
-            final CpioArchiveEntry out = tis.getNextCPIOEntry();
+            final CpioArchiveEntry entryOut = tis.getNextCPIOEntry();
             tis.close();
             tis = null;
-            assertNotNull(out);
-            assertEquals("foo", out.getName());
-            assertEquals(0, out.getSize());
+            assertNotNull(entryOut);
+            assertEquals("foo", entryOut.getName());
+            assertEquals(0, entryOut.getSize());
             // CPIO stores time with a granularity of 1 second
-            assertEquals(beforeArchiveWrite / 1000,
-                         out.getLastModifiedDate().getTime() / 1000);
-            assertTrue(out.isDirectory());
+            assertEquals(beforeArchiveWrite / 1000, entryOut.getLastModifiedDate().getTime() / 1000);
+            assertTrue(entryOut.isDirectory());
         } finally {
             if (tis != null) {
                 tis.close();
diff --git a/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java b/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java
index 8cb9cef9..9d13f036 100644
--- a/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java
@@ -85,7 +85,7 @@ public final class DumpTestCase extends AbstractTestCase {
 
     private void unarchiveAll(final File input) throws Exception {
         try (InputStream is = Files.newInputStream(input.toPath());
-                ArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("dump", is)) {
+                ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("dump", is)) {
             ArchiveEntry entry = in.getNextEntry();
             while (entry != null) {
                 final File archiveEntry = new File(dir, entry.getName());
diff --git a/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java b/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java
index ca059682..4dcce2d7 100644
--- a/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java
@@ -25,6 +25,7 @@ import java.nio.file.Files;
 
 import org.apache.commons.compress.AbstractTestCase;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
+import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 import org.junit.jupiter.api.Test;
 
 public final class JarTestCase extends AbstractTestCase {
@@ -37,7 +38,7 @@ public final class JarTestCase extends AbstractTestCase {
         final File file2 = getFile("test2.xml");
 
         try (OutputStream out = Files.newOutputStream(output.toPath());
-                ArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("jar", out)) {
+                ArchiveOutputStream<ZipArchiveEntry> os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("jar", out)) {
             os.putArchiveEntry(new ZipArchiveEntry("testdata/test1.xml"));
             Files.copy(file1.toPath(), os);
             os.closeArchiveEntry();
@@ -53,19 +54,19 @@ public final class JarTestCase extends AbstractTestCase {
     public void testJarUnarchive() throws Exception {
         final File input = getFile("bla.jar");
         try (InputStream is = Files.newInputStream(input.toPath());
-                ArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
+                ZipArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
 
-            ZipArchiveEntry entry = (ZipArchiveEntry) in.getNextEntry();
+            ZipArchiveEntry entry = in.getNextEntry();
             File o = new File(dir, entry.getName());
             o.getParentFile().mkdirs();
             Files.copy(in, o.toPath());
 
-            entry = (ZipArchiveEntry) in.getNextEntry();
+            entry = in.getNextEntry();
             o = new File(dir, entry.getName());
             o.getParentFile().mkdirs();
             Files.copy(in, o.toPath());
 
-            entry = (ZipArchiveEntry) in.getNextEntry();
+            entry = in.getNextEntry();
             o = new File(dir, entry.getName());
             o.getParentFile().mkdirs();
             Files.copy(in, o.toPath());
@@ -76,7 +77,7 @@ public final class JarTestCase extends AbstractTestCase {
     public void testJarUnarchiveAll() throws Exception {
         final File input = getFile("bla.jar");
         try (InputStream is = Files.newInputStream(input.toPath());
-                final ArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
+                final ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
 
             ArchiveEntry entry = in.getNextEntry();
             while (entry != null) {
diff --git a/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java b/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java
index caa59552..b1c79249 100644
--- a/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java
@@ -105,7 +105,7 @@ public class LongPathTest extends AbstractTestCase {
             expected.add("META-INF/");
             expected.add("META-INF/MANIFEST.MF");
         }
-        try (ArchiveInputStream ais = factory.createArchiveInputStream(new BufferedInputStream(Files.newInputStream(file.toPath())))) {
+        try (ArchiveInputStream<?> ais = factory.createArchiveInputStream(new BufferedInputStream(Files.newInputStream(file.toPath())))) {
             // check if expected type recognized
             if (name.endsWith(".tar")) {
                 assertTrue(ais instanceof TarArchiveInputStream);
diff --git a/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java b/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java
index 2f95ecf9..97b0816d 100644
--- a/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java
@@ -107,7 +107,7 @@ public class LongSymLinkTest extends AbstractTestCase {
             expected.add("META-INF/");
             expected.add("META-INF/MANIFEST.MF");
         }
-        final ArchiveInputStream ais = factory.createArchiveInputStream(new BufferedInputStream(Files.newInputStream(file.toPath())));
+        final ArchiveInputStream<?> ais = factory.createArchiveInputStream(new BufferedInputStream(Files.newInputStream(file.toPath())));
         // check if expected type recognized
         if (name.endsWith(".tar")){
             assertTrue(ais instanceof TarArchiveInputStream);
diff --git a/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java b/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java
index 9a8372a6..eb5eef50 100644
--- a/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java
@@ -73,11 +73,11 @@ public final class TarTestCase extends AbstractTestCase {
     public void testCOMPRESS114() throws Exception {
         final File input = getFile("COMPRESS-114.tar");
         try (final InputStream is = Files.newInputStream(input.toPath());
-             final ArchiveInputStream in = new TarArchiveInputStream(is, CharsetNames.ISO_8859_1)) {
-            TarArchiveEntry entry = (TarArchiveEntry) in.getNextEntry();
+             final TarArchiveInputStream in = new TarArchiveInputStream(is, CharsetNames.ISO_8859_1)) {
+            TarArchiveEntry entry = in.getNextEntry();
             assertEquals("3\u00b1\u00b1\u00b1F06\u00b1W2345\u00b1ZB\u00b1la\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1BLA", entry.getName());
             assertEquals(TarConstants.LF_NORMAL, entry.getLinkFlag());
-            entry = (TarArchiveEntry) in.getNextEntry();
+            entry = in.getNextEntry();
             assertEquals("0302-0601-3\u00b1\u00b1\u00b1F06\u00b1W2345\u00b1ZB\u00b1la\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1BLA", entry.getName());
             assertEquals(TarConstants.LF_NORMAL, entry.getLinkFlag());
         }
@@ -86,7 +86,8 @@ public final class TarTestCase extends AbstractTestCase {
     @Test
     public void testCOMPRESS178() throws Exception {
         final File input = getFile("COMPRESS-178.tar");
-        try (InputStream is = Files.newInputStream(input.toPath()); ArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("tar", is)) {
+        try (InputStream is = Files.newInputStream(input.toPath());
+                ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("tar", is)) {
             final IOException e = assertThrows(IOException.class, in::getNextEntry, "Expected IOException");
             final Throwable t = e.getCause();
             assertInstanceOf(IllegalArgumentException.class, t, "Expected cause = IllegalArgumentException");
@@ -97,7 +98,7 @@ public final class TarTestCase extends AbstractTestCase {
     public void testCOMPRESS178Lenient() throws Exception {
         final File input = getFile("COMPRESS-178.tar");
         try (final InputStream is = Files.newInputStream(input.toPath());
-             final ArchiveInputStream in = new TarArchiveInputStream(is, true)) {
+                final ArchiveInputStream<?> in = new TarArchiveInputStream(is, true)) {
             in.getNextEntry();
         }
     }
@@ -204,36 +205,33 @@ public final class TarTestCase extends AbstractTestCase {
         File archive = null;
         TarArchiveOutputStream tos = null;
         TarArchiveInputStream tis = null;
-        InputStream fis = null;
         try {
             archive = File.createTempFile("test.", ".tar", tmp[0]);
             archive.deleteOnExit();
             tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()));
-            final TarArchiveEntry in = new TarArchiveEntry("foo");
-            in.setModTime(tmp[1].lastModified());
-            in.setSize(tmp[1].length());
-            tos.putArchiveEntry(in);
+            final TarArchiveEntry entryIn = new TarArchiveEntry("foo");
+            entryIn.setModTime(tmp[1].lastModified());
+            entryIn.setSize(tmp[1].length());
+            tos.putArchiveEntry(entryIn);
             final byte[] b = new byte[(int) tmp[1].length()];
-            fis = Files.newInputStream(tmp[1].toPath());
-            while (fis.read(b) > 0) {
-                tos.write(b);
+            try (InputStream fis = Files.newInputStream(tmp[1].toPath())) {
+                while (fis.read(b) > 0) {
+                    tos.write(b);
+                }
             }
-            fis.close();
-            fis = null;
             tos.closeArchiveEntry();
             tos.close();
             tos = null;
             tis = new TarArchiveInputStream(Files.newInputStream(archive.toPath()));
-            final TarArchiveEntry out = tis.getNextTarEntry();
+            final TarArchiveEntry entryOut = tis.getNextTarEntry();
             tis.close();
             tis = null;
-            assertNotNull(out);
-            assertEquals("foo", out.getName());
-            assertEquals(TarConstants.LF_NORMAL, out.getLinkFlag());
-            assertEquals(tmp[1].length(), out.getSize());
-            assertEquals(tmp[1].lastModified() / 1000,
-                         out.getLastModifiedDate().getTime() / 1000);
-            assertFalse(out.isDirectory());
+            assertNotNull(entryOut);
+            assertEquals("foo", entryOut.getName());
+            assertEquals(TarConstants.LF_NORMAL, entryOut.getLinkFlag());
+            assertEquals(tmp[1].length(), entryOut.getSize());
+            assertEquals(tmp[1].lastModified() / 1000, entryOut.getLastModifiedDate().getTime() / 1000);
+            assertFalse(entryOut.isDirectory());
         } finally {
             if (tis != null) {
                 tis.close();
@@ -242,9 +240,6 @@ public final class TarTestCase extends AbstractTestCase {
                 tos.close();
             }
             tryHardToDelete(archive);
-            if (fis != null) {
-                fis.close();
-            }
             tryHardToDelete(tmp[1]);
             rmdir(tmp[0]);
         }
@@ -254,47 +249,32 @@ public final class TarTestCase extends AbstractTestCase {
     public void testFileEntryFromFile() throws Exception {
         final File[] tmp = createTempDirAndFile();
         File archive = null;
-        TarArchiveOutputStream tos = null;
-        TarArchiveInputStream tis = null;
-        InputStream fis = null;
+        archive = File.createTempFile("test.", ".tar", tmp[0]);
+        archive.deleteOnExit();
+        final TarArchiveEntry in = new TarArchiveEntry(tmp[1], "foo");
         try {
-            archive = File.createTempFile("test.", ".tar", tmp[0]);
-            archive.deleteOnExit();
-            tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()));
-            final TarArchiveEntry in = new TarArchiveEntry(tmp[1], "foo");
-            tos.putArchiveEntry(in);
-            final byte[] b = new byte[(int) tmp[1].length()];
-            fis = Files.newInputStream(tmp[1].toPath());
-            while (fis.read(b) > 0) {
-                tos.write(b);
+            try (TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+                tos.putArchiveEntry(in);
+                final byte[] b = new byte[(int) tmp[1].length()];
+                try (InputStream fis = Files.newInputStream(tmp[1].toPath())) {
+                    while (fis.read(b) > 0) {
+                        tos.write(b);
+                    }
+                }
+                tos.closeArchiveEntry();
+            }
+            final TarArchiveEntry out;
+            try (TarArchiveInputStream tis = new TarArchiveInputStream(Files.newInputStream(archive.toPath()))) {
+                out = tis.getNextTarEntry();
             }
-            fis.close();
-            fis = null;
-            tos.closeArchiveEntry();
-            tos.close();
-            tos = null;
-            tis = new TarArchiveInputStream(Files.newInputStream(archive.toPath()));
-            final TarArchiveEntry out = tis.getNextTarEntry();
-            tis.close();
-            tis = null;
             assertNotNull(out);
             assertEquals("foo", out.getName());
             assertEquals(TarConstants.LF_NORMAL, out.getLinkFlag());
             assertEquals(tmp[1].length(), out.getSize());
-            assertEquals(tmp[1].lastModified() / 1000,
-                         out.getLastModifiedDate().getTime() / 1000);
+            assertEquals(tmp[1].lastModified() / 1000, out.getLastModifiedDate().getTime() / 1000);
             assertFalse(out.isDirectory());
         } finally {
-            if (tis != null) {
-                tis.close();
-            }
-            if (tos != null) {
-                tos.close();
-            }
             tryHardToDelete(archive);
-            if (fis != null) {
-                fis.close();
-            }
             tryHardToDelete(tmp[1]);
             rmdir(tmp[0]);
         }
@@ -320,7 +300,7 @@ public final class TarTestCase extends AbstractTestCase {
         final File output = new File(dir, "bla.tar");
         final File file1 = getFile("test1.xml");
         try (OutputStream out = Files.newOutputStream(output.toPath());
-                ArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("tar", out)) {
+                TarArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("tar", out)) {
             final TarArchiveEntry entry = new TarArchiveEntry("testdata/test1.xml");
             entry.setModTime(0);
             entry.setSize(file1.length());
@@ -343,28 +323,25 @@ public final class TarTestCase extends AbstractTestCase {
 
         final File output = new File(dir, "bla.tar");
         final File file1 = getFile("test1.xml");
-        final OutputStream out = Files.newOutputStream(output.toPath());
-        final ArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("tar", out);
         final TarArchiveEntry entry = new TarArchiveEntry(name);
-        entry.setModTime(0);
-        entry.setSize(file1.length());
-        entry.setUserId(0);
-        entry.setGroupId(0);
-        entry.setUserName("avalon");
-        entry.setGroupName("excalibur");
-        entry.setMode(0100000);
-        os.putArchiveEntry(entry);
-        Files.copy(file1.toPath(), os);
-        os.closeArchiveEntry();
-        os.close();
-        out.close();
-
-        ArchiveOutputStream os2 = null;
-        try {
-            final String toLongName = "testdata/123456789012345678901234567890123456789012345678901234567890123456789012345678901234567.xml";
-            final File output2 = new File(dir, "bla.tar");
-            final OutputStream out2 = Files.newOutputStream(output2.toPath());
-            os2 = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("tar", out2);
+        try (OutputStream out = Files.newOutputStream(output.toPath());
+                TarArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("tar", out)) {
+            entry.setModTime(0);
+            entry.setSize(file1.length());
+            entry.setUserId(0);
+            entry.setGroupId(0);
+            entry.setUserName("avalon");
+            entry.setGroupName("excalibur");
+            entry.setMode(0100000);
+            os.putArchiveEntry(entry);
+            Files.copy(file1.toPath(), os);
+            os.closeArchiveEntry();
+        }
+
+        final String toLongName = "testdata/123456789012345678901234567890123456789012345678901234567890123456789012345678901234567.xml";
+        final File output2 = new File(dir, "bla.tar");
+        try (OutputStream out2 = Files.newOutputStream(output2.toPath());
+                TarArchiveOutputStream os2 = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("tar", out2);) {
             final TarArchiveEntry entry2 = new TarArchiveEntry(toLongName);
             entry2.setModTime(0);
             entry2.setSize(file1.length());
@@ -378,10 +355,6 @@ public final class TarTestCase extends AbstractTestCase {
             os2.closeArchiveEntry();
         } catch (final IOException e) {
             assertTrue(true);
-        } finally {
-            if (os2 != null){
-                os2.close();
-            }
         }
     }
 
@@ -576,9 +549,11 @@ public final class TarTestCase extends AbstractTestCase {
     @Test
     public void testTarFileUnarchive() throws Exception {
         final File file = getFile("bla.tar");
-        try (final TarFile tarFile = new TarFile(file)) {
-            final TarArchiveEntry entry = tarFile.getEntries().get(0);
-            Files.copy(tarFile.getInputStream(entry), new File(dir, entry.getName()).toPath());
+        try (TarFile tarFile = new TarFile(file)) {
+            TarArchiveEntry entry = tarFile.getEntries().get(0);
+            try (InputStream inputStream = tarFile.getInputStream(entry)) {
+                Files.copy(inputStream, new File(dir, entry.getName()).toPath());
+            }
         }
     }
 
@@ -586,8 +561,8 @@ public final class TarTestCase extends AbstractTestCase {
     public void testTarUnarchive() throws Exception {
         final File input = getFile("bla.tar");
         try (final InputStream is = Files.newInputStream(input.toPath());
-                final ArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("tar", is)) {
-            final TarArchiveEntry entry = (TarArchiveEntry) in.getNextEntry();
+                final TarArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("tar", is)) {
+            final TarArchiveEntry entry = in.getNextEntry();
             Files.copy(in, new File(dir, entry.getName()).toPath());
         }
     }
diff --git a/src/test/java/org/apache/commons/compress/archivers/TestArchiveStreamProvider.java b/src/test/java/org/apache/commons/compress/archivers/TestArchiveStreamProvider.java
index 66b7f5eb..ba328775 100644
--- a/src/test/java/org/apache/commons/compress/archivers/TestArchiveStreamProvider.java
+++ b/src/test/java/org/apache/commons/compress/archivers/TestArchiveStreamProvider.java
@@ -37,12 +37,14 @@ public class TestArchiveStreamProvider implements ArchiveStreamProvider {
     }
 
     @Override
-    public ArchiveInputStream createArchiveInputStream(final String name, final InputStream in, final String encoding) throws ArchiveException {
+    public <T extends ArchiveInputStream<? extends ArchiveEntry>> T createArchiveInputStream(final String name, final InputStream in,
+            final String encoding) throws ArchiveException {
         throw new ArchiveInvocationConfirmationException(name);
     }
 
     @Override
-    public ArchiveOutputStream createArchiveOutputStream(final String name, final OutputStream out, final String encoding) throws ArchiveException {
+    public <T extends ArchiveOutputStream<? extends ArchiveEntry>> T createArchiveOutputStream(final String name, final OutputStream out,
+            final String encoding) throws ArchiveException {
         throw new ArchiveInvocationConfirmationException(name);
     }
 
diff --git a/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java b/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
index 1c3d4ece..010031b8 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
@@ -205,6 +205,7 @@ public final class ZipTestCase extends AbstractTestCase {
 
         return result;
     }
+
     private void createArchiveEntry(final String payload, final ZipArchiveOutputStream zos, final String name)
             throws IOException {
         final ZipArchiveEntry in = new ZipArchiveEntry(name);
@@ -213,6 +214,7 @@ public final class ZipTestCase extends AbstractTestCase {
         zos.write(payload.getBytes());
         zos.closeArchiveEntry();
     }
+
     private ZipArchiveOutputStream createFirstEntry(final ZipArchiveOutputStream zos) throws IOException {
         createArchiveEntry(first_payload, zos, "file1.txt");
         return zos;
@@ -570,7 +572,7 @@ public final class ZipTestCase extends AbstractTestCase {
 
         // stream access
         try (final InputStream fis = Files.newInputStream(input.toPath());
-            final ArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", fis)) {
+            final ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", fis)) {
             for (ArchiveEntry entry; (entry = in.getNextEntry()) != null; ) {
                 readStream(in, entry, actualStatistics);
             }
@@ -616,16 +618,16 @@ public final class ZipTestCase extends AbstractTestCase {
         final List<ZipException> expectedExceptions = new ArrayList<>();
 
         try (final InputStream fis = Files.newInputStream(input.toPath());
-            ArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", fis)) {
+                ZipArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", fis)) {
 
             ZipArchiveEntry entry;
-            while ((entry = (ZipArchiveEntry) in.getNextEntry()) != null) {
+            while ((entry = in.getNextEntry()) != null) {
                 results.add(entry.getName());
 
-                final ArchiveInputStream nestedIn = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", in);
+                final ZipArchiveInputStream nestedIn = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", in);
                 try {
                     ZipArchiveEntry nestedEntry;
-                    while ((nestedEntry = (ZipArchiveEntry) nestedIn.getNextEntry()) != null) {
+                    while ((nestedEntry = nestedIn.getNextEntry()) != null) {
                         results.add(nestedEntry.getName());
                     }
                 } catch (final ZipException ex) {
@@ -729,7 +731,7 @@ public final class ZipTestCase extends AbstractTestCase {
         final File file2 = getFile("test2.xml");
 
         try (final OutputStream out = Files.newOutputStream(output.toPath())) {
-            try (ArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("zip", out)) {
+            try (ArchiveOutputStream<ZipArchiveEntry> os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("zip", out)) {
                 os.putArchiveEntry(new ZipArchiveEntry("testdata/test1.xml"));
                 Files.copy(file1.toPath(), os);
                 os.closeArchiveEntry();
@@ -744,10 +746,10 @@ public final class ZipTestCase extends AbstractTestCase {
         final List<File> results = new ArrayList<>();
 
         try (final InputStream fileInputStream = Files.newInputStream(output.toPath())) {
-            try (ArchiveInputStream archiveInputStream = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip",
+            try (ArchiveInputStream<ZipArchiveEntry> archiveInputStream = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip",
                 fileInputStream)) {
                 ZipArchiveEntry entry;
-                while ((entry = (ZipArchiveEntry) archiveInputStream.getNextEntry()) != null) {
+                while ((entry = archiveInputStream.getNextEntry()) != null) {
                     final File outfile = new File(resultDir.getCanonicalPath() + "/result/" + entry.getName());
                     outfile.getParentFile().mkdirs();
                     Files.copy(archiveInputStream, outfile.toPath());
@@ -790,11 +792,11 @@ public final class ZipTestCase extends AbstractTestCase {
             }
 
             // Unarchive the same
-            try (ArchiveInputStream inputStream = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip",
+            try (ZipArchiveInputStream inputStream = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip",
                 new ByteArrayInputStream(channel.array()))) {
 
                 ZipArchiveEntry entry;
-                while ((entry = (ZipArchiveEntry) inputStream.getNextEntry()) != null) {
+                while ((entry = inputStream.getNextEntry()) != null) {
                     final byte[] result = new byte[(int) entry.getSize()];
                     IOUtils.readFully(inputStream, result);
                     results.add(result);
@@ -821,7 +823,7 @@ public final class ZipTestCase extends AbstractTestCase {
             archivePath = archiveFile.toPath();
             archiveFile.deleteOnExit();
             zos = new ZipArchiveOutputStream(archivePath);
-            final ZipArchiveEntry in = (ZipArchiveEntry) zos.createArchiveEntry(tmpFilePath, "foo");
+            final ZipArchiveEntry in = zos.createArchiveEntry(tmpFilePath, "foo");
             zos.putArchiveEntry(in);
             final byte[] b = new byte[(int) tmpFile.length()];
             fis = Files.newInputStream(tmpFile.toPath());
@@ -863,7 +865,7 @@ public final class ZipTestCase extends AbstractTestCase {
     public void testZipUnarchive() throws Exception {
         final File input = getFile("bla.zip");
         try (final InputStream is = Files.newInputStream(input.toPath());
-                final ArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", is)) {
+                final ArchiveInputStream<ZipArchiveEntry> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", is)) {
             final ZipArchiveEntry entry = (ZipArchiveEntry) in.getNextEntry();
             Files.copy(in, new File(dir, entry.getName()).toPath());
         }
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 5171f892..1a286fdf 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
@@ -62,7 +62,7 @@ public class CpioArchiveInputStreamTest extends AbstractTestCase {
         try (final CpioArchiveInputStream in = new CpioArchiveInputStream(newInputStream("bla.cpio"))) {
             CpioArchiveEntry entry;
 
-            while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) {
+            while ((entry = in.getNextEntry()) != null) {
                 result.append(entry.getName());
                 int tmp;
                 while ((tmp = in.read()) != -1) {
@@ -79,7 +79,7 @@ public class CpioArchiveInputStreamTest extends AbstractTestCase {
         try (final CpioArchiveInputStream in = new CpioArchiveInputStream(newInputStream("redline.cpio"))) {
             CpioArchiveEntry entry;
 
-            while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) {
+            while ((entry = in.getNextEntry()) != null) {
                 count++;
                 assertNotNull(entry);
             }
@@ -94,7 +94,7 @@ public class CpioArchiveInputStreamTest extends AbstractTestCase {
         try (final CpioArchiveInputStream in = new CpioArchiveInputStream(newInputStream("COMPRESS-459.cpio"), "UTF-8")) {
             CpioArchiveEntry entry;
 
-            while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) {
+            while ((entry = in.getNextEntry()) != null) {
                 count++;
                 assertNotNull(entry);
             }
diff --git a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveTest.java b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveTest.java
index 45f48be1..62cfd6ae 100644
--- a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveTest.java
@@ -54,7 +54,7 @@ public class CpioArchiveTest {
             baos.close();
             try (ByteArrayInputStream bin = new ByteArrayInputStream(baos.toByteArray());
                 CpioArchiveInputStream in = new CpioArchiveInputStream(bin, "UTF-16LE")) {
-                final CpioArchiveEntry entry = (CpioArchiveEntry) in.getNextEntry();
+                final CpioArchiveEntry entry = in.getNextEntry();
                 assertNotNull(entry);
                 assertEquals("T\u00e4st.txt", entry.getName());
                 assertArrayEquals(new byte[] {1, 2, 3, 4}, IOUtils.toByteArray(in));
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 ed31b911..4d1a4603 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
@@ -37,6 +37,7 @@ import java.nio.file.Files;
 import java.nio.file.StandardOpenOption;
 
 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.ArchiveOutputStream;
 import org.apache.commons.compress.archivers.ArchiveStreamFactory;
@@ -126,7 +127,7 @@ public class ExpanderTest extends AbstractTestCase {
             o.write(new byte[14]);
         }
         try (@SuppressWarnings("resource") // Files.newOutputStream result closed by ArchiveOutputStream
-        ArchiveOutputStream aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("tar", Files.newOutputStream(archive.toPath()))) {
+        ArchiveOutputStream<ArchiveEntry> aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("tar", Files.newOutputStream(archive.toPath()))) {
             aos.putArchiveEntry(aos.createArchiveEntry(dir, "a"));
             aos.closeArchiveEntry();
             aos.putArchiveEntry(aos.createArchiveEntry(dir, "a/b"));
@@ -150,7 +151,7 @@ public class ExpanderTest extends AbstractTestCase {
             o.write(new byte[14]);
         }
         try (@SuppressWarnings("resource") // Files.newOutputStream result closed by ArchiveOutputStream
-        ArchiveOutputStream aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("tar", Files.newOutputStream(archive.toPath()))) {
+        ArchiveOutputStream<ArchiveEntry> aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("tar", Files.newOutputStream(archive.toPath()))) {
             aos.putArchiveEntry(aos.createArchiveEntry(dir, "./"));
             aos.closeArchiveEntry();
             aos.putArchiveEntry(aos.createArchiveEntry(dir, "./a"));
@@ -176,7 +177,7 @@ public class ExpanderTest extends AbstractTestCase {
             o.write(new byte[14]);
         }
         try (@SuppressWarnings("resource") // // Files.newOutputStream result closed by ArchiveOutputStream
-        ArchiveOutputStream aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("zip", Files.newOutputStream(archive.toPath()))) {
+        ArchiveOutputStream<ArchiveEntry> aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("zip", Files.newOutputStream(archive.toPath()))) {
             aos.putArchiveEntry(aos.createArchiveEntry(dir, "a"));
             aos.closeArchiveEntry();
             aos.putArchiveEntry(aos.createArchiveEntry(dir, "a/b"));
@@ -200,7 +201,7 @@ public class ExpanderTest extends AbstractTestCase {
             o.write(new byte[14]);
         }
         try (@SuppressWarnings("resource") // Files.newOutputStream result closed by ArchiveOutputStream
-        ArchiveOutputStream aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("zip", Files.newOutputStream(archive.toPath()))) {
+        ArchiveOutputStream<ArchiveEntry> aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("zip", Files.newOutputStream(archive.toPath()))) {
             aos.putArchiveEntry(aos.createArchiveEntry(dummy, entry));
             aos.write("Hello, world 1".getBytes(UTF_8));
             aos.closeArchiveEntry();
diff --git a/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java b/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java
index abf22d01..00fce551 100644
--- a/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java
@@ -68,7 +68,7 @@ public class ParameterizedArchiverTest extends AbstractTestCase {
         // TODO How to parameterize a BeforeEach method?
         setUp(format);
         try (OutputStream os = Files.newOutputStream(target.toPath());
-             ArchiveOutputStream aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(format, os)) {
+             ArchiveOutputStream<?> aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(format, os)) {
             new Archiver().create(aos, dir);
         }
         verifyContent(format);
@@ -138,7 +138,7 @@ public class ParameterizedArchiverTest extends AbstractTestCase {
     private void verifyContent(final String format) throws IOException, ArchiveException {
         try (InputStream is = Files.newInputStream(target.toPath());
              BufferedInputStream bis = new BufferedInputStream(is);
-             ArchiveInputStream ais = ArchiveStreamFactory.DEFAULT.createArchiveInputStream(format, bis)) {
+             ArchiveInputStream<?> ais = ArchiveStreamFactory.DEFAULT.createArchiveInputStream(format, bis)) {
             assertDir("a", ais.getNextEntry());
             assertDir("a/b", ais.getNextEntry());
             final ArchiveEntry n = ais.getNextEntry();
diff --git a/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedExpanderTest.java b/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedExpanderTest.java
index 4e25980b..b244499a 100644
--- a/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedExpanderTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedExpanderTest.java
@@ -34,6 +34,7 @@ import java.nio.file.StandardOpenOption;
 import java.util.stream.Stream;
 
 import org.apache.commons.compress.AbstractTestCase;
+import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.ArchiveOutputStream;
 import org.apache.commons.compress.archivers.ArchiveStreamFactory;
@@ -63,7 +64,7 @@ public class ParameterizedExpanderTest extends AbstractTestCase {
         // TODO How to parameterize a BeforeEach method?
         setUp(format);
         try (InputStream i = new BufferedInputStream(Files.newInputStream(archive.toPath()));
-             ArchiveInputStream ais = ArchiveStreamFactory.DEFAULT.createArchiveInputStream(format, i)) {
+             ArchiveInputStream<?> ais = ArchiveStreamFactory.DEFAULT.createArchiveInputStream(format, i)) {
             new Expander().expand(ais, resultDir);
         }
         verifyTargetDir();
@@ -136,8 +137,7 @@ public class ParameterizedExpanderTest extends AbstractTestCase {
         try (OutputStream o = Files.newOutputStream(dummy.toPath())) {
             o.write(new byte[14]);
         }
-        try (ArchiveOutputStream aos = ArchiveStreamFactory.DEFAULT
-             .createArchiveOutputStream(format, Files.newOutputStream(archive.toPath()))) {
+        try (ArchiveOutputStream<ArchiveEntry> aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(format, Files.newOutputStream(archive.toPath()))) {
             aos.putArchiveEntry(aos.createArchiveEntry(dir.toPath(), "a"));
             aos.closeArchiveEntry();
             aos.putArchiveEntry(aos.createArchiveEntry(dir, "a/b"));
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 09c6a433..b969d85f 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
@@ -348,9 +348,9 @@ public class TarArchiveInputStreamTest extends AbstractTestCase {
             // untar these tars
             // -----------------------
             try (final InputStream is = Files.newInputStream(tarF.toPath());
-                final TarArchiveInputStream debInputStream = (TarArchiveInputStream) ArchiveStreamFactory.DEFAULT.createArchiveInputStream("tar", is)) {
+                final TarArchiveInputStream debInputStream = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("tar", is)) {
                 TarArchiveEntry outEntry;
-                while ((outEntry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) {
+                while ((outEntry = debInputStream.getNextEntry()) != null) {
                     assertTrue(outEntry.getName().endsWith("/"), outEntry.getName());
                 }
             }
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
index 5a2bb61c..94236d15 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
@@ -163,8 +163,7 @@ public class TarArchiveOutputStreamTest extends AbstractTestCase {
         f.deleteOnExit();
         final OutputStream fos = Files.newOutputStream(f.toPath());
 
-        final ArchiveOutputStream tarOut = ArchiveStreamFactory.DEFAULT
-            .createArchiveOutputStream(ArchiveStreamFactory.TAR, fos);
+        final ArchiveOutputStream<ArchiveEntry> tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, fos);
 
         final File file1 = getFile("test1.xml");
         final TarArchiveEntry sEntry = new TarArchiveEntry(file1, file1.getName());
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java
index dc3763ff..4e6c628b 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java
@@ -31,6 +31,7 @@ import java.nio.file.Path;
 import java.nio.file.attribute.GroupPrincipal;
 import java.nio.file.attribute.UserPrincipal;
 
+import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveException;
 import org.apache.commons.compress.archivers.ArchiveOutputStream;
 import org.apache.commons.compress.archivers.ArchiveStreamFactory;
@@ -52,7 +53,7 @@ public class TarMemoryFileSystemTest {
 
             final Path target = fileSystem.getPath("original-file.tar");
             try (final OutputStream out = Files.newOutputStream(target);
-                 final ArchiveOutputStream tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, out)) {
+                    final ArchiveOutputStream<ArchiveEntry> tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, out)) {
                 final TarArchiveEntry entry = new TarArchiveEntry(source);
                 tarOut.putArchiveEntry(entry);
 
@@ -61,7 +62,7 @@ public class TarMemoryFileSystemTest {
             }
 
             try (final InputStream input = Files.newInputStream(target);
-                 final TarArchiveInputStream tarIn = new TarArchiveInputStream(input)) {
+                    final TarArchiveInputStream tarIn = new TarArchiveInputStream(input)) {
                 final TarArchiveEntry nextTarEntry = tarIn.getNextTarEntry();
 
                 assertEquals(user, nextTarEntry.getUserName());
@@ -78,7 +79,7 @@ public class TarMemoryFileSystemTest {
 
             final File f = File.createTempFile("commons-compress-memoryfs", ".tar");
             try (final OutputStream out = Files.newOutputStream(f.toPath());
-                 final ArchiveOutputStream tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, out)) {
+                    final ArchiveOutputStream<ArchiveEntry> tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, out)) {
                 final TarArchiveEntry entry = new TarArchiveEntry(p);
                 tarOut.putArchiveEntry(entry);
 
@@ -95,7 +96,7 @@ public class TarMemoryFileSystemTest {
             final Path p = fileSystem.getPath("target.tar");
 
             try (final OutputStream out = Files.newOutputStream(p);
-                 final ArchiveOutputStream tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, out)) {
+                    final ArchiveOutputStream<ArchiveEntry> tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, out)) {
                 final String content = "Test";
                 final TarArchiveEntry entry = new TarArchiveEntry("test.txt");
                 entry.setSize(content.length());
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java b/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java
index 4c29ab4d..89da791e 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java
@@ -2207,8 +2207,7 @@ public class Zip64SupportIT {
 
         // with Zip64Mode.AlwaysWithCompatibility, the relative header offset and disk number
         // start will not be set in extra fields
-        final File zipUsingModeAlwaysWithCompatibility = buildZipWithZip64Mode(
-                "testZip64ModeAlwaysWithCompatibility-output-1",
+        final File zipUsingModeAlwaysWithCompatibility = buildZipWithZip64Mode("testZip64ModeAlwaysWithCompatibility-output-1",
                 Zip64Mode.AlwaysWithCompatibility, inputFile);
         final ZipFile zipFileWithAlwaysWithCompatibility = new ZipFile(zipUsingModeAlwaysWithCompatibility);
         ZipArchiveEntry entry = zipFileWithAlwaysWithCompatibility.getEntries().nextElement();
@@ -2223,9 +2222,7 @@ public class Zip64SupportIT {
 
         // with Zip64Mode.Always, the relative header offset and disk number start will be
         // set in extra fields
-        final File zipUsingModeAlways = buildZipWithZip64Mode(
-                "testZip64ModeAlwaysWithCompatibility-output-2",
-                Zip64Mode.Always, inputFile);
+        final File zipUsingModeAlways = buildZipWithZip64Mode("testZip64ModeAlwaysWithCompatibility-output-2", Zip64Mode.Always, inputFile);
         final ZipFile zipFileWithAlways = new ZipFile(zipUsingModeAlways);
         entry = zipFileWithAlways.getEntries().nextElement();
         for (final ZipExtraField extraField : entry.getExtraFields()) {
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
index 0a69f739..4a8aad88 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
@@ -130,8 +130,7 @@ public class ZipArchiveInputStreamTest extends AbstractTestCase {
         for (int i = 0; i < len; i++) {
             input[i] = (byte) bytes[i];
         }
-        try (ArchiveInputStream ais = ArchiveStreamFactory.DEFAULT
-             .createArchiveInputStream("zip", new ByteArrayInputStream(input))) {
+        try (ArchiveInputStream<?> ais = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", new ByteArrayInputStream(input))) {
             ais.getNextEntry();
             IOUtils.toByteArray(ais);
         }
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipMemoryFileSystemTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipMemoryFileSystemTest.java
index 99532680..c5e7ab3c 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipMemoryFileSystemTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipMemoryFileSystemTest.java
@@ -26,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.nio.channels.SeekableByteChannel;
 import java.nio.file.FileSystem;
@@ -50,6 +51,7 @@ import org.apache.commons.compress.archivers.ArchiveOutputStream;
 import org.apache.commons.compress.archivers.ArchiveStreamFactory;
 import org.apache.commons.compress.parallel.InputStreamSupplier;
 import org.apache.commons.compress.utils.IOUtils;
+import org.apache.commons.io.file.PathUtils;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -84,11 +86,13 @@ public class ZipMemoryFileSystemTest {
             list.add(firstFile);
             list.add(secondFile);
 
-            SeekableByteChannel channel = ZipSplitReadOnlySeekableByteChannel.forPaths(lastFile, list);
-            assertTrue(channel instanceof ZipSplitReadOnlySeekableByteChannel);
+            try (SeekableByteChannel channel = ZipSplitReadOnlySeekableByteChannel.forPaths(lastFile, list)) {
+                assertTrue(channel instanceof ZipSplitReadOnlySeekableByteChannel);
+            }
 
-            channel = ZipSplitReadOnlySeekableByteChannel.forPaths(firstFile, secondFile, lastFile);
-            assertTrue(channel instanceof ZipSplitReadOnlySeekableByteChannel);
+            try (SeekableByteChannel channel = ZipSplitReadOnlySeekableByteChannel.forPaths(firstFile, secondFile, lastFile)) {
+                assertTrue(channel instanceof ZipSplitReadOnlySeekableByteChannel);
+            }
         }
     }
 
@@ -113,90 +117,99 @@ public class ZipMemoryFileSystemTest {
             final int randomDiskNumber = random.nextInt(3);
             final int randomOffset = randomDiskNumber < 2 ? random.nextInt(firstFileSize) : random.nextInt(lastFileSize);
 
-            final ZipSplitReadOnlySeekableByteChannel channel = (ZipSplitReadOnlySeekableByteChannel)
-                    ZipSplitReadOnlySeekableByteChannel.buildFromLastSplitSegment(lastMemoryPath);
-            channel.position(randomDiskNumber, randomOffset);
-            long expectedPosition = randomOffset;
+            try (ZipSplitReadOnlySeekableByteChannel channel = (ZipSplitReadOnlySeekableByteChannel) ZipSplitReadOnlySeekableByteChannel
+                    .buildFromLastSplitSegment(lastMemoryPath)) {
+                channel.position(randomDiskNumber, randomOffset);
+                long expectedPosition = randomOffset;
 
-            expectedPosition += randomDiskNumber > 0 ? firstFileSize : 0;
-            expectedPosition += randomDiskNumber > 1 ? secondFileSize : 0;
+                expectedPosition += randomDiskNumber > 0 ? firstFileSize : 0;
+                expectedPosition += randomDiskNumber > 1 ? secondFileSize : 0;
 
-            assertEquals(expectedPosition, channel.position());
+                assertEquals(expectedPosition, channel.position());
+            }
         }
 
     }
 
     @Test
     public void scatterFileInMemory() throws IOException {
+        final byte[] B_PAYLOAD = "RBBBBBBS".getBytes();
+        final byte[] A_PAYLOAD = "XAAY".getBytes();
+        final Path target = Files.createTempFile(dir, "scattertest", ".zip");
         try (FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().build()) {
             final Path scatterFile = fileSystem.getPath("scattertest.notzip");
-            final ScatterZipOutputStream scatterZipOutputStream = ScatterZipOutputStream.pathBased(scatterFile);
-            final byte[] B_PAYLOAD = "RBBBBBBS".getBytes();
-            final byte[] A_PAYLOAD = "XAAY".getBytes();
+            try (ScatterZipOutputStream scatterZipOutputStream = ScatterZipOutputStream.pathBased(scatterFile)) {
 
-            final ZipArchiveEntry zab = new ZipArchiveEntry("b.txt");
-            zab.setMethod(ZipEntry.DEFLATED);
-            final ByteArrayInputStream payload = new ByteArrayInputStream(B_PAYLOAD);
-            scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zab, createPayloadSupplier(payload)));
+                final ZipArchiveEntry zab = new ZipArchiveEntry("b.txt");
+                zab.setMethod(ZipEntry.DEFLATED);
+                final ByteArrayInputStream payload = new ByteArrayInputStream(B_PAYLOAD);
+                scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zab, createPayloadSupplier(payload)));
 
-            final ZipArchiveEntry zae = new ZipArchiveEntry("a.txt");
-            zae.setMethod(ZipEntry.DEFLATED);
-            final ByteArrayInputStream payload1 = new ByteArrayInputStream(A_PAYLOAD);
-            scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zae, createPayloadSupplier(payload1)));
+                final ZipArchiveEntry zae = new ZipArchiveEntry("a.txt");
+                zae.setMethod(ZipEntry.DEFLATED);
+                final ByteArrayInputStream payload1 = new ByteArrayInputStream(A_PAYLOAD);
+                scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zae, createPayloadSupplier(payload1)));
 
-            final Path target = Files.createTempFile(dir, "scattertest", ".zip");
-            final ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(target);
-            scatterZipOutputStream.writeTo(outputStream);
-            outputStream.close();
-            scatterZipOutputStream.close();
-
-            final ZipFile zf = new ZipFile(target.toFile());
-            final ZipArchiveEntry b_entry = zf.getEntries("b.txt").iterator().next();
-            assertEquals(8, b_entry.getSize());
-            assertArrayEquals(B_PAYLOAD, IOUtils.toByteArray(zf.getInputStream(b_entry)));
-
-            final ZipArchiveEntry a_entry = zf.getEntries("a.txt").iterator().next();
-            assertEquals(4, a_entry.getSize());
-            assertArrayEquals(A_PAYLOAD, IOUtils.toByteArray(zf.getInputStream(a_entry)));
-            zf.close();
-        }
+                try (ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(target)) {
+                    scatterZipOutputStream.writeTo(outputStream);
+                }
+            }
 
+            try (ZipFile zf = new ZipFile(target.toFile())) {
+                final ZipArchiveEntry b_entry = zf.getEntries("b.txt").iterator().next();
+                assertEquals(8, b_entry.getSize());
+                try (InputStream inputStream = zf.getInputStream(b_entry)) {
+                    assertArrayEquals(B_PAYLOAD, IOUtils.toByteArray(inputStream));
+                }
+
+                final ZipArchiveEntry a_entry = zf.getEntries("a.txt").iterator().next();
+                assertEquals(4, a_entry.getSize());
+                try (InputStream inputStream = zf.getInputStream(a_entry)) {
+                    assertArrayEquals(A_PAYLOAD, IOUtils.toByteArray(inputStream));
+                }
+            }
+        } finally {
+            PathUtils.delete(target);
+        }
     }
 
     @Test
     public void scatterFileWithCompressionAndTargetInMemory() throws IOException {
+        final byte[] B_PAYLOAD = "RBBBBBBS".getBytes();
+        final byte[] A_PAYLOAD = "XAAY".getBytes();
         try (FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().build()) {
+            final Path target = fileSystem.getPath("scattertest.zip");
             final Path scatterFile = fileSystem.getPath("scattertest.notzip");
-            final ScatterZipOutputStream scatterZipOutputStream = ScatterZipOutputStream.pathBased(scatterFile,
-                    Deflater.BEST_COMPRESSION);
-            final byte[] B_PAYLOAD = "RBBBBBBS".getBytes();
-            final byte[] A_PAYLOAD = "XAAY".getBytes();
+            try (ScatterZipOutputStream scatterZipOutputStream = ScatterZipOutputStream.pathBased(scatterFile, Deflater.BEST_COMPRESSION)) {
 
-            final ZipArchiveEntry zab = new ZipArchiveEntry("b.txt");
-            zab.setMethod(ZipEntry.DEFLATED);
-            final ByteArrayInputStream payload = new ByteArrayInputStream(B_PAYLOAD);
-            scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zab, createPayloadSupplier(payload)));
+                final ZipArchiveEntry zab = new ZipArchiveEntry("b.txt");
+                zab.setMethod(ZipEntry.DEFLATED);
+                final ByteArrayInputStream payload = new ByteArrayInputStream(B_PAYLOAD);
+                scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zab, createPayloadSupplier(payload)));
 
-            final ZipArchiveEntry zae = new ZipArchiveEntry("a.txt");
-            zae.setMethod(ZipEntry.DEFLATED);
-            final ByteArrayInputStream payload1 = new ByteArrayInputStream(A_PAYLOAD);
-            scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zae, createPayloadSupplier(payload1)));
+                final ZipArchiveEntry zae = new ZipArchiveEntry("a.txt");
+                zae.setMethod(ZipEntry.DEFLATED);
+                final ByteArrayInputStream payload1 = new ByteArrayInputStream(A_PAYLOAD);
+                scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zae, createPayloadSupplier(payload1)));
 
-            final Path target = fileSystem.getPath("scattertest.zip");
-            final ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(target);
-            scatterZipOutputStream.writeTo(outputStream);
-            outputStream.close();
-            scatterZipOutputStream.close();
+                try (ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(target)) {
+                    scatterZipOutputStream.writeTo(outputStream);
+                }
+            }
 
-            try (final ZipFile zf = new ZipFile(Files.newByteChannel(target, StandardOpenOption.READ),
-                    target.getFileName().toString(), ZipEncodingHelper.UTF8, true)) {
+            try (final ZipFile zf = new ZipFile(Files.newByteChannel(target, StandardOpenOption.READ), target.getFileName().toString(), ZipEncodingHelper.UTF8,
+                    true)) {
                 final ZipArchiveEntry b_entry = zf.getEntries("b.txt").iterator().next();
                 assertEquals(8, b_entry.getSize());
-                assertArrayEquals(B_PAYLOAD, IOUtils.toByteArray(zf.getInputStream(b_entry)));
+                try (InputStream inputStream = zf.getInputStream(b_entry)) {
+                    assertArrayEquals(B_PAYLOAD, IOUtils.toByteArray(inputStream));
+                }
 
                 final ZipArchiveEntry a_entry = zf.getEntries("a.txt").iterator().next();
                 assertEquals(4, a_entry.getSize());
-                assertArrayEquals(A_PAYLOAD, IOUtils.toByteArray(zf.getInputStream(a_entry)));
+                try (InputStream inputStream = zf.getInputStream(a_entry)) {
+                    assertArrayEquals(A_PAYLOAD, IOUtils.toByteArray(inputStream));
+                }
             }
         }
     }
@@ -205,36 +218,39 @@ public class ZipMemoryFileSystemTest {
     public void scatterFileWithCompressionInMemory() throws IOException {
         try (FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().build()) {
             final Path scatterFile = fileSystem.getPath("scattertest.notzip");
-            final ScatterZipOutputStream scatterZipOutputStream = ScatterZipOutputStream.pathBased(scatterFile,
-                    Deflater.BEST_COMPRESSION);
+            final Path target = Files.createTempFile(dir, "scattertest", ".zip");
             final byte[] B_PAYLOAD = "RBBBBBBS".getBytes();
             final byte[] A_PAYLOAD = "XAAY".getBytes();
+            try (ScatterZipOutputStream scatterZipOutputStream = ScatterZipOutputStream.pathBased(scatterFile, Deflater.BEST_COMPRESSION)) {
 
-            final ZipArchiveEntry zab = new ZipArchiveEntry("b.txt");
-            zab.setMethod(ZipEntry.DEFLATED);
-            final ByteArrayInputStream payload = new ByteArrayInputStream(B_PAYLOAD);
-            scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zab, createPayloadSupplier(payload)));
+                final ZipArchiveEntry zab = new ZipArchiveEntry("b.txt");
+                zab.setMethod(ZipEntry.DEFLATED);
+                final ByteArrayInputStream payload = new ByteArrayInputStream(B_PAYLOAD);
+                scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zab, createPayloadSupplier(payload)));
 
-            final ZipArchiveEntry zae = new ZipArchiveEntry("a.txt");
-            zae.setMethod(ZipEntry.DEFLATED);
-            final ByteArrayInputStream payload1 = new ByteArrayInputStream(A_PAYLOAD);
-            scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zae, createPayloadSupplier(payload1)));
+                final ZipArchiveEntry zae = new ZipArchiveEntry("a.txt");
+                zae.setMethod(ZipEntry.DEFLATED);
+                final ByteArrayInputStream payload1 = new ByteArrayInputStream(A_PAYLOAD);
+                scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zae, createPayloadSupplier(payload1)));
 
-            final Path target = Files.createTempFile(dir, "scattertest", ".zip");
-            final ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(target);
-            scatterZipOutputStream.writeTo(outputStream);
-            outputStream.close();
-            scatterZipOutputStream.close();
-
-            final ZipFile zf = new ZipFile(target.toFile());
-            final ZipArchiveEntry b_entry = zf.getEntries("b.txt").iterator().next();
-            assertEquals(8, b_entry.getSize());
-            assertArrayEquals(B_PAYLOAD, IOUtils.toByteArray(zf.getInputStream(b_entry)));
-
-            final ZipArchiveEntry a_entry = zf.getEntries("a.txt").iterator().next();
-            assertEquals(4, a_entry.getSize());
-            assertArrayEquals(A_PAYLOAD, IOUtils.toByteArray(zf.getInputStream(a_entry)));
-            zf.close();
+                try (ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(target)) {
+                    scatterZipOutputStream.writeTo(outputStream);
+                }
+            }
+
+            try (ZipFile zf = new ZipFile(target.toFile())) {
+                final ZipArchiveEntry b_entry = zf.getEntries("b.txt").iterator().next();
+                assertEquals(8, b_entry.getSize());
+                try (InputStream inputStream = zf.getInputStream(b_entry)) {
+                    assertArrayEquals(B_PAYLOAD, IOUtils.toByteArray(inputStream));
+                }
+
+                final ZipArchiveEntry a_entry = zf.getEntries("a.txt").iterator().next();
+                assertEquals(4, a_entry.getSize());
+                try (InputStream inputStream = zf.getInputStream(a_entry)) {
+                    assertArrayEquals(A_PAYLOAD, IOUtils.toByteArray(inputStream));
+                }
+            }
         }
 
     }
@@ -247,14 +263,12 @@ public class ZipMemoryFileSystemTest {
     @AfterEach
     public void tearDown() throws IOException {
         try (Stream<Path> walk = Files.walk(dir)) {
-            walk.sorted(Comparator.reverseOrder())
-                    .peek(path -> println("Deleting: " + path.toAbsolutePath()))
-                    .forEach(path -> {
-                        try {
-                            Files.deleteIfExists(path);
-                        } catch (final IOException ignore) {
-                        }
-                    });
+            walk.sorted(Comparator.reverseOrder()).peek(path -> println("Deleting: " + path.toAbsolutePath())).forEach(path -> {
+                try {
+                    Files.deleteIfExists(path);
+                } catch (final IOException ignore) {
+                }
+            });
         }
     }
 
@@ -262,35 +276,38 @@ public class ZipMemoryFileSystemTest {
     public void zipFileInMemory() throws IOException {
         try (FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().build()) {
             final Path scatterFile = fileSystem.getPath("scattertest.notzip");
-            final ScatterZipOutputStream scatterZipOutputStream = ScatterZipOutputStream.pathBased(scatterFile,
-                    Deflater.BEST_COMPRESSION);
+            final Path target = fileSystem.getPath("scattertest.zip");
             final byte[] B_PAYLOAD = "RBBBBBBS".getBytes();
             final byte[] A_PAYLOAD = "XAAY".getBytes();
+            try (ScatterZipOutputStream scatterZipOutputStream = ScatterZipOutputStream.pathBased(scatterFile, Deflater.BEST_COMPRESSION)) {
 
-            final ZipArchiveEntry zab = new ZipArchiveEntry("b.txt");
-            zab.setMethod(ZipEntry.DEFLATED);
-            final ByteArrayInputStream payload = new ByteArrayInputStream(B_PAYLOAD);
-            scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zab, createPayloadSupplier(payload)));
+                final ZipArchiveEntry zab = new ZipArchiveEntry("b.txt");
+                zab.setMethod(ZipEntry.DEFLATED);
+                final ByteArrayInputStream payload = new ByteArrayInputStream(B_PAYLOAD);
+                scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zab, createPayloadSupplier(payload)));
 
-            final ZipArchiveEntry zae = new ZipArchiveEntry("a.txt");
-            zae.setMethod(ZipEntry.DEFLATED);
-            final ByteArrayInputStream payload1 = new ByteArrayInputStream(A_PAYLOAD);
-            scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zae, createPayloadSupplier(payload1)));
+                final ZipArchiveEntry zae = new ZipArchiveEntry("a.txt");
+                zae.setMethod(ZipEntry.DEFLATED);
+                final ByteArrayInputStream payload1 = new ByteArrayInputStream(A_PAYLOAD);
+                scatterZipOutputStream.addArchiveEntry(createZipArchiveEntryRequest(zae, createPayloadSupplier(payload1)));
 
-            final Path target = fileSystem.getPath("scattertest.zip");
-            final ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(target);
-            scatterZipOutputStream.writeTo(outputStream);
-            outputStream.close();
-            scatterZipOutputStream.close();
+                try (ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(target)) {
+                    scatterZipOutputStream.writeTo(outputStream);
+                }
+            }
 
             try (final ZipFile zf = new ZipFile(target)) {
                 final ZipArchiveEntry b_entry = zf.getEntries("b.txt").iterator().next();
                 assertEquals(8, b_entry.getSize());
-                assertArrayEquals(B_PAYLOAD, IOUtils.toByteArray(zf.getInputStream(b_entry)));
+                try (InputStream inputStream = zf.getInputStream(b_entry)) {
+                    assertArrayEquals(B_PAYLOAD, IOUtils.toByteArray(inputStream));
+                }
 
                 final ZipArchiveEntry a_entry = zf.getEntries("a.txt").iterator().next();
                 assertEquals(4, a_entry.getSize());
-                assertArrayEquals(A_PAYLOAD, IOUtils.toByteArray(zf.getInputStream(a_entry)));
+                try (InputStream inputStream = zf.getInputStream(a_entry)) {
+                    assertArrayEquals(A_PAYLOAD, IOUtils.toByteArray(inputStream));
+                }
             }
         }
     }
@@ -304,7 +321,7 @@ public class ZipMemoryFileSystemTest {
             Files.write(textFileInMemSys, bytes);
 
             final Path zipInLocalSys = Files.createTempFile(dir, "commons-compress-memoryfs", ".zip");
-            try (final ArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInLocalSys.toFile())) {
+            try (final ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInLocalSys.toFile())) {
                 final ZipArchiveEntry entry = new ZipArchiveEntry(textFileInMemSys, textFileInMemSys.getFileName().toString());
                 entry.setSize(Files.size(textFileInMemSys));
                 zipOut.putArchiveEntry(entry);
@@ -325,7 +342,7 @@ public class ZipMemoryFileSystemTest {
 
             final Path f = Files.createTempFile(dir, "commons-compress-memoryfs", ".zip");
             try (final OutputStream out = Files.newOutputStream(f);
-                 final ArchiveOutputStream zipOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.ZIP, out)) {
+                    final ArchiveOutputStream<ZipArchiveEntry> zipOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.ZIP, out)) {
                 final ZipArchiveEntry entry = new ZipArchiveEntry(p, p.getFileName().toString());
                 entry.setSize(Files.size(p));
                 zipOut.putArchiveEntry(entry);
@@ -346,7 +363,7 @@ public class ZipMemoryFileSystemTest {
             Files.write(textFileInMemSys, bytes);
 
             final Path zipInLocalSys = Files.createTempFile(dir, "commons-compress-memoryfs", ".zip");
-            try (final ArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInLocalSys)) {
+            try (final ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInLocalSys)) {
                 final ZipArchiveEntry entry = new ZipArchiveEntry(textFileInMemSys, textFileInMemSys.getFileName().toString());
                 entry.setSize(Files.size(textFileInMemSys));
                 zipOut.putArchiveEntry(entry);
@@ -370,7 +387,7 @@ public class ZipMemoryFileSystemTest {
             final Path zipInLocalSys = Files.createTempFile(dir, "commons-compress-memoryfs", ".zip");
             try (final SeekableByteChannel byteChannel = Files.newByteChannel(zipInLocalSys,
                     EnumSet.of(StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING));
-                 final ArchiveOutputStream zipOut = new ZipArchiveOutputStream(byteChannel)) {
+                    final ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(byteChannel)) {
                 final ZipArchiveEntry entry = new ZipArchiveEntry(textFileInMemSys, textFileInMemSys.getFileName().toString());
                 entry.setSize(Files.size(textFileInMemSys));
                 zipOut.putArchiveEntry(entry);
@@ -392,7 +409,7 @@ public class ZipMemoryFileSystemTest {
             Files.write(textFileInMemSys, bytes);
 
             final Path zipInLocalSys = Files.createTempFile(dir, "commons-compress-memoryfs", ".zip");
-            try (final ArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInLocalSys.toFile(), 64 * 1024L)) {
+            try (final ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInLocalSys.toFile(), 64 * 1024L)) {
                 final ZipArchiveEntry entry = new ZipArchiveEntry(textFileInMemSys, textFileInMemSys.getFileName().toString());
                 entry.setSize(Files.size(textFileInMemSys));
                 zipOut.putArchiveEntry(entry);
@@ -402,14 +419,10 @@ public class ZipMemoryFileSystemTest {
                 zipOut.finish();
                 List<Path> splitZips;
                 try (Stream<Path> paths = Files.walk(dir, 1)) {
-                    splitZips = paths
-                            .filter(Files::isRegularFile)
-                            .peek(path -> println("Found: " + path.toAbsolutePath()))
-                            .collect(Collectors.toList());
+                    splitZips = paths.filter(Files::isRegularFile).peek(path -> println("Found: " + path.toAbsolutePath())).collect(Collectors.toList());
                 }
                 assertEquals(splitZips.size(), 2);
-                assertEquals(Files.size(splitZips.get(0)) +
-                        Files.size(splitZips.get(1)) - 4, zipOut.getBytesWritten());
+                assertEquals(Files.size(splitZips.get(0)) + Files.size(splitZips.get(1)) - 4, zipOut.getBytesWritten());
             }
         }
 
@@ -421,7 +434,7 @@ public class ZipMemoryFileSystemTest {
             final Path p = fileSystem.getPath("target.zip");
 
             try (final OutputStream out = Files.newOutputStream(p);
-                 final ArchiveOutputStream zipOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.ZIP, out)) {
+                    final ArchiveOutputStream<ZipArchiveEntry> zipOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.ZIP, out)) {
                 final String content = "Test";
                 final ZipArchiveEntry entry = new ZipArchiveEntry("test.txt");
                 entry.setSize(content.length());
@@ -441,7 +454,7 @@ public class ZipMemoryFileSystemTest {
         try (FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().build()) {
             final Path zipInMemSys = fileSystem.getPath("target.zip");
 
-            try (final ArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInMemSys)) {
+            try (final ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInMemSys)) {
                 final String content = "Test";
                 final ZipArchiveEntry entry = new ZipArchiveEntry("test.txt");
                 entry.setSize(content.length());
@@ -462,9 +475,8 @@ public class ZipMemoryFileSystemTest {
             final Path zipInMemSys = fileSystem.getPath("target.zip");
 
             try (final SeekableByteChannel byteChannel = Files.newByteChannel(zipInMemSys,
-                    EnumSet.of(StandardOpenOption.READ, StandardOpenOption.WRITE,
-                            StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE_NEW));
-                 final ArchiveOutputStream zipOut = new ZipArchiveOutputStream(byteChannel)) {
+                    EnumSet.of(StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE_NEW));
+                    final ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(byteChannel)) {
                 final String content = "Test";
                 final ZipArchiveEntry entry = new ZipArchiveEntry("test.txt");
                 entry.setSize(content.length());
@@ -486,7 +498,7 @@ public class ZipMemoryFileSystemTest {
             final byte[] bytes = new byte[100 * 1024];
             SecureRandom.getInstanceStrong().nextBytes(bytes);
 
-            try (final ArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInMemSys, 64 * 1024L)) {
+            try (final ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInMemSys, 64 * 1024L)) {
                 final ZipArchiveEntry entry = new ZipArchiveEntry("test.txt");
                 entry.setSize(bytes.length);
                 zipOut.putArchiveEntry(entry);
@@ -498,14 +510,10 @@ public class ZipMemoryFileSystemTest {
 
                 List<Path> splitZips;
                 try (Stream<Path> paths = Files.walk(fileSystem.getPath("."), 1)) {
-                    splitZips = paths
-                            .filter(Files::isRegularFile)
-                            .peek(path -> println("Found: " + path.toAbsolutePath()))
-                            .collect(Collectors.toList());
+                    splitZips = paths.filter(Files::isRegularFile).peek(path -> println("Found: " + path.toAbsolutePath())).collect(Collectors.toList());
                 }
                 assertEquals(splitZips.size(), 2);
-                assertEquals(Files.size(splitZips.get(0)) +
-                        Files.size(splitZips.get(1)) - 4, zipOut.getBytesWritten());
+                assertEquals(Files.size(splitZips.get(0)) + Files.size(splitZips.get(1)) - 4, zipOut.getBytesWritten());
             }
         }
 
diff --git a/src/test/java/org/apache/commons/compress/compressors/Pack200TestCase.java b/src/test/java/org/apache/commons/compress/compressors/Pack200TestCase.java
index 31b11078..80307f80 100644
--- a/src/test/java/org/apache/commons/compress/compressors/Pack200TestCase.java
+++ b/src/test/java/org/apache/commons/compress/compressors/Pack200TestCase.java
@@ -34,8 +34,8 @@ import java.util.Map;
 import org.apache.commons.compress.AbstractTestCase;
 import org.apache.commons.compress.archivers.ArchiveEntry;
 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.jar.JarArchiveOutputStream;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 import org.apache.commons.compress.compressors.pack200.Pack200CompressorInputStream;
 import org.apache.commons.compress.compressors.pack200.Pack200CompressorOutputStream;
@@ -52,7 +52,7 @@ public final class Pack200TestCase extends AbstractTestCase {
         final File file2 = getFile("test2.xml");
 
         try (OutputStream out = new Pack200CompressorOutputStream(Files.newOutputStream(output.toPath()), mode);
-             ArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("jar", out)) {
+             JarArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("jar", out)) {
 
             os.putArchiveEntry(new ZipArchiveEntry("testdata/test1.xml"));
             Files.copy(file1.toPath(), os);
@@ -64,7 +64,7 @@ public final class Pack200TestCase extends AbstractTestCase {
         }
 
         try (InputStream is = new Pack200CompressorInputStream(output);
-            final ArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
+            final ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
             final List<String> files = new ArrayList<>();
             files.add("testdata/test1.xml");
             files.add("testdata/test2.xml");
@@ -78,7 +78,7 @@ public final class Pack200TestCase extends AbstractTestCase {
         try (
             InputStream is = useFile ? new Pack200CompressorInputStream(input, mode)
                 : new Pack200CompressorInputStream(Files.newInputStream(input.toPath()), mode);
-            ArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
+            ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
 
             ArchiveEntry entry = in.getNextEntry();
             while (entry != null) {
diff --git a/src/test/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStreamTest.java
index 57c62bd2..7ad1511b 100644
--- a/src/test/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStreamTest.java
@@ -43,8 +43,7 @@ public class BZip2CompressorInputStreamTest extends AbstractTestCase {
         for (int i = 0; i < len; i++) {
             input[i] = (byte) bytes[i];
         }
-        try (ArchiveInputStream ais = ArchiveStreamFactory.DEFAULT
-             .createArchiveInputStream("zip", new ByteArrayInputStream(input))) {
+        try (ArchiveInputStream<?> ais = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", new ByteArrayInputStream(input))) {
             ais.getNextEntry();
             IOUtils.toByteArray(ais);
         }
diff --git a/src/test/java/org/apache/commons/compress/compressors/deflate64/Deflate64CompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/deflate64/Deflate64CompressorInputStreamTest.java
index 1ff9c08b..1a4e1338 100644
--- a/src/test/java/org/apache/commons/compress/compressors/deflate64/Deflate64CompressorInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/deflate64/Deflate64CompressorInputStreamTest.java
@@ -81,8 +81,7 @@ public class Deflate64CompressorInputStreamTest {
         for (int i = 0; i < len; i++) {
             input[i] = (byte) bytes[i];
         }
-        try (ArchiveInputStream ais = ArchiveStreamFactory.DEFAULT
-             .createArchiveInputStream("zip", new ByteArrayInputStream(input))) {
+        try (ArchiveInputStream<?> ais = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", new ByteArrayInputStream(input))) {
             ais.getNextEntry();
             IOUtils.toByteArray(ais);
         }
diff --git a/src/test/java/org/apache/commons/compress/compressors/pack200/Pack200UtilsTest.java b/src/test/java/org/apache/commons/compress/compressors/pack200/Pack200UtilsTest.java
index a413aab9..e7aeb34d 100644
--- a/src/test/java/org/apache/commons/compress/compressors/pack200/Pack200UtilsTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/pack200/Pack200UtilsTest.java
@@ -39,7 +39,7 @@ public final class Pack200UtilsTest extends AbstractTestCase {
         try {
             Pack200Utils.normalize(input, output[1], new HashMap<>());
             try (InputStream is = Files.newInputStream(output[1].toPath());
-                    ArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
+                    ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
 
                 ArchiveEntry entry = in.getNextEntry();
                 while (entry != null) {
@@ -73,7 +73,7 @@ public final class Pack200UtilsTest extends AbstractTestCase {
             Pack200Utils.normalize(output[1]);
 
             try (InputStream is = Files.newInputStream(output[1].toPath());
-                    ArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
+                    ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
 
                 ArchiveEntry entry = in.getNextEntry();
                 while (entry != null) {