commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r911465 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress: archivers/ archivers/ar/ archivers/cpio/ archivers/tar/ compressors/
Date Thu, 18 Feb 2010 16:10:21 GMT
Author: bodewig
Date: Thu Feb 18 16:10:20 2010
New Revision: 911465

URL: http://svn.apache.org/viewvc?rev=911465&view=rev
Log:
use long to count bytes or we get trouble with archives > 2GB

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorInputStream.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java?rev=911465&r1=911464&r2=911465&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java
Thu Feb 18 16:10:20 2010
@@ -43,7 +43,7 @@
     private static final int BYTE_MASK = 0xFF;
     
     /** holds the number of bytes read in this stream */
-    private int bytesRead = 0;
+    private long bytesRead = 0;
 
     /**
      * Returns the next Archive Entry in this Stream.
@@ -74,8 +74,7 @@
      * 
      * @return the byte read, or -1 if end of input is reached
      * @throws IOException
-     *             if an I/O error has occurred or if a CPIO file error has
-     *             occurred
+     *             if an I/O error has occurred
      */
     public int read() throws IOException {
         int num = read(SINGLE, 0, 1);
@@ -89,16 +88,45 @@
      * @param read the number of bytes read
      */
     protected void count(int read) {
-        if(read != -1) {
+        count((long) read);
+    }
+
+    /**
+     * Increments the counter of already read bytes.
+     * Doesn't increment if the EOF has been hit (read == -1)
+     * 
+     * @param read the number of bytes read
+     */
+    protected void count(long read) {
+        if (read != -1) {
             bytesRead = bytesRead + read;
         }
     }
     
     /**
+     * Decrements the counter of already read bytes.
+     * 
+     * @param read the number of bytes pushed back.
+     */
+    protected void pushedBackBytes(long pushedBack) {
+        bytesRead -= pushedBack;
+    }
+    
+    /**
      * Returns the current number of bytes read from this stream.
      * @return the number of read bytes
+     * @deprecated this method may yield wrong results for large
+     * archives, use #getBytesRead instead
      */
     public int getCount() {
+        return (int) bytesRead;
+    }
+
+    /**
+     * Returns the current number of bytes read from this stream.
+     * @return the number of read bytes
+     */
+    public long getBytesRead() {
         return bytesRead;
     }
 }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java?rev=911465&r1=911464&r2=911465&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
Thu Feb 18 16:10:20 2010
@@ -52,8 +52,8 @@
     private final byte[] oneByte = new byte[1];
     static final int BYTE_MASK = 0xFF;
 
-    /** holds the number of bytes read in this stream */
-    private int bytesRead = 0;
+    /** holds the number of bytes written to this stream */
+    private long bytesWritten = 0;
     // Methods specific to ArchiveOutputStream
     
     /**
@@ -113,22 +113,42 @@
     }
 
     /**
-     * Increments the counter of already read bytes.
+     * Increments the counter of already written bytes.
      * Doesn't increment if the EOF has been hit (read == -1)
      * 
      * @param read the number of bytes read
      */
     protected void count(int read) {
-        if(read != -1) {
-            bytesRead = bytesRead + read;
+        count((long) read);
+    }
+
+    /**
+     * Increments the counter of already written bytes.
+     * Doesn't increment if the EOF has been hit (read == -1)
+     * 
+     * @param written the number of bytes written
+     */
+    protected void count(long written) {
+        if (written != -1) {
+            bytesWritten = bytesWritten + written;
         }
     }
     
     /**
-     * Returns the current number of bytes read from this stream.
-     * @return the number of read bytes
+     * Returns the current number of bytes written to this stream.
+     * @return the number of written bytes
+     * @deprecated this method may yield wrong results for large
+     * archives, use #getBytesWritten instead
      */
     public int getCount() {
-        return bytesRead;
+        return (int) bytesWritten;
+    }
+
+    /**
+     * Returns the current number of bytes written to this stream.
+     * @return the number of written bytes
+     */
+    public long getBytesWritten() {
+        return bytesWritten;
     }
 }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java?rev=911465&r1=911464&r2=911465&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
Thu Feb 18 16:10:20 2010
@@ -86,7 +86,7 @@
             final byte[] realized = new byte[expected.length];
             final int read = read(realized);
             if (read != expected.length) {
-                throw new IOException("failed to read header. Occured at byte: " + getCount());
+                throw new IOException("failed to read header. Occured at byte: " + getBytesRead());
             }
             for (int i = 0; i < expected.length; i++) {
                 if (expected[i] != realized[i]) {
@@ -125,11 +125,11 @@
             final byte[] realized = new byte[expected.length];
             final int read = read(realized);
             if (read != expected.length) {
-                throw new IOException("failed to read entry header. Occured at byte: " +
getCount());
+                throw new IOException("failed to read entry header. Occured at byte: " +
getBytesRead());
             }
             for (int i = 0; i < expected.length; i++) {
                 if (expected[i] != realized[i]) {
-                    throw new IOException("invalid entry header. not read the content? Occured
at byte: " + getCount());
+                    throw new IOException("invalid entry header. not read the content? Occured
at byte: " + getBytesRead());
                 }
             }
         }

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=911465&r1=911464&r2=911465&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
Thu Feb 18 16:10:20 2010
@@ -184,7 +184,7 @@
             } else if (magicString.equals(MAGIC_OLD_ASCII)) {
                 this.entry = readOldAsciiEntry();
             } else {
-                throw new IOException("Unknown magic [" + magicString + "]. Occured at byte:
" + getCount());
+                throw new IOException("Unknown magic [" + magicString + "]. Occured at byte:
" + getBytesRead());
             }
         }
 
@@ -239,7 +239,7 @@
             this.entryEOF = true;
             if (this.entry.getFormat() == FORMAT_NEW_CRC) {
                 if (this.crc != this.entry.getChksum()) {
-                    throw new IOException("CRC Error. Occured at byte: " + getCount());
+                    throw new IOException("CRC Error. Occured at byte: " + getBytesRead());
                 }
             }
             return -1; // EOF for this entry
@@ -320,7 +320,7 @@
         String name = readCString((int) namesize);
         ret.setName(name);
         if (mode == 0 && !name.equals(CPIO_TRAILER)){
-            throw new IOException("Mode 0 only allowed in the trailer. Found entry name:
"+name + " Occured at byte: " + getCount());
+            throw new IOException("Mode 0 only allowed in the trailer. Found entry name:
"+name + " Occured at byte: " + getBytesRead());
         }
         skip(ret.getHeaderPadCount());
 
@@ -346,7 +346,7 @@
         final String name = readCString((int) namesize);
         ret.setName(name);
         if (mode == 0 && !name.equals(CPIO_TRAILER)){
-            throw new IOException("Mode 0 only allowed in the trailer. Found entry: "+ name
+ " Occured at byte: " + getCount());
+            throw new IOException("Mode 0 only allowed in the trailer. Found entry: "+ name
+ " Occured at byte: " + getBytesRead());
         }
 
         return ret;
@@ -372,7 +372,7 @@
         final String name = readCString((int) namesize);
         ret.setName(name);
         if (mode == 0 && !name.equals(CPIO_TRAILER)){
-            throw new IOException("Mode 0 only allowed in the trailer. Found entry: "+name
+ "Occured at byte: " + getCount());
+            throw new IOException("Mode 0 only allowed in the trailer. Found entry: "+name
+ "Occured at byte: " + getBytesRead());
         }
         skip(ret.getHeaderPadCount());
 

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java?rev=911465&r1=911464&r2=911465&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
Thu Feb 18 16:10:20 2010
@@ -275,7 +275,7 @@
             if (rec == null) {
                 // Unexpected EOF!
                 throw new IOException("unexpected EOF with " + numToRead
-                                      + " bytes unread. Occured at byte: " + getCount());
+                                      + " bytes unread. Occured at byte: " + getBytesRead());
             }
             count(rec.length);
             int sz = numToRead;

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorInputStream.java?rev=911465&r1=911464&r2=911465&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorInputStream.java
Thu Feb 18 16:10:20 2010
@@ -21,7 +21,7 @@
 import java.io.InputStream;
 
 public abstract class CompressorInputStream extends InputStream {
-    private int bytesRead = 0;
+    private long bytesRead = 0;
     
     /**
      * Increments the counter of already read bytes.
@@ -30,16 +30,36 @@
      * @param read the number of bytes read
      */
     protected void count(int read) {
+        count((long) read);
+    }
+    
+    /**
+     * Increments the counter of already read bytes.
+     * Doesn't increment if the EOF has been hit (read == -1)
+     * 
+     * @param read the number of bytes read
+     */
+    protected void count(long read) {
         if(read != -1) {
             bytesRead = bytesRead + read;
         }
     }
-    
+
     /**
      * Returns the current number of bytes read from this stream.
      * @return the number of read bytes
+     * @deprecated this method may yield wrong results for large
+     * archives, use #getBytesRead instead
      */
     public int getCount() {
+        return (int) bytesRead;
+    }
+
+    /**
+     * Returns the current number of bytes read from this stream.
+     * @return the number of read bytes
+     */
+    public long getBytesRead() {
         return bytesRead;
     }
 }



Mime
View raw message