Author: scolebourne Date: Sun Dec 3 10:30:07 2006 New Revision: 481854 URL: http://svn.apache.org/viewvc?view=rev&rev=481854 Log: IO-84 - Make IOUtils.copy return -1 not an exception for large files, as more backwards compatible
Modified: jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsCopyTestCase.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=481854&r1=481853&r2=481854 ============================================================================== --- jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt (original) +++ jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt Sun Dec 3 10:30:07 2006 @@ -60,15 +60,14 @@ - This now handles the situation where an error occurs when deleting the file - IOUtils.copy [IO-84] - - The copy(InputStream, OutputStream) method now throws an exception if - the count is greater than an int - - The copy(Reader, Writer) method now throws an exception if - the count is greater than an int + - Copy methods could return inaccurate byte/char count for large streams + - The copy(InputStream, OutputStream) method now returns -1 if the count is greater than an int + - The copy(Reader, Writer) method now throws now returns -1 if the count is greater than an int - Added a new copyLarge(InputStream, OutputStream) method that returns a long - Added a new copyLarge(Reader, Writer) method that returns a long - CountingInputStream/CountingOutputStream [IO-84] - - methods were declared as int thus the count was innacurate for large streams + - 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 Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java?view=diff&rev=481854&r1=481853&r2=481854 ============================================================================== --- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java (original) +++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java Sun Dec 3 10:30:07 2006 @@ -982,10 +982,10 @@ * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * <p> - * Large streams (over 2GB) will throw an [EMAIL PROTECTED] ArithmeticException} - * after the copy has completed since the correct number of bytes - * cannot be returned as an int. For large streams use the - * <code>copyLarge(InputStream, OutputStream)</code> method. + * Large streams (over 2GB) will return a bytes copied value of + * <code>-1</code> after the copy has completed since the correct + * number of bytes cannot be returned as an int. For large streams + * use the <code>copyLarge(InputStream, OutputStream)</code> method. * * @param input the <code>InputStream</code> to read from * @param output the <code>OutputStream</code> to write to @@ -995,13 +995,12 @@ * @throws ArithmeticException if the byte count is too large * @since Commons IO 1.1 */ - public static int copy(InputStream input, OutputStream output) - throws IOException { + public static int copy(InputStream input, OutputStream output) throws IOException { long count = copyLarge(input, output); if (count > Integer.MAX_VALUE) { - throw new ArithmeticException("The byte count " + count + " is too large to be converted to an int"); + return -1; } - return (int)count; + return (int) count; } /** @@ -1088,10 +1087,10 @@ * This method buffers the input internally, so there is no need to use a * <code>BufferedReader</code>. * <p> - * Large streams (over 2GB) will throw an [EMAIL PROTECTED] ArithmeticException} - * after the copy has completed since the correct number of characters - * cannot be returned as an int. For large streams use the - * <code>copyLarge(Reader, Writer)</code> method. + * Large streams (over 2GB) will return a chars copied value of + * <code>-1</code> after the copy has completed since the correct + * number of chars cannot be returned as an int. For large streams + * use the <code>copyLarge(Reader, Writer)</code> method. * * @param input the <code>Reader</code> to read from * @param output the <code>Writer</code> to write to @@ -1104,9 +1103,9 @@ public static int copy(Reader input, Writer output) throws IOException { long count = copyLarge(input, output); if (count > Integer.MAX_VALUE) { - throw new ArithmeticException("The character count " + count + " is too large to be converted to an int"); + return -1; } - return (int)count; + return (int) count; } /** Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsCopyTestCase.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsCopyTestCase.java?view=diff&rev=481854&r1=481853&r2=481854 ============================================================================== --- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsCopyTestCase.java (original) +++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsCopyTestCase.java Sun Dec 3 10:30:07 2006 @@ -125,12 +125,7 @@ OutputStream out = new NullOutputStream(); // Test copy() method - try { - IOUtils.copy(in, out); - fail("Expected copy() to throw an ArithmeticException"); - } catch (ArithmeticException ae) { - // expected result - } + assertEquals(-1, IOUtils.copy(in, out)); // reset the input in.close(); @@ -369,12 +364,7 @@ Writer writer = new NullWriter(); // Test copy() method - try { - IOUtils.copy(reader, writer); - fail("Expected copy() to throw an ArithmeticException"); - } catch (ArithmeticException ae) { - // expected result - } + assertEquals(-1, IOUtils.copy(reader, writer)); // reset the input reader.close(); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]