commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r911031 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio: CpioArchiveOutputStream.java CpioConstants.java
Date Wed, 17 Feb 2010 16:00:21 GMT
Author: bodewig
Date: Wed Feb 17 16:00:21 2010
New Revision: 911031

URL: http://svn.apache.org/viewvc?rev=911031&view=rev
Log:
it looks as if CPIO was writing files in blocks with 512 being the default blocksize.  COMPRESS-85

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioConstants.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java?rev=911031&r1=911030&r2=911031&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
Wed Feb 17 16:00:21 2010
@@ -91,7 +91,7 @@
      *            The format of the stream
      */
     public CpioArchiveOutputStream(final OutputStream out, final short format) {
-        this.out = new FilterOutputStream(out);
+        this.out = new CountingStream(out);
         switch (format) {
         case FORMAT_NEW:
         case FORMAT_NEW_CRC:
@@ -336,7 +336,13 @@
         this.entry.setNumberOfLinks(1);
         writeHeader(this.entry);
         closeArchiveEntry();
-        
+
+        int lengthOfLastBlock =
+            (int) (((CountingStream) out).getTotalWritten() % BLOCK_SIZE);
+        if (lengthOfLastBlock != 0) {
+            pad(BLOCK_SIZE - lengthOfLastBlock);
+        }
+
         finished = true;
     }
 
@@ -418,4 +424,24 @@
         return new CpioArchiveEntry(inputFile, entryName);
     }
 
+    private static class CountingStream extends FilterOutputStream {
+        private long totalWritten = 0;
+
+        private CountingStream(final OutputStream out) {
+            super(out);
+        }
+        public void write(byte[] b) throws IOException {
+            write(b, 0, b.length);
+        }
+        public void write(int b) throws IOException {
+            totalWritten++;
+            out.write(b);
+        }
+        public void write(byte[] b, int off, int len)
+            throws IOException {
+            totalWritten += len;
+            out.write(b, off, len);
+        }
+        private long getTotalWritten() { return totalWritten; }
+    }
 }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioConstants.java?rev=911031&r1=911030&r2=911031&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioConstants.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioConstants.java
Wed Feb 17 16:00:21 2010
@@ -134,4 +134,7 @@
 
     /** The special trailer marker */
     final String CPIO_TRAILER = "TRAILER!!!";
+
+    /** The default block size */
+    final int BLOCK_SIZE = 512;
 }



Mime
View raw message