You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2016/01/07 20:49:25 UTC

commons-compress git commit: reduce duplication as suggested by Jeremy Gustie

Repository: commons-compress
Updated Branches:
  refs/heads/master c9b96aaf7 -> 5d027c32c


reduce duplication as suggested by Jeremy Gustie


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/5d027c32
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/5d027c32
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/5d027c32

Branch: refs/heads/master
Commit: 5d027c32c97eaf43c5f296afce98f1e4afc7baca
Parents: c9b96aa
Author: Stefan Bodewig <bo...@apache.org>
Authored: Thu Jan 7 20:48:38 2016 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Thu Jan 7 20:48:38 2016 +0100

----------------------------------------------------------------------
 .../archivers/ArchiveStreamFactory.java         | 32 +++++---------------
 1 file changed, 8 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/5d027c32/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
----------------------------------------------------------------------
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 78f254d..28fe13b 100644
--- a/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
+++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
@@ -342,31 +342,15 @@ public class ArchiveStreamFactory {
             int signatureLength = IOUtils.readFully(in, signature);
             in.reset();
             if (ZipArchiveInputStream.matches(signature, signatureLength)) {
-                if (entryEncoding != null) {
-                    return new ZipArchiveInputStream(in, entryEncoding);
-                } else {
-                    return new ZipArchiveInputStream(in);
-                }
+                return createArchiveInputStream(ZIP, in);
             } else if (JarArchiveInputStream.matches(signature, signatureLength)) {
-                if (entryEncoding != null) {
-                    return new JarArchiveInputStream(in, entryEncoding);
-                } else {
-                    return new JarArchiveInputStream(in);
-                }
+                return createArchiveInputStream(JAR, in);
             } else if (ArArchiveInputStream.matches(signature, signatureLength)) {
-                return new ArArchiveInputStream(in);
+                return createArchiveInputStream(AR, in);
             } else if (CpioArchiveInputStream.matches(signature, signatureLength)) {
-                if (entryEncoding != null) {
-                    return new CpioArchiveInputStream(in, entryEncoding);
-                } else {
-                    return new CpioArchiveInputStream(in);
-                }
+                return createArchiveInputStream(CPIO, in);
             } else if (ArjArchiveInputStream.matches(signature, signatureLength)) {
-                if (entryEncoding != null) {
-                    return new ArjArchiveInputStream(in, entryEncoding);
-                } else {
-                    return new ArjArchiveInputStream(in);
-                }
+                return createArchiveInputStream(ARJ, in);
             } else if (SevenZFile.matches(signature, signatureLength)) {
                 throw new StreamingNotSupportedException(SEVEN_Z);
             }
@@ -377,7 +361,7 @@ public class ArchiveStreamFactory {
             signatureLength = IOUtils.readFully(in, dumpsig);
             in.reset();
             if (DumpArchiveInputStream.matches(dumpsig, signatureLength)) {
-                return new DumpArchiveInputStream(in, entryEncoding);
+                return createArchiveInputStream(DUMP, in);
             }
 
             // Tar needs an even bigger buffer to check the signature; read the first block
@@ -386,7 +370,7 @@ public class ArchiveStreamFactory {
             signatureLength = IOUtils.readFully(in, tarheader);
             in.reset();
             if (TarArchiveInputStream.matches(tarheader, signatureLength)) {
-                return new TarArchiveInputStream(in, entryEncoding);
+                return createArchiveInputStream(TAR, in);
             }
             // COMPRESS-117 - improve auto-recognition
             if (signatureLength >= 512) {
@@ -395,7 +379,7 @@ public class ArchiveStreamFactory {
                     tais = new TarArchiveInputStream(new ByteArrayInputStream(tarheader));
                     // COMPRESS-191 - verify the header checksum
                     if (tais.getNextTarEntry().isCheckSumOK()) {
-                        return new TarArchiveInputStream(in, encoding);
+                        return createArchiveInputStream(TAR, in);
                     }
                 } catch (Exception e) { // NOPMD
                     // can generate IllegalArgumentException as well