commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r743003 - in /commons/sandbox/compress/trunk/src: main/java/org/apache/commons/compress/archivers/ main/java/org/apache/commons/compress/archivers/tar/ test/java/org/apache/commons/compress/
Date Tue, 10 Feb 2009 15:58:29 GMT
Author: bodewig
Date: Tue Feb 10 15:57:46 2009
New Revision: 743003

URL: http://svn.apache.org/viewvc?rev=743003&view=rev
Log:
merge TarArchive*Stream with Tar*Stream

Removed:
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
Modified:
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarInputStream.java
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarOutputStream.java
    commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java

Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java?rev=743003&r1=743002&r2=743003&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
(original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
Tue Feb 10 15:57:46 2009
@@ -28,8 +28,8 @@
 import org.apache.commons.compress.archivers.cpio.CpioArchiveOutputStream;
 import org.apache.commons.compress.archivers.jar.JarArchiveInputStream;
 import org.apache.commons.compress.archivers.jar.JarArchiveOutputStream;
-import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
-import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
+import org.apache.commons.compress.archivers.tar.TarInputStream;
+import org.apache.commons.compress.archivers.tar.TarOutputStream;
 import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
 
@@ -52,7 +52,7 @@
         } else if("zip".equalsIgnoreCase(archiverName)) {
             return new ZipArchiveInputStream(in);
         } else if("tar".equalsIgnoreCase(archiverName)) {
-            return new TarArchiveInputStream(in);
+            return new TarInputStream(in);
         } else if("jar".equalsIgnoreCase(archiverName)) {
             return new JarArchiveInputStream(in);
         } else if("cpio".equalsIgnoreCase(archiverName)) {
@@ -67,7 +67,7 @@
         } else if("zip".equalsIgnoreCase(archiverName)) {
             return new ZipArchiveOutputStream(out);
         } else if("tar".equalsIgnoreCase(archiverName)) {
-            return new TarArchiveOutputStream(out);
+            return new TarOutputStream(out);
         } else if("jar".equalsIgnoreCase(archiverName)) {
             return new JarArchiveOutputStream(out);
         } else if("cpio".equalsIgnoreCase(archiverName)) {
@@ -88,8 +88,8 @@
             return new ZipArchiveInputStream(input);
         } else if(JarArchiveInputStream.matches(signature, signatureLength)) {
             return new JarArchiveInputStream(input);
-        } else if(TarArchiveInputStream.matches(signature, signatureLength)) {
-            return new TarArchiveInputStream(input);
+        } else if(TarInputStream.matches(signature, signatureLength)) {
+            return new TarInputStream(input);
         } else if(ArArchiveInputStream.matches(signature, signatureLength)) {
             return new ArArchiveInputStream(input);
         } else if(CpioArchiveInputStream.matches(signature, signatureLength)) {

Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarInputStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarInputStream.java?rev=743003&r1=743002&r2=743003&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarInputStream.java
(original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarInputStream.java
Tue Feb 10 15:57:46 2009
@@ -23,10 +23,11 @@
 
 package org.apache.commons.compress.archivers.tar;
 
-import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveInputStream;
 
 /**
  * The TarInputStream reads a UNIX tar archive as an InputStream.
@@ -35,7 +36,7 @@
  * using read().
  *
  */
-public class TarInputStream extends FilterInputStream {
+public class TarInputStream extends ArchiveInputStream {
     private static final int SMALL_BUFFER_SIZE = 256;
     private static final int BUFFER_SIZE = 8 * 1024;
     private static final int LARGE_BUFFER_SIZE = 32 * 1024;
@@ -59,6 +60,8 @@
 
     // CheckStyle:VisibilityModifier ON
 
+    private final InputStream in;
+
     /**
      * Constructor for TarInputStream.
      * @param is the input stream to use
@@ -83,7 +86,7 @@
      * @param recordSize the record size to use
      */
     public TarInputStream(InputStream is, int blockSize, int recordSize) {
-        super(is);
+        this.in = is;
 
         this.buffer = new TarBuffer(is, blockSize, recordSize);
         this.readBuf = null;
@@ -167,23 +170,6 @@
     }
 
     /**
-     * Since we do not support marking just yet, we return false.
-     *
-     * @return False.
-     */
-    public boolean markSupported() {
-        return false;
-    }
-
-    /**
-     * Since we do not support marking just yet, we do nothing.
-     *
-     * @param markLimit The limit to mark.
-     */
-    public void mark(int markLimit) {
-    }
-
-    /**
      * Since we do not support marking just yet, we do nothing.
      */
     public void reset() {
@@ -202,7 +188,7 @@
      * @return The next TarEntry in the archive, or null.
      * @throws IOException on error
      */
-    public TarArchiveEntry getNextEntry() throws IOException {
+    public ArchiveEntry getNextEntry() throws IOException {
         if (hasHitEOF) {
             return null;
         }
@@ -399,4 +385,47 @@
             out.write(buf, 0, numRead);
         }
     }
+
+    // used to be implemented via FilterInputStream
+    public int read(byte[] b) throws IOException {
+        return read(b, 0, b.length);
+    }
+
+    // ArchiveInputStream
+
+    public static boolean matches(byte[] signature, int length) {
+        // 6574 7473 2e31 6d78
+        
+        if (length < 8) {
+            return false;
+        }
+
+        if (signature[0] != 0x74) {
+            return false;
+        }
+        if (signature[1] != 0x65) {
+            return false;
+        }
+        if (signature[2] != 0x73) {
+            return false;
+        }
+        if (signature[3] != 0x74) {
+            return false;
+        }
+        if (signature[4] != 0x31) {
+            return false;
+        }
+        if (signature[5] != 0x2e) {
+            return false;
+        }
+        if (signature[6] != 0x78) {
+            return false;
+        }
+        if (signature[7] != 0x6d) {
+            return false;
+        }
+        
+        return true;
+    }
+    
 }

Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarOutputStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarOutputStream.java?rev=743003&r1=743002&r2=743003&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarOutputStream.java
(original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarOutputStream.java
Tue Feb 10 15:57:46 2009
@@ -18,9 +18,10 @@
  */
 package org.apache.commons.compress.archivers.tar;
 
-import java.io.FilterOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveOutputStream;
 
 /**
  * The TarOutputStream writes a UNIX tar archive as an OutputStream.
@@ -28,7 +29,7 @@
  * by writing to this stream using write().
  *
  */
-public class TarOutputStream extends FilterOutputStream {
+public class TarOutputStream extends ArchiveOutputStream {
     /** Fail if a long file name is required in the archive. */
     public static final int LONGFILE_ERROR = 0;
 
@@ -53,6 +54,8 @@
 
     private boolean closed = false;
 
+    private final OutputStream out;
+
     /**
      * Constructor for TarInputStream.
      * @param os the output stream to use
@@ -77,7 +80,7 @@
      * @param recordSize the record size to use
      */
     public TarOutputStream(OutputStream os, int blockSize, int recordSize) {
-        super(os);
+        out = os;
 
         this.buffer = new TarBuffer(os, blockSize, recordSize);
         this.debug = false;
@@ -345,4 +348,33 @@
 
         buffer.writeRecord(recordBuf);
     }
+
+    // used to be implemented via FilterOutputStream
+    public void flush() throws IOException {
+        out.flush();
+    }
+        
+    // ArchiveOutputStream
+
+    public void closeArchiveEntry() throws IOException {
+        closeEntry();
+    }
+
+    public void putArchiveEntry(ArchiveEntry entry) throws IOException {
+        putNextEntry((TarArchiveEntry) entry);
+    }
+
+    public String getDefaultFileExtension() {
+        return "tar";
+    }
+
+    public byte[] getHeader() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public String getName() {
+        return "tar";
+    }
+
 }

Modified: commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java?rev=743003&r1=743002&r2=743003&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java
(original)
+++ commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java
Tue Feb 10 15:57:46 2009
@@ -29,7 +29,7 @@
 import org.apache.commons.compress.archivers.ar.ArArchiveInputStream;
 import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream;
 import org.apache.commons.compress.archivers.jar.JarArchiveInputStream;
-import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.commons.compress.archivers.tar.TarInputStream;
 import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 
 public final class DetectArchiverTestCase extends TestCase {
@@ -46,7 +46,7 @@
 				new BufferedInputStream(new FileInputStream(
 						new File(getClass().getClassLoader().getResource("bla.tar").getFile()))));
 		assertNotNull(tar);
-		assertTrue(tar instanceof TarArchiveInputStream);
+		assertTrue(tar instanceof TarInputStream);
 
 		final ArchiveInputStream zip = factory.createArchiveInputStream(
 				new BufferedInputStream(new FileInputStream(



Mime
View raw message