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 2013/01/20 21:16:13 UTC

svn commit: r1435940 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java site/xdoc/examples.xml

Author: bodewig
Date: Sun Jan 20 20:16:13 2013
New Revision: 1435940

URL: http://svn.apache.org/viewvc?rev=1435940&view=rev
Log:
document 'EOF behaviour' of Dump/Ar/Cpio InputStreams

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
    commons/proper/compress/trunk/src/site/xdoc/examples.xml

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java?rev=1435940&r1=1435939&r2=1435940&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java Sun Jan 20 20:16:13 2013
@@ -44,7 +44,7 @@ import org.apache.commons.compress.archi
  * 
  * Due to the limitation of the file name length to 16 bytes GNU and
  * BSD has their own variants of this format. Currently Commons
- * Compress can read but not write the GNU variant and fully supports
+ * Compress can read but not write the GNU variant.  It fully supports
  * the BSD variant.
  * 
  * @see <a href="http://www.freebsd.org/cgi/man.cgi?query=ar&sektion=5">ar man page</a>

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java?rev=1435940&r1=1435939&r2=1435940&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java Sun Jan 20 20:16:13 2013
@@ -82,14 +82,32 @@ public class CpioArchiveInputStream exte
     private final byte[] FOUR_BYTES_BUF = new byte[4];
     private final byte[] SIX_BYTES_BUF = new byte[6];
 
+    private final int blockSize;
+
     /**
-     * Construct the cpio input stream
+     * Construct the cpio input stream with a blocksize of {@link
+     * CpioConstants#BLOCK_SIZE BLOCK_SIZE}.
      * 
      * @param in
      *            The cpio stream
      */
     public CpioArchiveInputStream(final InputStream in) {
+        this(in, BLOCK_SIZE);
+    }
+
+    /**
+     * Construct the cpio input stream with a blocksize of {@link CpioConstants#BLOCK_SIZE BLOCK_SIZE}.
+     * Construct the cpio input stream.
+     * 
+     * @param in
+     *            The cpio stream
+     * @param blockSize
+     *            The block size of the archive.
+     * @since 1.5
+     */
+    public CpioArchiveInputStream(final InputStream in, int blockSize) {
         this.in = in;
+        this.blockSize = blockSize;
     }
 
     /**
@@ -199,6 +217,7 @@ public class CpioArchiveInputStream exte
 
         if (this.entry.getName().equals(CPIO_TRAILER)) {
             this.entryEOF = true;
+            skipRemainderOfLastBlock();
             return null;
         }
         return this.entry;
@@ -433,6 +452,16 @@ public class CpioArchiveInputStream exte
     }
 
     /**
+     * Skips the padding zeros written after the TRAILER!!! entry.
+     */
+    private void skipRemainderOfLastBlock() throws IOException {
+        long readFromLastBlock = (getBytesRead() % blockSize);
+        if (readFromLastBlock != 0) {
+            skip(blockSize - readFromLastBlock);
+        }
+    }
+
+    /**
      * Checks if the signature matches one of the following magic values:
      * 
      * Strings:

Modified: commons/proper/compress/trunk/src/site/xdoc/examples.xml
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/site/xdoc/examples.xml?rev=1435940&r1=1435939&r2=1435940&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/site/xdoc/examples.xml (original)
+++ commons/proper/compress/trunk/src/site/xdoc/examples.xml Sun Jan 20 20:16:13 2013
@@ -116,6 +116,11 @@ LOOP UNTIL entry.getSize() HAS BEEN READ
           longer than 16 characters using the BSD dialect, writing
           the SVR4/GNU dialect is not supported.</p>
 
+        <p>It is not possible to detect the end of an AR archive in a
+        reliable way so <code>ArArchiveInputStream</code> will read
+        until it reaches the end of the stream or fails to parse the
+        stream's content as AR entries.</p>
+
       </subsection>
 
       <subsection name="cpio">
@@ -146,6 +151,16 @@ LOOP UNTIL entry.getSize() HAS BEEN READ
 }
 ]]></source>
 
+        <p>Traditionally CPIO archives are written in blocks of 512
+        bytes - the block size is a configuration parameter of the
+        <code>Cpio*Stream</code>'s constuctors.  Starting with version
+        1.5 <code>CpioArchiveInputStream</code> will consume the
+        padding written to fill the current block when the end of the
+        archive is reached.  Unfortunately many CPIO implementations
+        use larger block sizes so there may be more zero-byte padding
+        left inside the original input stream after the archive has
+        been consumed completely.</p>
+
       </subsection>
 
       <subsection name="dump">
@@ -170,6 +185,11 @@ LOOP UNTIL entry.getSize() HAS BEEN READ
 }
 ]]></source>
 
+        <p>Prior to version 1.5 <code>DumpArchiveInputStream</code>
+        would close the original input once it had read the last
+        record.  Starting with version 1.5 it will not close the
+        stream implicitly.</p>
+
       </subsection>
 
       <subsection name="tar">