Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 12539 invoked from network); 3 Jul 2003 15:54:45 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 3 Jul 2003 15:54:45 -0000 Received: (qmail 14177 invoked by uid 97); 3 Jul 2003 15:57:11 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@nagoya.betaversion.org Received: (qmail 14170 invoked from network); 3 Jul 2003 15:57:11 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 3 Jul 2003 15:57:11 -0000 Received: (qmail 7890 invoked by uid 500); 3 Jul 2003 15:53:44 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 54275 invoked by uid 500); 3 Jul 2003 14:43:06 -0000 Date: 3 Jul 2003 14:43:03 -0000 Message-ID: <20030703144303.198.qmail@icarus.apache.org> From: jeremias@apache.org To: jakarta-commons-sandbox-cvs@apache.org Subject: cvs commit: jakarta-commons-sandbox/io/src/java/org/apache/commons/io IOUtil.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N jeremias 2003/07/03 07:43:03 Modified: io/src/java/org/apache/commons/io IOUtil.java Log: Javadocs the most important copy() methods now return the number of bytes copied. Revision Changes Path 1.3 +125 -9 jakarta-commons-sandbox/io/src/java/org/apache/commons/io/IOUtil.java Index: IOUtil.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/IOUtil.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- IOUtil.java 7 Dec 2002 20:31:07 -0000 1.2 +++ IOUtil.java 3 Jul 2003 14:43:02 -0000 1.3 @@ -1,5 +1,3 @@ -package org.apache.commons.io; - /* ==================================================================== * The Apache Software License, Version 1.1 * @@ -53,6 +51,7 @@ * information on the Apache Software Foundation, please see * . */ +package org.apache.commons.io; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -252,52 +251,74 @@ /** * Copy bytes from an InputStream to an OutputStream. + * @param input the InputStream to read from + * @param output the OutputStream to write to + * @return the number of bytes copied + * @throws IOException In case of an I/O problem */ - public static void copy( final InputStream input, final OutputStream output ) + public static int copy( final InputStream input, final OutputStream output ) throws IOException { - copy( input, output, DEFAULT_BUFFER_SIZE ); + return copy( input, output, DEFAULT_BUFFER_SIZE ); } /** * Copy bytes from an InputStream to an OutputStream. + * @param input the InputStream to read from + * @param output the OutputStream to write to * @param bufferSize Size of internal buffer to use. + * @return the number of bytes copied + * @throws IOException In case of an I/O problem */ - public static void copy( final InputStream input, + public static int copy( final InputStream input, final OutputStream output, final int bufferSize ) throws IOException { final byte[] buffer = new byte[ bufferSize ]; + int count = 0; int n = 0; while( -1 != ( n = input.read( buffer ) ) ) { output.write( buffer, 0, n ); + count += n; } + return count; } /** * Copy chars from a Reader to a Writer. + * @param input the Reader to read from + * @param output the Writer to write to + * @return the number of characters copied + * @throws IOException In case of an I/O problem */ - public static void copy( final Reader input, final Writer output ) + public static int copy( final Reader input, final Writer output ) throws IOException { - copy( input, output, DEFAULT_BUFFER_SIZE ); + return copy( input, output, DEFAULT_BUFFER_SIZE ); } /** * Copy chars from a Reader to a Writer. + * @param input the Reader to read from + * @param output the Writer to write to * @param bufferSize Size of internal buffer to use. + * @return the number of characters copied + * @throws IOException In case of an I/O problem */ - public static void copy( final Reader input, final Writer output, final int bufferSize ) + public static int copy( final Reader input, final Writer output, final int bufferSize ) throws IOException { final char[] buffer = new char[ bufferSize ]; + int count = 0; int n = 0; while( -1 != ( n = input.read( buffer ) ) ) { output.write( buffer, 0, n ); + count += n; } + return count; } /////////////////////////////////////////////////////////////// @@ -313,6 +334,9 @@ * Copy and convert bytes from an InputStream to chars on a * Writer. * The platform's default encoding is used for the byte-to-char conversion. + * @param input the InputStream to read from + * @param output the Writer to write to + * @throws IOException In case of an I/O problem */ public static void copy( final InputStream input, final Writer output ) throws IOException @@ -324,7 +348,10 @@ * Copy and convert bytes from an InputStream to chars on a * Writer. * The platform's default encoding is used for the byte-to-char conversion. + * @param input the InputStream to read from + * @param output the Writer to write to * @param bufferSize Size of internal buffer to use. + * @throws IOException In case of an I/O problem */ public static void copy( final InputStream input, final Writer output, final int bufferSize ) throws IOException @@ -336,9 +363,12 @@ /** * Copy and convert bytes from an InputStream to chars on a * Writer, using the specified encoding. + * @param input the InputStream to read from + * @param output the Writer to write to * @param encoding The name of a supported character encoding. See the * IANA * Charset Registry for a list of valid encoding types. + * @throws IOException In case of an I/O problem */ public static void copy( final InputStream input, final Writer output, final String encoding ) throws IOException @@ -350,10 +380,13 @@ /** * Copy and convert bytes from an InputStream to chars on a * Writer, using the specified encoding. + * @param input the InputStream to read from + * @param output the Writer to write to * @param encoding The name of a supported character encoding. See the * IANA * Charset Registry for a list of valid encoding types. * @param bufferSize Size of internal buffer to use. + * @throws IOException In case of an I/O problem */ public static void copy( final InputStream input, final Writer output, @@ -372,6 +405,9 @@ /** * Get the contents of an InputStream as a String. * The platform's default encoding is used for the byte-to-char conversion. + * @param input the InputStream to read from + * @return the requested String + * @throws IOException In case of an I/O problem */ public static String toString( final InputStream input ) throws IOException @@ -382,7 +418,10 @@ /** * Get the contents of an InputStream as a String. * The platform's default encoding is used for the byte-to-char conversion. + * @param input the InputStream to read from * @param bufferSize Size of internal buffer to use. + * @return the requested String + * @throws IOException In case of an I/O problem */ public static String toString( final InputStream input, final int bufferSize ) throws IOException @@ -394,9 +433,12 @@ /** * Get the contents of an InputStream as a String. + * @param input the InputStream to read from * @param encoding The name of a supported character encoding. See the * IANA * Charset Registry for a list of valid encoding types. + * @return the requested String + * @throws IOException In case of an I/O problem */ public static String toString( final InputStream input, final String encoding ) throws IOException @@ -406,10 +448,13 @@ /** * Get the contents of an InputStream as a String. + * @param input the InputStream to read from * @param encoding The name of a supported character encoding. See the * IANA * Charset Registry for a list of valid encoding types. * @param bufferSize Size of internal buffer to use. + * @return the requested String + * @throws IOException In case of an I/O problem */ public static String toString( final InputStream input, final String encoding, @@ -426,6 +471,9 @@ /** * Get the contents of an InputStream as a byte[]. + * @param input the InputStream to read from + * @return the requested byte array + * @throws IOException In case of an I/O problem */ public static byte[] toByteArray( final InputStream input ) throws IOException @@ -435,7 +483,10 @@ /** * Get the contents of an InputStream as a byte[]. + * @param input the InputStream to read from * @param bufferSize Size of internal buffer to use. + * @return the requested byte array + * @throws IOException In case of an I/O problem */ public static byte[] toByteArray( final InputStream input, final int bufferSize ) throws IOException @@ -456,6 +507,9 @@ /** * Serialize chars from a Reader to bytes on an OutputStream, and * flush the OutputStream. + * @param input the Reader to read from + * @param output the OutputStream to write to + * @throws IOException In case of an I/O problem */ public static void copy( final Reader input, final OutputStream output ) throws IOException @@ -466,7 +520,10 @@ /** * Serialize chars from a Reader to bytes on an OutputStream, and * flush the OutputStream. + * @param input the Reader to read from + * @param output the OutputStream to write to * @param bufferSize Size of internal buffer to use. + * @throws IOException In case of an I/O problem */ public static void copy( final Reader input, final OutputStream output, final int bufferSize ) throws IOException @@ -482,6 +539,9 @@ // Reader -> String /** * Get the contents of a Reader as a String. + * @param input the Reader to read from + * @return the requested String + * @throws IOException In case of an I/O problem */ public static String toString( final Reader input ) throws IOException @@ -491,7 +551,10 @@ /** * Get the contents of a Reader as a String. + * @param input the Reader to read from * @param bufferSize Size of internal buffer to use. + * @return the requested String + * @throws IOException In case of an I/O problem */ public static String toString( final Reader input, final int bufferSize ) throws IOException @@ -506,6 +569,9 @@ // Reader -> byte[] /** * Get the contents of a Reader as a byte[]. + * @param input the Reader to read from + * @return the requested byte array + * @throws IOException In case of an I/O problem */ public static byte[] toByteArray( final Reader input ) throws IOException @@ -515,7 +581,10 @@ /** * Get the contents of a Reader as a byte[]. + * @param input the Reader to read from * @param bufferSize Size of internal buffer to use. + * @return the requested byte array + * @throws IOException In case of an I/O problem */ public static byte[] toByteArray( final Reader input, final int bufferSize ) throws IOException @@ -538,6 +607,9 @@ /** * Serialize chars from a String to bytes on an OutputStream, and * flush the OutputStream. + * @param input the String to read from + * @param output the OutputStream to write to + * @throws IOException In case of an I/O problem */ public static void copy( final String input, final OutputStream output ) throws IOException @@ -548,7 +620,10 @@ /** * Serialize chars from a String to bytes on an OutputStream, and * flush the OutputStream. + * @param input the String to read from + * @param output the OutputStream to write to * @param bufferSize Size of internal buffer to use. + * @throws IOException In case of an I/O problem */ public static void copy( final String input, final OutputStream output, final int bufferSize ) throws IOException @@ -568,6 +643,9 @@ /** * Copy chars from a String to a Writer. + * @param input the String to read from + * @param output the Writer to write to + * @throws IOException In case of an I/O problem */ public static void copy( final String input, final Writer output ) throws IOException @@ -585,6 +663,7 @@ * after the copy. * @deprecated Buffering streams is actively harmful! See the class description as to why. Use * {@link #copy(InputStream, OutputStream)} instead. + * @throws IOException In case of an I/O problem */ public static void bufferedCopy( final InputStream input, final OutputStream output ) throws IOException @@ -600,6 +679,9 @@ // String -> byte[] /** * Get the contents of a String as a byte[]. + * @param input the String to convert + * @return the requested byte array + * @throws IOException In case of an I/O problem */ public static byte[] toByteArray( final String input ) throws IOException @@ -609,7 +691,10 @@ /** * Get the contents of a String as a byte[]. + * @param input the String to convert * @param bufferSize Size of internal buffer to use. + * @return the requested byte array + * @throws IOException In case of an I/O problem */ public static byte[] toByteArray( final String input, final int bufferSize ) throws IOException @@ -634,6 +719,9 @@ * Copy and convert bytes from a byte[] to chars on a * Writer. * The platform's default encoding is used for the byte-to-char conversion. + * @param input the byte array to read from + * @param output the Writer to write to + * @throws IOException In case of an I/O problem */ public static void copy( final byte[] input, final Writer output ) throws IOException @@ -645,7 +733,10 @@ * Copy and convert bytes from a byte[] to chars on a * Writer. * The platform's default encoding is used for the byte-to-char conversion. + * @param input the byte array to read from + * @param output the Writer to write to * @param bufferSize Size of internal buffer to use. + * @throws IOException In case of an I/O problem */ public static void copy( final byte[] input, final Writer output, final int bufferSize ) throws IOException @@ -657,9 +748,12 @@ /** * Copy and convert bytes from a byte[] to chars on a * Writer, using the specified encoding. + * @param input the byte array to read from + * @param output the Writer to write to * @param encoding The name of a supported character encoding. See the * IANA * Charset Registry for a list of valid encoding types. + * @throws IOException In case of an I/O problem */ public static void copy( final byte[] input, final Writer output, final String encoding ) throws IOException @@ -671,10 +765,13 @@ /** * Copy and convert bytes from a byte[] to chars on a * Writer, using the specified encoding. + * @param input the byte array to read from + * @param output the Writer to write to * @param encoding The name of a supported character encoding. See the * IANA * Charset Registry for a list of valid encoding types. * @param bufferSize Size of internal buffer to use. + * @throws IOException In case of an I/O problem */ public static void copy( final byte[] input, final Writer output, @@ -693,6 +790,9 @@ /** * Get the contents of a byte[] as a String. * The platform's default encoding is used for the byte-to-char conversion. + * @param input the byte array to read from + * @return the requested String + * @throws IOException In case of an I/O problem */ public static String toString( final byte[] input ) throws IOException @@ -703,7 +803,10 @@ /** * Get the contents of a byte[] as a String. * The platform's default encoding is used for the byte-to-char conversion. + * @param input the byte array to read from * @param bufferSize Size of internal buffer to use. + * @return the requested String + * @throws IOException In case of an I/O problem */ public static String toString( final byte[] input, final int bufferSize ) throws IOException @@ -715,9 +818,12 @@ /** * Get the contents of a byte[] as a String. + * @param input the byte array to read from * @param encoding The name of a supported character encoding. See the * IANA * Charset Registry for a list of valid encoding types. + * @return the requested String + * @throws IOException In case of an I/O problem */ public static String toString( final byte[] input, final String encoding ) throws IOException @@ -727,10 +833,13 @@ /** * Get the contents of a byte[] as a String. + * @param input the byte array to read from * @param encoding The name of a supported character encoding. See the * IANA * Charset Registry for a list of valid encoding types. * @param bufferSize Size of internal buffer to use. + * @return the requested String + * @throws IOException In case of an I/O problem */ public static String toString( final byte[] input, final String encoding, @@ -748,6 +857,9 @@ /** * Copy bytes from a byte[] to an OutputStream. + * @param input the byte array to read from + * @param output the OutputStream to write to + * @throws IOException In case of an I/O problem */ public static void copy( final byte[] input, final OutputStream output ) throws IOException @@ -757,7 +869,10 @@ /** * Copy bytes from a byte[] to an OutputStream. + * @param input the byte array to read from + * @param output the OutputStream to write to * @param bufferSize Size of internal buffer to use. + * @throws IOException In case of an I/O problem */ public static void copy( final byte[] input, final OutputStream output, @@ -773,6 +888,7 @@ * @param input1 the first stream * @param input2 the second stream * @return true if the content of the streams are equal or they both don't exist, false otherwise + * @throws IOException In case of an I/O problem */ public static boolean contentEquals( final InputStream input1, final InputStream input2 ) --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org