commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r462818 - in /jakarta/commons/proper/io/trunk: RELEASE-NOTES.txt src/java/org/apache/commons/io/input/CountingInputStream.java src/java/org/apache/commons/io/output/CountingOutputStream.java
Date Wed, 11 Oct 2006 14:44:18 GMT
Author: scolebourne
Date: Wed Oct 11 07:44:17 2006
New Revision: 462818

URL: http://svn.apache.org/viewvc?view=rev&rev=462818
Log:
IO-84 - Change int methods from deprecated to exception throwng

Modified:
    jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt
    jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/input/CountingInputStream.java
    jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/CountingOutputStream.java

Modified: jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt?view=diff&rev=462818&r1=462817&r2=462818
==============================================================================
--- jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt (original)
+++ jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt Wed Oct 11 07:44:17 2006
@@ -63,6 +63,11 @@
   - Comment about result byte/char count being limited to an int, thus
     being inacurate for large streams
 
+- CountingInputStream/CountingOutputStream [IO-84]
+  - methods were declared as int thus the count was innacurate for large streams
+  - new long based methods getByteCount()/resetByteCount() added
+  - existing methods changed to throw an exception if the count is greater than an int
+
 
 Enhancements from 1.2
 ---------------------

Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/input/CountingInputStream.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/input/CountingInputStream.java?view=diff&rev=462818&r1=462817&r2=462818
==============================================================================
--- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/input/CountingInputStream.java
(original)
+++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/input/CountingInputStream.java
Wed Oct 11 07:44:17 2006
@@ -110,49 +110,57 @@
     /**
      * The number of bytes that have passed through this stream.
      * <p>
-     * <strong>WARNING</strong> This method will return an
-     * incorrect count for files over 2GB - use
-     * <code>getByteCount()</code> instead.
+     * NOTE: From v1.3 this method throws an ArithmeticException if the
+     * count is greater than can be expressed by an <code>int</code>.
+     * See {@link #getByteCount()} for a method using a <code>long</code>.
      *
      * @return the number of bytes accumulated
-     * @deprecated use <code>getByteCount()</code> - see issue IO-84
+     * @throws ArithmeticException if the byte count is too large
      */
-    public int getCount() {
-        return (int) getByteCount();
+    public synchronized int getCount() {
+        long result = getByteCount();
+        if (result > Integer.MAX_VALUE) {
+            throw new ArithmeticException("The byte count " + result + " is too large to
be converted to an int");
+        }
+        return (int) result;
     }
 
     /** 
-     * Set the count back to 0. 
+     * Set the byte count back to 0. 
      * <p>
-     * <strong>WARNING</strong> This method will return an
-     * incorrect count for files over 2GB - use
-     * <code>resetByteCount()</code> instead.
+     * NOTE: From v1.3 this method throws an ArithmeticException if the
+     * count is greater than can be expressed by an <code>int</code>.
+     * See {@link #resetByteCount()} for a method using a <code>long</code>.
      *
-     * @return the count previous to resetting.
-     * @deprecated use <code>resetByteCount()</code> - see issue IO-84
+     * @return the count previous to resetting
+     * @throws ArithmeticException if the byte count is too large
      */
     public synchronized int resetCount() {
-        return (int) resetByteCount();
+        long result = resetByteCount();
+        if (result > Integer.MAX_VALUE) {
+            throw new ArithmeticException("The byte count " + result + " is too large to
be converted to an int");
+        }
+        return (int) result;
     }
 
     /**
      * The number of bytes that have passed through this stream.
      * <p>
-     * NOTE: This method is a replacement for <code>getCount()</code>
+     * NOTE: This method is an alternative for <code>getCount()</code>
      * and was added because that method returns an integer which will
      * result in incorrect count for files over 2GB.
      *
      * @return the number of bytes accumulated
      * @since Commons IO 1.3
      */
-    public long getByteCount() {
+    public synchronized long getByteCount() {
         return this.count;
     }
 
     /** 
      * Set the byte count back to 0. 
      * <p>
-     * NOTE: This method is a replacement for <code>resetCount()</code>
+     * NOTE: This method is an alternative for <code>resetCount()</code>
      * and was added because that method returns an integer which will
      * result in incorrect count for files over 2GB.
      *

Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/CountingOutputStream.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/CountingOutputStream.java?view=diff&rev=462818&r1=462817&r2=462818
==============================================================================
--- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/CountingOutputStream.java
(original)
+++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/CountingOutputStream.java
Wed Oct 11 07:44:17 2006
@@ -88,49 +88,57 @@
     /**
      * The number of bytes that have passed through this stream.
      * <p>
-     * <strong>WARNING</strong> This method will return an
-     * incorrect count for files over 2GB - use
-     * <code>getByteCount()</code> instead.
+     * NOTE: From v1.3 this method throws an ArithmeticException if the
+     * count is greater than can be expressed by an <code>int</code>.
+     * See {@link #getByteCount()} for a method using a <code>long</code>.
      *
      * @return the number of bytes accumulated
-     * @deprecated use <code>getByteCount()</code> - see issue IO-84
+     * @throws ArithmeticException if the byte count is too large
      */
-    public int getCount() {
-        return (int) getByteCount();
+    public synchronized int getCount() {
+        long result = getByteCount();
+        if (result > Integer.MAX_VALUE) {
+            throw new ArithmeticException("The byte count " + result + " is too large to
be converted to an int");
+        }
+        return (int) result;
     }
 
     /** 
-      * Set the count back to 0. 
-      * <p>
-      * <strong>WARNING</strong> This method will return an
-      * incorrect count for files over 2GB - use
-      * <code>resetByteCount()</code> instead.
-      *
-      * @return the count previous to resetting.
-      * @deprecated use <code>resetByteCount()</code> - see issue IO-84
-      */
+     * Set the byte count back to 0. 
+     * <p>
+     * NOTE: From v1.3 this method throws an ArithmeticException if the
+     * count is greater than can be expressed by an <code>int</code>.
+     * See {@link #resetByteCount()} for a method using a <code>long</code>.
+     *
+     * @return the count previous to resetting
+     * @throws ArithmeticException if the byte count is too large
+     */
     public synchronized int resetCount() {
-        return (int) resetByteCount();
+        long result = resetByteCount();
+        if (result > Integer.MAX_VALUE) {
+            throw new ArithmeticException("The byte count " + result + " is too large to
be converted to an int");
+        }
+        return (int) result;
     }
 
     /**
      * The number of bytes that have passed through this stream.
      * <p>
-     * NOTE: This method is a replacement for <code>getCount()</code>.
+     * NOTE: This method is an alternative for <code>getCount()</code>.
      * It was added because that method returns an integer which will
      * result in incorrect count for files over 2GB.
      *
      * @return the number of bytes accumulated
      * @since Commons IO 1.3
      */
-    public long getByteCount() {
+    public synchronized long getByteCount() {
         return this.count;
     }
 
     /** 
      * Set the byte count back to 0. 
      * <p>
-     * NOTE: This method is a replacement for <code>resetCount()</code>.
+     * NOTE: This method is an alternative for <code>resetCount()</code>.
      * It was added because that method returns an integer which will
      * result in incorrect count for files over 2GB.
      *



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message