Author: sebb
Date: Thu Apr  2 23:32:33 2009
New Revision: 761473

URL: http://svn.apache.org/viewvc?rev=761473&view=rev
Log:
Give Tar more data to work with when autodetecting

Modified:
    
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java?rev=761473&r1=761472&r2=761473&view=diff
==============================================================================
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
 Thu Apr  2 23:32:33 2009
@@ -131,18 +131,21 @@
             in.reset();
             if (ZipArchiveInputStream.matches(signature, signatureLength)) {
                 return new ZipArchiveInputStream(in);
-            } else if (JarArchiveInputStream
-                    .matches(signature, signatureLength)) {
+            } else if (JarArchiveInputStream.matches(signature, 
signatureLength)) {
                 return new JarArchiveInputStream(in);
-            } else if (TarArchiveInputStream
-                    .matches(signature, signatureLength)) {
-                return new TarArchiveInputStream(in);
             } else if (ArArchiveInputStream.matches(signature, 
signatureLength)) {
                 return new ArArchiveInputStream(in);
-            } else if (CpioArchiveInputStream.matches(signature,
-                    signatureLength)) {
+            } else if (CpioArchiveInputStream.matches(signature, 
signatureLength)) {
                 return new CpioArchiveInputStream(in);
             }
+            // Tar needs a bigger buffer to check the signature; read the 
first block
+            final byte[] tarheader = new byte[512];
+            in.mark(tarheader.length);
+            signatureLength = in.read(tarheader);
+            in.reset();
+            if (TarArchiveInputStream.matches(tarheader, signatureLength)) {
+                return new TarArchiveInputStream(in);
+            }
         } catch (IOException e) {
             throw new ArchiveException(
                     "Could not use reset and mark operations.", e);


Reply via email to