Author: bodewig
Date: Mon Aug 15 11:30:14 2011
New Revision: 1157782

URL: http://svn.apache.org/viewvc?rev=1157782&view=rev
Log:
DumpArchiveInputStream didn't count bytes read.  COMPRESS-132

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

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java?rev=1157782&r1=1157781&r2=1157782&view=diff
==============================================================================
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java
 Mon Aug 15 11:30:14 2011
@@ -21,6 +21,7 @@ package org.apache.commons.compress.arch
 import org.apache.commons.compress.archivers.ArchiveException;
 import org.apache.commons.compress.archivers.ArchiveInputStream;
 
+import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -71,7 +72,7 @@ public class DumpArchiveInputStream exte
      * @throws Exception
      */
     public DumpArchiveInputStream(InputStream is) throws ArchiveException {
-        this.raw = new TapeInputStream(is);
+        this.raw = new TapeInputStream(new CountingStream(is));
         this.hasHitEOF = false;
 
         try {
@@ -482,4 +483,30 @@ outer: 
         return DumpArchiveConstants.NFS_MAGIC == 
DumpArchiveUtil.convert32(buffer,
             7);
     }
+
+    private class CountingStream extends FilterInputStream {
+        private CountingStream(final InputStream in) {
+            super(in);
+        }
+        @Override
+        public int read() throws IOException {
+            int r = in.read();
+            if (r >= 0) {
+                count(1);
+            }
+            return r;
+        }
+        @Override
+        public int read(byte[] b) throws IOException {
+            return read(b, 0, b.length);
+        }
+        @Override
+        public int read(byte[] b, int off, int len) throws IOException {
+            int r = in.read(b, off, len);
+            if (r >= 0) {
+                count(r);
+            }
+            return r;
+        }
+    }
 }


Reply via email to