scolebourne    2004/07/31 04:26:39

  Modified:    io/src/java/org/apache/commons/io IOUtils.java
  Log:
  Deprecate methods not actually doing IO, Javadoc buffer behaviour
  
  Revision  Changes    Path
  1.18      +34 -33    jakarta-commons/io/src/java/org/apache/commons/io/IOUtils.java
  
  Index: IOUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/io/src/java/org/apache/commons/io/IOUtils.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- IOUtils.java      31 Jul 2004 09:52:09 -0000      1.17
  +++ IOUtils.java      31 Jul 2004 11:26:39 -0000      1.18
  @@ -21,7 +21,6 @@
   import java.io.OutputStream;
   import java.io.Reader;
   import java.io.StringWriter;
  -import java.io.UnsupportedEncodingException;
   import java.io.Writer;
   
   import org.apache.commons.io.output.ByteArrayOutputStream;
  @@ -130,6 +129,9 @@
       //-----------------------------------------------------------------------
       /**
        * Get the contents of an <code>InputStream</code> as a <code>byte[]</code>.
  +     * <p>
  +     * This method buffers the input internally, so there is no need to use a
  +     * <code>BufferedInputStream</code>.
        * 
        * @param input  the <code>InputStream</code> to read from
        * @return the requested byte array
  @@ -145,6 +147,9 @@
       /**
        * Get the contents of a <code>Reader</code> as a <code>byte[]</code>
        * using the default character encoding of the platform.
  +     * <p>
  +     * This method buffers the input internally, so there is no need to use a
  +     * <code>BufferedReader</code>.
        * 
        * @param input  the <code>Reader</code> to read from
        * @return the requested byte array
  @@ -163,12 +168,16 @@
        * <p>
        * Character encoding names can be found at
        * <a href="http://www.iana.org/assignments/character-sets";>IANA</a>.
  +     * <p>
  +     * This method buffers the input internally, so there is no need to use a
  +     * <code>BufferedReader</code>.
        * 
        * @param input  the <code>Reader</code> to read from
        * @param encoding  the encoding to use, null means platform default
        * @return the requested byte array
        * @throws NullPointerException if the input is null
        * @throws IOException if an I/O error occurs
  +     * @since 1.1
        */
       public static byte[] toByteArray(Reader input, String encoding) throws 
IOException {
           ByteArrayOutputStream output = new ByteArrayOutputStream();
  @@ -185,39 +194,21 @@
        * @param input  the <code>String</code> to convert
        * @return the requested byte array
        * @throws NullPointerException if the input is null
  -     * @throws IOException if an I/O error occurs
  -     *  (never happens, but can't remove due to backwards compatibility)
  +     * @throws IOException if an I/O error occurs (never occurs)
  +     * @deprecated Use [EMAIL PROTECTED] String#getBytes()}
        */
       public static byte[] toByteArray(String input) throws IOException {
           return input.getBytes();
       }
   
  -    /**
  -     * Get the contents of a <code>String</code> as a <code>byte[]</code>
  -     * using the specified character encoding.
  -     * <p>
  -     * This is based on [EMAIL PROTECTED] String#getBytes(String)}.
  -     * Character encoding names can be found at
  -     * <a href="http://www.iana.org/assignments/character-sets";>IANA</a>.
  -     * 
  -     * @param input  the <code>String</code> to convert
  -     * @param encoding  the encoding to use, null means platform default
  -     * @return the requested byte array
  -     * @throws NullPointerException if the input is null
  -     * @throws UnsupportedEncodingException if the named charset is not supported
  -     */
  -    public static byte[] toByteArray(String input, String encoding) throws 
UnsupportedEncodingException {
  -        if (encoding == null) {
  -            return input.getBytes();
  -        }
  -        return input.getBytes(encoding);
  -    }
  -
       // toString
       //-----------------------------------------------------------------------
       /**
        * Get the contents of an <code>InputStream</code> as a String
        * using the default character encoding of the platform.
  +     * <p>
  +     * This method buffers the input internally, so there is no need to use a
  +     * <code>BufferedInputStream</code>.
        * 
        * @param input  the <code>InputStream</code> to read from
        * @return the requested String
  @@ -236,6 +227,9 @@
        * <p>
        * Character encoding names can be found at
        * <a href="http://www.iana.org/assignments/character-sets";>IANA</a>.
  +     * <p>
  +     * This method buffers the input internally, so there is no need to use a
  +     * <code>BufferedInputStream</code>.
        * 
        * @param input  the <code>InputStream</code> to read from
        * @param encoding  the encoding to use, null means platform default
  @@ -251,6 +245,9 @@
   
       /**
        * Get the contents of a <code>Reader</code> as a String.
  +     * <p>
  +     * This method buffers the input internally, so there is no need to use a
  +     * <code>BufferedReader</code>.
        * 
        * @param input  the <code>Reader</code> to read from
        * @return the requested String
  @@ -270,12 +267,11 @@
        * @param input the byte array to read from
        * @return the requested String
        * @throws NullPointerException if the input is null
  -     * @throws IOException if an I/O error occurs
  +     * @throws IOException if an I/O error occurs (never occurs)
  +     * @deprecated Use [EMAIL PROTECTED] String#String(byte[])}
        */
       public static String toString(byte[] input) throws IOException {
  -        StringWriter sw = new StringWriter();
  -        CopyUtils.copy(input, sw);
  -        return sw.toString();
  +        return new String(input);
       }
   
       /**
  @@ -289,17 +285,22 @@
        * @param encoding  the encoding to use, null means platform default
        * @return the requested String
        * @throws NullPointerException if the input is null
  -     * @throws IOException if an I/O error occurs
  +     * @throws IOException if an I/O error occurs (never occurs)
  +     * @deprecated Use [EMAIL PROTECTED] String#String(byte[],String)}
        */
       public static String toString(byte[] input, String encoding) throws IOException 
{
  -        StringWriter sw = new StringWriter();
  -        CopyUtils.copy(input, sw, encoding);
  -        return sw.toString();
  +        if (encoding == null) {
  +            return new String(input);
  +        } else {
  +            return new String(input, encoding);
  +        }
       }
   
       //-----------------------------------------------------------------------
       /**
        * Compare the contents of two Streams to determine if they are equal or not.
  +     * <p>
  +     * This method buffers the input internally using 
<code>BufferedInputStream</code>.
        *
        * @param input1  the first stream
        * @param input2  the second stream
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to