You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by je...@apache.org on 2003/07/25 09:51:26 UTC

cvs commit: jakarta-commons-sandbox/io/src/java/org/apache/commons/io/input SwappedDataInputStream.java

jeremias    2003/07/25 00:51:26

  Modified:    io/src/java/org/apache/commons/io IOUtil.java FileUtils.java
                        EndianUtil.java
               io/src/test/org/apache/commons/io IOUtilTestCase.java
                        IOTestSuite.java
               io/src/java/org/apache/commons/io/input
                        SwappedDataInputStream.java
  Added:       io/src/java/org/apache/commons/io IOUtils.java
                        EndianUtils.java
  Log:
  IOUtil to IOUtils and EndianUtil to EndianUtils.
  Fix references so dependant classes reference *Utils
  Submitted by: Matthew Hawthorne <mh...@alumni.pitt.edu>
  
  Deprecate IOUtil and EndianUtil.
  Fix some of the license headers (more to do)
  
  Revision  Changes    Path
  1.4       +9 -2      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IOUtil.java	3 Jul 2003 14:43:02 -0000	1.3
  +++ IOUtil.java	25 Jul 2003 07:51:24 -0000	1.4
  @@ -51,6 +51,12 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  +
  +/* ====================================================================
  + *  TODO: THIS CLASS WILL BE DELETED BEFORE RELEASE 1.0!!!
  + * ==================================================================== 
  + */
  +
   package org.apache.commons.io;
   
   import java.io.BufferedInputStream;
  @@ -115,7 +121,8 @@
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:jefft@apache.org">Jeff Turner</a>
    * @version CVS $Revision$ $Date$
  - * @since 4.0
  + * @deprecated Use IOUtils instead. This class will be deleted prior to release
  + *      1.0.
    */
   
   /*
  
  
  
  1.11      +24 -29    jakarta-commons-sandbox/io/src/java/org/apache/commons/io/FileUtils.java
  
  Index: FileUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/FileUtils.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- FileUtils.java	28 Jul 2002 20:48:46 -0000	1.10
  +++ FileUtils.java	25 Jul 2003 07:51:24 -0000	1.11
  @@ -1,9 +1,7 @@
  -package org.apache.commons.io;
  -
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -18,21 +16,21 @@
    *    the documentation and/or other materials provided with the
    *    distribution.
    *
  - * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:
  + * 3. The end-user documentation included with the redistribution, if
  + *    any, must include the following acknowlegement:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowledgment may appear in the software itself,
  - *    if and wherever such third-party acknowledgments normally appear.
  + *    Alternately, this acknowlegement may appear in the software itself,
  + *    if and wherever such third-party acknowlegements normally appear.
    *
  - * 4. The names "Apache" and "Apache Software Foundation" and
  - *    "Apache Turbine" must not be used to endorse or promote products
  - *    derived from this software without prior written permission. For
  - *    written permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - *    "Apache Turbine", nor may "Apache" appear in their name, without
  - *    prior written permission of the Apache Software Foundation.
  + * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  + *    Foundation" must not be used to endorse or promote products derived
  + *    from this software without prior written permission. For written
  + *    permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache"
  + *    nor may "Apache" appear in their names without prior written
  + *    permission of the Apache Software Foundation.
    *
    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  @@ -52,20 +50,17 @@
    * individuals on behalf of the Apache Software Foundation.  For more
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
  - *
    */
  -
  +package org.apache.commons.io;
   
   import java.io.File;
   import java.io.FileInputStream;
  -import java.io.FileNotFoundException;
   import java.io.FileOutputStream;
   import java.io.InputStream;
   import java.io.IOException;
   import java.net.URL;
   import java.util.Vector;
   
  -
   /*
    * This class provides basic facilities for manipulating files and file paths.
    *
  @@ -472,13 +467,13 @@
           {
               input1 = new FileInputStream( file1 );
               input2 = new FileInputStream( file2 );
  -            return IOUtil.contentEquals( input1, input2 );
  +            return IOUtils.contentEquals( input1, input2 );
   
           }
           finally
           {
  -            IOUtil.shutdownStream( input1 );
  -            IOUtil.shutdownStream( input2 );
  +            IOUtils.shutdownStream( input1 );
  +            IOUtils.shutdownStream( input2 );
           }
       }
   
  @@ -742,9 +737,9 @@
   
           final FileInputStream input = new FileInputStream( source );
           final FileOutputStream output = new FileOutputStream( destination );
  -        IOUtil.copy( input, output );
  -        IOUtil.shutdownStream( input );
  -        IOUtil.shutdownStream( output );
  +        IOUtils.copy( input, output );
  +        IOUtils.shutdownStream( input );
  +        IOUtils.shutdownStream( output );
   
           if( source.length() != destination.length() )
           {
  @@ -790,9 +785,9 @@
   
           final InputStream input = source.openStream();
           final FileOutputStream output = new FileOutputStream( destination );
  -        IOUtil.copy( input, output );
  -        IOUtil.shutdownStream( input );
  -        IOUtil.shutdownStream( output );
  +        IOUtils.copy( input, output );
  +        IOUtils.shutdownStream( input );
  +        IOUtils.shutdownStream( output );
       }
   
       /**
  
  
  
  1.2       +8 -2      jakarta-commons-sandbox/io/src/java/org/apache/commons/io/EndianUtil.java
  
  Index: EndianUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/EndianUtil.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EndianUtil.java	8 Jul 2002 22:14:46 -0000	1.1
  +++ EndianUtil.java	25 Jul 2003 07:51:26 -0000	1.2
  @@ -54,6 +54,11 @@
    * <http://www.apache.org/>.
    */
   
  +/* ====================================================================
  + *  TODO: THIS CLASS WILL BE DELETED BEFORE RELEASE 1.0!!!
  + * ==================================================================== 
  + */
  +
   import java.io.EOFException;
   import java.io.IOException;
   import java.io.InputStream;
  @@ -64,7 +69,8 @@
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @version CVS $Revision$ $Date$
  - * @since 4.0
  + * @deprecated Use EndianUtils instead. This class will be deleted prior to 
  + *      release 1.0.
    */
   public final class EndianUtil
   {
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/IOUtils.java
  
  Index: IOUtils.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.io;
  
  import java.io.BufferedInputStream;
  import java.io.BufferedOutputStream;
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.OutputStream;
  import java.io.OutputStreamWriter;
  import java.io.Reader;
  import java.io.StringReader;
  import java.io.StringWriter;
  import java.io.Writer;
  
  /**
   * General IO Stream manipulation.
   * <p>
   * This class provides static utility methods for input/output operations, particularly buffered
   * copying between sources (<code>InputStream</code>, <code>Reader</code>, <code>String</code> and
   * <code>byte[]</code>) and destinations (<code>OutputStream</code>, <code>Writer</code>,
   * <code>String</code> and <code>byte[]</code>).
   * </p>
   *
   * <p>Unless otherwise noted, these <code>copy</code> methods do <em>not</em> flush or close the
   * streams. Often, doing so would require making non-portable assumptions about the streams' origin
   * and further use. This means that both streams' <code>close()</code> methods must be called after
   * copying. if one omits this step, then the stream resources (sockets, file descriptors) are
   * released when the associated Stream is garbage-collected. It is not a good idea to rely on this
   * mechanism. For a good overview of the distinction between "memory management" and "resource
   * management", see <a href="http://www.unixreview.com/articles/1998/9804/9804ja/ja.htm">this
   * UnixReview article</a></p>
   *
   * <p>For each <code>copy</code> method, a variant is provided that allows the caller to specify the
   * buffer size (the default is 4k). As the buffer size can have a fairly large impact on speed, this
   * may be worth tweaking. Often "large buffer -&gt; faster" does not hold, even for large data
   * transfers.</p>
   *
   * <p>For byte-to-char methods, a <code>copy</code> variant allows the encoding to be selected
   * (otherwise the platform default is used).</p>
   *
   * <p>The <code>copy</code> methods use an internal buffer when copying. It is therefore advisable
   * <em>not</em> to deliberately wrap the stream arguments to the <code>copy</code> methods in
   * <code>Buffered*</code> streams. For example, don't do the
   * following:</p>
   *
   * <code>copy( new BufferedInputStream( in ), new BufferedOutputStream( out ) );</code>
   *
   * <p>The rationale is as follows:</p>
   *
   * <p>Imagine that an InputStream's read() is a very expensive operation, which would usually suggest
   * wrapping in a BufferedInputStream. The BufferedInputStream works by issuing infrequent
   * {@link java.io.InputStream#read(byte[] b, int off, int len)} requests on the underlying InputStream, to
   * fill an internal buffer, from which further <code>read</code> requests can inexpensively get
   * their data (until the buffer runs out).</p>
   * <p>However, the <code>copy</code> methods do the same thing, keeping an internal buffer,
   * populated by {@link InputStream#read(byte[] b, int off, int len)} requests. Having two buffers
   * (or three if the destination stream is also buffered) is pointless, and the unnecessary buffer
   * management hurts performance slightly (about 3%, according to some simple experiments).</p>
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @author <a href="mailto:jefft@apache.org">Jeff Turner</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/07/25 07:51:26 $
   * @since 4.0
   */
  
  /*
   * Behold, intrepid explorers; a map of this class:
   *
   *       Method      Input               Output          Dependency
   *       ------      -----               ------          -------
   * 1     copy        InputStream         OutputStream    (primitive)
   * 2     copy        Reader              Writer          (primitive)
   *
   * 3     copy        InputStream         Writer          2
   * 4     toString    InputStream         String          3
   * 5     toByteArray InputStream         byte[]          1
   *
   * 6     copy        Reader              OutputStream    2
   * 7     toString    Reader              String          2
   * 8     toByteArray Reader              byte[]          6
   *
   * 9     copy        String              OutputStream    2
   * 10    copy        String              Writer          (trivial)
   * 11    toByteArray String              byte[]          9
   *
   * 12    copy        byte[]              Writer          3
   * 13    toString    byte[]              String          12
   * 14    copy        byte[]              OutputStream    (trivial)
   *
   *
   * Note that only the first two methods shuffle bytes; the rest use these two, or (if possible) copy
   * using native Java copy methods. As there are method variants to specify buffer size and encoding,
   * each row may correspond to up to 4 methods.
   *
   */
  public final class IOUtils
  {
      private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
  
      /**
       * Private constructor to prevent instantiation.
       */
      private IOUtils()
      {
      }
  
      /**
       * Unconditionally close an <code>Reader</code>.
       * Equivalent to {@link Reader#close()}, except any exceptions will be ignored.
       *
       * @param input A (possibly null) Reader
       */
      public static void shutdownReader( final Reader input )
      {
          if( input == null )
          {
              return;
          }
  
          try
          {
              input.close();
          }
          catch( final IOException ioe )
          {
          }
      }
  
      /**
       * Unconditionally close an <code>Writer</code>.
       * Equivalent to {@link Writer#close()}, except any exceptions will be ignored.
       *
       * @param output A (possibly null) Writer
       */
      public static void shutdownWriter( final Writer output )
      {
          if( output == null )
          {
              return;
          }
  
          try
          {
              output.close();
          }
          catch( final IOException ioe )
          {
          }
      }
  
      /**
       * Unconditionally close an <code>OutputStream</code>.
       * Equivalent to {@link OutputStream#close()}, except any exceptions will be ignored.
       * @param output A (possibly null) OutputStream
       */
      public static void shutdownStream( final OutputStream output )
      {
          if( output == null )
          {
              return;
          }
  
          try
          {
              output.close();
          }
          catch( final IOException ioe )
          {
          }
      }
  
      /**
       * Unconditionally close an <code>InputStream</code>.
       * Equivalent to {@link InputStream#close()}, except any exceptions will be ignored.
       * @param input A (possibly null) InputStream
       */
      public static void shutdownStream( final InputStream input )
      {
          if( input == null )
          {
              return;
          }
  
          try
          {
              input.close();
          }
          catch( final IOException ioe )
          {
          }
      }
  
      ///////////////////////////////////////////////////////////////
      // Core copy methods
      ///////////////////////////////////////////////////////////////
  
      /**
       * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
       * @param input the <code>InputStream</code> to read from
       * @param output the <code>OutputStream</code> to write to
       * @return the number of bytes copied
       * @throws IOException In case of an I/O problem
       */
      public static int copy( final InputStream input, final OutputStream output )
          throws IOException
      {
          return copy( input, output, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
       * @param input the <code>InputStream</code> to read from
       * @param output the <code>OutputStream</code> 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 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 <code>Reader</code> to a <code>Writer</code>.
       * @param input the <code>Reader</code> to read from
       * @param output the <code>Writer</code> to write to
       * @return the number of characters copied
       * @throws IOException In case of an I/O problem
       */
      public static int copy( final Reader input, final Writer output )
          throws IOException
      {
          return copy( input, output, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Copy chars from a <code>Reader</code> to a <code>Writer</code>.
       * @param input the <code>Reader</code> to read from
       * @param output the <code>Writer</code> 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 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;
      }
  
      ///////////////////////////////////////////////////////////////
      // Derived copy methods
      // InputStream -> *
      ///////////////////////////////////////////////////////////////
  
  
      ///////////////////////////////////////////////////////////////
      // InputStream -> Writer
  
      /**
       * Copy and convert bytes from an <code>InputStream</code> to chars on a
       * <code>Writer</code>.
       * The platform's default encoding is used for the byte-to-char conversion.
       * @param input the <code>InputStream</code> to read from
       * @param output the <code>Writer</code> to write to
       * @throws IOException In case of an I/O problem
       */
      public static void copy( final InputStream input, final Writer output )
          throws IOException
      {
          copy( input, output, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Copy and convert bytes from an <code>InputStream</code> to chars on a
       * <code>Writer</code>.
       * The platform's default encoding is used for the byte-to-char conversion.
       * @param input the <code>InputStream</code> to read from
       * @param output the <code>Writer</code> 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
      {
          final InputStreamReader in = new InputStreamReader( input );
          copy( in, output, bufferSize );
      }
  
      /**
       * Copy and convert bytes from an <code>InputStream</code> to chars on a
       * <code>Writer</code>, using the specified encoding.
       * @param input the <code>InputStream</code> to read from
       * @param output the <code>Writer</code> to write to
       * @param encoding The name of a supported character encoding. See the
       * <a href="http://www.iana.org/assignments/character-sets">IANA
       * Charset Registry</a> 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
      {
          final InputStreamReader in = new InputStreamReader( input, encoding );
          copy( in, output );
      }
  
      /**
       * Copy and convert bytes from an <code>InputStream</code> to chars on a
       * <code>Writer</code>, using the specified encoding.
       * @param input the <code>InputStream</code> to read from
       * @param output the <code>Writer</code> to write to
       * @param encoding The name of a supported character encoding. See the
       *        <a href="http://www.iana.org/assignments/character-sets">IANA
       *        Charset Registry</a> 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,
                               final String encoding,
                               final int bufferSize )
          throws IOException
      {
          final InputStreamReader in = new InputStreamReader( input, encoding );
          copy( in, output, bufferSize );
      }
  
  
      ///////////////////////////////////////////////////////////////
      // InputStream -> String
  
      /**
       * Get the contents of an <code>InputStream</code> as a String.
       * The platform's default encoding is used for the byte-to-char conversion.
       * @param input the <code>InputStream</code> to read from
       * @return the requested <code>String</code>
       * @throws IOException In case of an I/O problem
       */
      public static String toString( final InputStream input )
          throws IOException
      {
          return toString( input, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Get the contents of an <code>InputStream</code> as a String.
       * The platform's default encoding is used for the byte-to-char conversion.
       * @param input the <code>InputStream</code> to read from
       * @param bufferSize Size of internal buffer to use.
       * @return the requested <code>String</code>
       * @throws IOException In case of an I/O problem
       */
      public static String toString( final InputStream input, final int bufferSize )
          throws IOException
      {
          final StringWriter sw = new StringWriter();
          copy( input, sw, bufferSize );
          return sw.toString();
      }
  
      /**
       * Get the contents of an <code>InputStream</code> as a String.
       * @param input the <code>InputStream</code> to read from
       * @param encoding The name of a supported character encoding. See the
       *    <a href="http://www.iana.org/assignments/character-sets">IANA
       *    Charset Registry</a> for a list of valid encoding types.
       * @return the requested <code>String</code>
       * @throws IOException In case of an I/O problem
       */
      public static String toString( final InputStream input, final String encoding )
          throws IOException
      {
          return toString( input, encoding, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Get the contents of an <code>InputStream</code> as a String.
       * @param input the <code>InputStream</code> to read from
       * @param encoding The name of a supported character encoding. See the
       *   <a href="http://www.iana.org/assignments/character-sets">IANA
       *   Charset Registry</a> for a list of valid encoding types.
       * @param bufferSize Size of internal buffer to use.
       * @return the requested <code>String</code>
       * @throws IOException In case of an I/O problem
       */
      public static String toString( final InputStream input,
                                     final String encoding,
                                     final int bufferSize )
          throws IOException
      {
          final StringWriter sw = new StringWriter();
          copy( input, sw, encoding, bufferSize );
          return sw.toString();
      }
  
      ///////////////////////////////////////////////////////////////
      // InputStream -> byte[]
  
      /**
       * Get the contents of an <code>InputStream</code> as a <code>byte[]</code>.
       * @param input the <code>InputStream</code> 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
      {
          return toByteArray( input, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Get the contents of an <code>InputStream</code> as a <code>byte[]</code>.
       * @param input the <code>InputStream</code> 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
      {
          final ByteArrayOutputStream output = new ByteArrayOutputStream();
          copy( input, output, bufferSize );
          return output.toByteArray();
      }
  
  
      ///////////////////////////////////////////////////////////////
      // Derived copy methods
      // Reader -> *
      ///////////////////////////////////////////////////////////////
  
      ///////////////////////////////////////////////////////////////
      // Reader -> OutputStream
      /**
       * Serialize chars from a <code>Reader</code> to bytes on an <code>OutputStream</code>, and
       * flush the <code>OutputStream</code>.
       * @param input the <code>Reader</code> to read from
       * @param output the <code>OutputStream</code> to write to
       * @throws IOException In case of an I/O problem
       */
      public static void copy( final Reader input, final OutputStream output )
          throws IOException
      {
          copy( input, output, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Serialize chars from a <code>Reader</code> to bytes on an <code>OutputStream</code>, and
       * flush the <code>OutputStream</code>.
       * @param input the <code>Reader</code> to read from
       * @param output the <code>OutputStream</code> 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
      {
          final OutputStreamWriter out = new OutputStreamWriter( output );
          copy( input, out, bufferSize );
          // NOTE: Unless anyone is planning on rewriting OutputStreamWriter, we have to flush
          // here.
          out.flush();
      }
  
      ///////////////////////////////////////////////////////////////
      // Reader -> String
      /**
       * Get the contents of a <code>Reader</code> as a String.
       * @param input the <code>Reader</code> to read from
       * @return the requested <code>String</code>
       * @throws IOException In case of an I/O problem
       */
      public static String toString( final Reader input )
          throws IOException
      {
          return toString( input, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Get the contents of a <code>Reader</code> as a String.
       * @param input the <code>Reader</code> to read from
       * @param bufferSize Size of internal buffer to use.
       * @return the requested <code>String</code>
       * @throws IOException In case of an I/O problem
       */
      public static String toString( final Reader input, final int bufferSize )
          throws IOException
      {
          final StringWriter sw = new StringWriter();
          copy( input, sw, bufferSize );
          return sw.toString();
      }
  
  
      ///////////////////////////////////////////////////////////////
      // Reader -> byte[]
      /**
       * Get the contents of a <code>Reader</code> as a <code>byte[]</code>.
       * @param input the <code>Reader</code> 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
      {
          return toByteArray( input, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Get the contents of a <code>Reader</code> as a <code>byte[]</code>.
       * @param input the <code>Reader</code> 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
      {
          ByteArrayOutputStream output = new ByteArrayOutputStream();
          copy( input, output, bufferSize );
          return output.toByteArray();
      }
  
  
      ///////////////////////////////////////////////////////////////
      // Derived copy methods
      // String -> *
      ///////////////////////////////////////////////////////////////
  
  
      ///////////////////////////////////////////////////////////////
      // String -> OutputStream
  
      /**
       * Serialize chars from a <code>String</code> to bytes on an <code>OutputStream</code>, and
       * flush the <code>OutputStream</code>.
       * @param input the <code>String</code> to read from
       * @param output the <code>OutputStream</code> to write to
       * @throws IOException In case of an I/O problem
       */
      public static void copy( final String input, final OutputStream output )
          throws IOException
      {
          copy( input, output, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Serialize chars from a <code>String</code> to bytes on an <code>OutputStream</code>, and
       * flush the <code>OutputStream</code>.
       * @param input the <code>String</code> to read from
       * @param output the <code>OutputStream</code> 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
      {
          final StringReader in = new StringReader( input );
          final OutputStreamWriter out = new OutputStreamWriter( output );
          copy( in, out, bufferSize );
          // NOTE: Unless anyone is planning on rewriting OutputStreamWriter, we have to flush
          // here.
          out.flush();
      }
  
  
  
      ///////////////////////////////////////////////////////////////
      // String -> Writer
  
      /**
       * Copy chars from a <code>String</code> to a <code>Writer</code>.
       * @param input the <code>String</code> to read from
       * @param output the <code>Writer</code> to write to
       * @throws IOException In case of an I/O problem
       */
      public static void copy( final String input, final Writer output )
          throws IOException
      {
          output.write( input );
      }
  
      /**
       * Copy bytes from an <code>InputStream</code> to an
       * <code>OutputStream</code>, with buffering.
       * This is equivalent to passing a
       * {@link java.io.BufferedInputStream} and
       * {@link java.io.BufferedOutputStream} to {@link #copy(InputStream, OutputStream)},
       * and flushing the output stream afterwards. The streams are not closed
       * 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
      {
          final BufferedInputStream in = new BufferedInputStream( input );
          final BufferedOutputStream out = new BufferedOutputStream( output );
          copy( in, out );
          out.flush();
      }
  
  
      ///////////////////////////////////////////////////////////////
      // String -> byte[]
      /**
       * Get the contents of a <code>String</code> as a <code>byte[]</code>.
       * @param input the <code>String</code> 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
      {
          return toByteArray( input, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Get the contents of a <code>String</code> as a <code>byte[]</code>.
       * @param input the <code>String</code> 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
      {
          ByteArrayOutputStream output = new ByteArrayOutputStream();
          copy( input, output, bufferSize );
          return output.toByteArray();
      }
  
  
  
      ///////////////////////////////////////////////////////////////
      // Derived copy methods
      // byte[] -> *
      ///////////////////////////////////////////////////////////////
  
  
      ///////////////////////////////////////////////////////////////
      // byte[] -> Writer
  
      /**
       * Copy and convert bytes from a <code>byte[]</code> to chars on a
       * <code>Writer</code>.
       * The platform's default encoding is used for the byte-to-char conversion.
       * @param input the byte array to read from
       * @param output the <code>Writer</code> to write to
       * @throws IOException In case of an I/O problem
       */
      public static void copy( final byte[] input, final Writer output )
          throws IOException
      {
          copy( input, output, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Copy and convert bytes from a <code>byte[]</code> to chars on a
       * <code>Writer</code>.
       * The platform's default encoding is used for the byte-to-char conversion.
       * @param input the byte array to read from
       * @param output the <code>Writer</code> 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
      {
          final ByteArrayInputStream in = new ByteArrayInputStream( input );
          copy( in, output, bufferSize );
      }
  
      /**
       * Copy and convert bytes from a <code>byte[]</code> to chars on a
       * <code>Writer</code>, using the specified encoding.
       * @param input the byte array to read from
       * @param output the <code>Writer</code> to write to
       * @param encoding The name of a supported character encoding. See the
       * <a href="http://www.iana.org/assignments/character-sets">IANA
       * Charset Registry</a> 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
      {
          final ByteArrayInputStream in = new ByteArrayInputStream( input );
          copy( in, output, encoding );
      }
  
      /**
       * Copy and convert bytes from a <code>byte[]</code> to chars on a
       * <code>Writer</code>, using the specified encoding.
       * @param input the byte array to read from
       * @param output the <code>Writer</code> to write to
       * @param encoding The name of a supported character encoding. See the
       *        <a href="http://www.iana.org/assignments/character-sets">IANA
       *        Charset Registry</a> 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,
                               final String encoding,
                               final int bufferSize )
          throws IOException
      {
          final ByteArrayInputStream in = new ByteArrayInputStream( input );
          copy( in, output, encoding, bufferSize );
      }
  
  
      ///////////////////////////////////////////////////////////////
      // byte[] -> String
  
      /**
       * Get the contents of a <code>byte[]</code> 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 <code>String</code>
       * @throws IOException In case of an I/O problem
       */
      public static String toString( final byte[] input )
          throws IOException
      {
          return toString( input, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Get the contents of a <code>byte[]</code> 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 <code>String</code>
       * @throws IOException In case of an I/O problem
       */
      public static String toString( final byte[] input, final int bufferSize )
          throws IOException
      {
          final StringWriter sw = new StringWriter();
          copy( input, sw, bufferSize );
          return sw.toString();
      }
  
      /**
       * Get the contents of a <code>byte[]</code> as a String.
       * @param input the byte array to read from
       * @param encoding The name of a supported character encoding. See the
       *    <a href="http://www.iana.org/assignments/character-sets">IANA
       *    Charset Registry</a> for a list of valid encoding types.
       * @return the requested <code>String</code>
       * @throws IOException In case of an I/O problem
       */
      public static String toString( final byte[] input, final String encoding )
          throws IOException
      {
          return toString( input, encoding, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Get the contents of a <code>byte[]</code> as a String.
       * @param input the byte array to read from
       * @param encoding The name of a supported character encoding. See the
       *   <a href="http://www.iana.org/assignments/character-sets">IANA
       *   Charset Registry</a> for a list of valid encoding types.
       * @param bufferSize Size of internal buffer to use.
       * @return the requested <code>String</code>
       * @throws IOException In case of an I/O problem
       */
      public static String toString( final byte[] input,
                                     final String encoding,
                                     final int bufferSize )
          throws IOException
      {
          final StringWriter sw = new StringWriter();
          copy( input, sw, encoding, bufferSize );
          return sw.toString();
      }
  
  
      ///////////////////////////////////////////////////////////////
      // byte[] -> OutputStream
  
      /**
       * Copy bytes from a <code>byte[]</code> to an <code>OutputStream</code>.
       * @param input the byte array to read from
       * @param output the <code>OutputStream</code> to write to
       * @throws IOException In case of an I/O problem
       */
      public static void copy( final byte[] input, final OutputStream output )
          throws IOException
      {
          copy( input, output, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Copy bytes from a <code>byte[]</code> to an <code>OutputStream</code>.
       * @param input the byte array to read from
       * @param output the <code>OutputStream</code> 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,
                               final int bufferSize )
          throws IOException
      {
          output.write( input );
      }
  
      /**
       * Compare the contents of two Streams to determine if they are equal or not.
       *
       * @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 )
          throws IOException
      {
          final InputStream bufferedInput1 = new BufferedInputStream( input1 );
          final InputStream bufferedInput2 = new BufferedInputStream( input2 );
  
          int ch = bufferedInput1.read();
          while( -1 != ch )
          {
              final int ch2 = bufferedInput2.read();
              if( ch != ch2 )
              {
                  return false;
              }
              ch = bufferedInput1.read();
          }
  
          final int ch2 = bufferedInput2.read();
          if( -1 != ch2 )
          {
              return false;
          }
          else
          {
              return true;
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/EndianUtils.java
  
  Index: EndianUtils.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.io;
  
  import java.io.EOFException;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  
  /**
   * Utility code for dealing with different endian systems.
   * <br>
   * Origin of code: Apache Avalon (Excalibur)
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/07/25 07:51:26 $
   */
  public final class EndianUtils
  {
      public static final int SIZEOF_BYTE = 1;
      public static final int SIZEOF_SHORT = 2;
      public static final int SIZEOF_INT = 4;
      public static final int SIZEOF_FLOAT = 4;
      public static final int SIZEOF_LONG = 8;
  
      /**
       * Private constructor to avoid instantiation.
       */
      private EndianUtils() {
      }
  
      public static short swapShort( final short value )
      {
          return (short)( ( ( ( value >> 0 ) & 0xff ) << 8 ) +
              ( ( ( value >> 8 ) & 0xff ) << 0 ) );
      }
  
      public static int swapInteger( final int value )
      {
          return
              ( ( ( value >> 0 ) & 0xff ) << 24 ) +
              ( ( ( value >> 8 ) & 0xff ) << 16 ) +
              ( ( ( value >> 16 ) & 0xff ) << 8 ) +
              ( ( ( value >> 24 ) & 0xff ) << 0 );
      }
  
      public static long swapLong( final long value )
      {
          return
              ( ( ( value >> 0 ) & 0xff ) << 56 ) +
              ( ( ( value >> 8 ) & 0xff ) << 48 ) +
              ( ( ( value >> 16 ) & 0xff ) << 40 ) +
              ( ( ( value >> 24 ) & 0xff ) << 32 ) +
              ( ( ( value >> 32 ) & 0xff ) << 24 ) +
              ( ( ( value >> 40 ) & 0xff ) << 16 ) +
              ( ( ( value >> 48 ) & 0xff ) << 8 ) +
              ( ( ( value >> 56 ) & 0xff ) << 0 );
      }
  
      public static float swapFloat( final float value )
      {
          return Float.intBitsToFloat( swapInteger( Float.floatToIntBits( value ) ) );
      }
  
      public static double swapDouble( final double value )
      {
          return Double.longBitsToDouble( swapLong( Double.doubleToLongBits( value ) ) );
      }
  
      public static void writeSwappedShort( final byte[] data, final int offset, final int value )
      {
          data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff );
          data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff );
      }
  
      public static short readSwappedShort( final byte[] data, final int offset )
      {
          return (short)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
              ( ( data[ offset + 1 ] & 0xff ) << 8 ) );
      }
  
      public static int readSwappedUnsignedShort( final byte[] data, final int offset )
      {
          return (int)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
              ( ( data[ offset + 1 ] & 0xff ) << 8 ) );
      }
  
      public static void writeSwappedInteger( final byte[] data, final int offset, final int value )
      {
          data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff );
          data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff );
          data[ offset + 2 ] = (byte)( ( value >> 16 ) & 0xff );
          data[ offset + 3 ] = (byte)( ( value >> 24 ) & 0xff );
      }
  
      public static int readSwappedInteger( final byte[] data, final int offset )
      {
          return (int)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
              ( ( data[ offset + 1 ] & 0xff ) << 8 ) +
              ( ( data[ offset + 2 ] & 0xff ) << 16 ) +
              ( ( data[ offset + 3 ] & 0xff ) << 24 ) );
      }
  
      public static long readSwappedUnsignedInteger( final byte[] data, final int offset )
      {
          return (long)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
              ( ( data[ offset + 1 ] & 0xff ) << 8 ) +
              ( ( data[ offset + 2 ] & 0xff ) << 16 ) +
              ( ( data[ offset + 3 ] & 0xff ) << 24 ) );
      }
  
      public static void writeSwappedLong( final byte[] data, final int offset, final long value )
      {
          data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff );
          data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff );
          data[ offset + 2 ] = (byte)( ( value >> 16 ) & 0xff );
          data[ offset + 3 ] = (byte)( ( value >> 24 ) & 0xff );
          data[ offset + 4 ] = (byte)( ( value >> 32 ) & 0xff );
          data[ offset + 5 ] = (byte)( ( value >> 40 ) & 0xff );
          data[ offset + 6 ] = (byte)( ( value >> 48 ) & 0xff );
          data[ offset + 7 ] = (byte)( ( value >> 56 ) & 0xff );
      }
  
      public static long readSwappedLong( final byte[] data, final int offset )
      {
          return (long)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
              ( ( data[ offset + 1 ] & 0xff ) << 8 ) +
              ( ( data[ offset + 2 ] & 0xff ) << 16 ) +
              ( ( data[ offset + 3 ] & 0xff ) << 24 ) +
              ( ( data[ offset + 4 ] & 0xff ) << 32 ) +
              ( ( data[ offset + 5 ] & 0xff ) << 40 ) +
              ( ( data[ offset + 6 ] & 0xff ) << 48 ) +
              ( ( data[ offset + 7 ] & 0xff ) << 56 ) );
      }
  
      public static void writeSwappedFloat( final byte[] data, final int offset, final float value )
      {
          writeSwappedInteger( data, offset, Float.floatToIntBits( value ) );
      }
  
      public static float readSwappedFloat( final byte[] data, final int offset )
      {
          return Float.intBitsToFloat( readSwappedInteger( data, offset ) );
      }
  
      public static void writeSwappedDouble( final byte[] data, final int offset, final double value )
      {
          writeSwappedLong( data, offset, Double.doubleToLongBits( value ) );
      }
  
      public static double readSwappedDouble( final byte[] data, final int offset )
      {
          return Double.longBitsToDouble( readSwappedLong( data, offset ) );
      }
  
      //////////////////////////////////////////////////////////////////////
      //
      //  The following haven't been fully tested yet - unit tests coming soon!!!
      //
      //////////////////////////////////////////////////////////////////////
      public static void writeSwappedShort( final OutputStream output, final int value )
          throws IOException
      {
          output.write( (byte)( ( value >> 0 ) & 0xff ) );
          output.write( (byte)( ( value >> 8 ) & 0xff ) );
      }
  
      public static short readSwappedShort( final InputStream input )
          throws IOException
      {
          return (short)( ( ( read( input ) & 0xff ) << 0 ) +
              ( ( read( input ) & 0xff ) << 8 ) );
      }
  
      public static int readSwappedUnsignedShort( final InputStream input )
          throws IOException
      {
          final int value1 = read( input );
          final int value2 = read( input );
  
          return (int)( ( ( value1 & 0xff ) << 0 ) +
              ( ( value2 & 0xff ) << 8 ) );
      }
  
      public static void writeSwappedInteger( final OutputStream output, final int value )
          throws IOException
      {
          output.write( (byte)( ( value >> 0 ) & 0xff ) );
          output.write( (byte)( ( value >> 8 ) & 0xff ) );
          output.write( (byte)( ( value >> 16 ) & 0xff ) );
          output.write( (byte)( ( value >> 24 ) & 0xff ) );
      }
  
      public static int readSwappedInteger( final InputStream input )
          throws IOException
      {
          final int value1 = read( input );
          final int value2 = read( input );
          final int value3 = read( input );
          final int value4 = read( input );
  
          return (int)( ( ( value1 & 0xff ) << 0 ) +
              ( ( value2 & 0xff ) << 8 ) +
              ( ( value3 & 0xff ) << 16 ) +
              ( ( value4 & 0xff ) << 24 ) );
      }
  
      public static long readSwappedUnsignedInteger( final InputStream input )
          throws IOException
      {
          final int value1 = read( input );
          final int value2 = read( input );
          final int value3 = read( input );
          final int value4 = read( input );
  
          return (long)( ( ( value1 & 0xff ) << 0 ) +
              ( ( value2 & 0xff ) << 8 ) +
              ( ( value3 & 0xff ) << 16 ) +
              ( ( value4 & 0xff ) << 24 ) );
      }
  
      public static void writeSwappedLong( final OutputStream output, final long value )
          throws IOException
      {
          output.write( (byte)( ( value >> 0 ) & 0xff ) );
          output.write( (byte)( ( value >> 8 ) & 0xff ) );
          output.write( (byte)( ( value >> 16 ) & 0xff ) );
          output.write( (byte)( ( value >> 24 ) & 0xff ) );
          output.write( (byte)( ( value >> 32 ) & 0xff ) );
          output.write( (byte)( ( value >> 40 ) & 0xff ) );
          output.write( (byte)( ( value >> 48 ) & 0xff ) );
          output.write( (byte)( ( value >> 56 ) & 0xff ) );
      }
  
      public static long readSwappedLong( final InputStream input )
          throws IOException
      {
          final int value1 = read( input );
          final int value2 = read( input );
          final int value3 = read( input );
          final int value4 = read( input );
          final int value5 = read( input );
          final int value6 = read( input );
          final int value7 = read( input );
          final int value8 = read( input );
  
          return (long)( ( ( value1 & 0xff ) << 0 ) +
              ( ( value2 & 0xff ) << 8 ) +
              ( ( value3 & 0xff ) << 16 ) +
              ( ( value4 & 0xff ) << 24 ) +
              ( ( value5 & 0xff ) << 32 ) +
              ( ( value6 & 0xff ) << 40 ) +
              ( ( value7 & 0xff ) << 48 ) +
              ( ( value8 & 0xff ) << 56 ) );
      }
  
      public static void writeSwappedFloat( final OutputStream output, final float value )
          throws IOException
      {
          writeSwappedInteger( output, Float.floatToIntBits( value ) );
      }
  
      public static float readSwappedFloat( final InputStream input )
          throws IOException
      {
          return Float.intBitsToFloat( readSwappedInteger( input ) );
      }
  
      public static void writeSwappedDouble( final OutputStream output, final double value )
          throws IOException
      {
          writeSwappedLong( output, Double.doubleToLongBits( value ) );
      }
  
      public static double readSwappedDouble( final InputStream input )
          throws IOException
      {
          return Double.longBitsToDouble( readSwappedLong( input ) );
      }
  
      private static int read( final InputStream input )
          throws IOException
      {
          final int value = input.read();
  
          if( -1 == value )
          {
              throw new EOFException( "Unexpected EOF reached" );
          }
  
          return value;
      }
  }
  
  
  
  1.5       +25 -25    jakarta-commons-sandbox/io/src/test/org/apache/commons/io/IOUtilTestCase.java
  
  Index: IOUtilTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/io/src/test/org/apache/commons/io/IOUtilTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- IOUtilTestCase.java	3 Jul 2003 14:43:27 -0000	1.4
  +++ IOUtilTestCase.java	25 Jul 2003 07:51:26 -0000	1.5
  @@ -79,7 +79,7 @@
   // Note: jdk1.2 dependency
   
   /**
  - * This is used to test IOUtil for correctness. The following checks are performed:
  + * This is used to test IOUtils for correctness. The following checks are performed:
    * <ul>
    *   <li>The return must not be null, must be the same type and equals() to the method's second arg</li>
    *   <li>All bytes must have been read from the source (available() == 0)</li>
  @@ -211,7 +211,7 @@
           final FileInputStream fin = new FileInputStream( m_testFile );
           final FileOutputStream fout = new FileOutputStream( destination );
   
  -        int count = IOUtil.copy( fin, fout );
  +        int count = IOUtils.copy( fin, fout );
           assertTrue( "Not all bytes were read", fin.available() == 0 );
           assertEquals( "Number of bytes read should equal file size", m_testFile.length(), count );
           fout.flush();
  @@ -230,7 +230,7 @@
           final FileInputStream fin = new FileInputStream( m_testFile );
           final FileWriter fout = new FileWriter( destination );
   
  -        IOUtil.copy( fin, fout );
  +        IOUtils.copy( fin, fout );
   
           assertTrue( "Not all bytes were read", fin.available() == 0 );
           fout.flush();
  @@ -246,7 +246,7 @@
           throws Exception
       {
           final FileInputStream fin = new FileInputStream( m_testFile );
  -        final String out = IOUtil.toString( fin );
  +        final String out = IOUtils.toString( fin );
           assertNotNull( out );
           assertTrue( "Not all bytes were read", fin.available() == 0 );
           assertTrue( "Wrong output size: out.length()=" + out.length() +
  @@ -260,10 +260,10 @@
           final File destination = newFile( "copy3.txt" );
           final FileReader fin = new FileReader( m_testFile );
           final FileOutputStream fout = new FileOutputStream( destination );
  -        IOUtil.copy( fin, fout );
  +        IOUtils.copy( fin, fout );
           //Note: this method *does* flush. It is equivalent to:
           //  final OutputStreamWriter _out = new OutputStreamWriter(fout);
  -        //  IOUtil.copy( fin, _out, 4096 ); // copy( Reader, Writer, int );
  +        //  IOUtils.copy( fin, _out, 4096 ); // copy( Reader, Writer, int );
           //  _out.flush();
           //  out = fout;
   
  @@ -281,7 +281,7 @@
           final File destination = newFile( "copy4.txt" );
           final FileReader fin = new FileReader( m_testFile );
           final FileWriter fout = new FileWriter( destination );
  -        int count = IOUtil.copy( fin, fout );
  +        int count = IOUtils.copy( fin, fout );
           assertEquals( "The number of characters returned by copy is wrong", m_testFile.length(), count);
   
           fout.flush();
  @@ -296,7 +296,7 @@
           throws Exception
       {
           final FileReader fin = new FileReader( m_testFile );
  -        final String out = IOUtil.toString( fin );
  +        final String out = IOUtils.toString( fin );
           assertNotNull( out );
           assertTrue( "Wrong output size: out.length()=" +
                       out.length() + "!=" + FILE_SIZE,
  @@ -310,12 +310,12 @@
           final File destination = newFile( "copy5.txt" );
           final FileReader fin = new FileReader( m_testFile );
           // Create our String. Rely on testReaderToString() to make sure this is valid.
  -        final String str = IOUtil.toString( fin );
  +        final String str = IOUtils.toString( fin );
           final FileOutputStream fout = new FileOutputStream( destination );
  -        IOUtil.copy( str, fout );
  +        IOUtils.copy( str, fout );
           //Note: this method *does* flush. It is equivalent to:
           //  final OutputStreamWriter _out = new OutputStreamWriter(fout);
  -        //  IOUtil.copy( str, _out, 4096 ); // copy( Reader, Writer, int );
  +        //  IOUtils.copy( str, _out, 4096 ); // copy( Reader, Writer, int );
           //  _out.flush();
           //  out = fout;
           // note: we don't flush here; this IOUtils method does it for us
  @@ -333,9 +333,9 @@
           final File destination = newFile( "copy6.txt" );
           FileReader fin = new FileReader( m_testFile );
           // Create our String. Rely on testReaderToString() to make sure this is valid.
  -        final String str = IOUtil.toString( fin );
  +        final String str = IOUtils.toString( fin );
           final FileWriter fout = new FileWriter( destination );
  -        IOUtil.copy( str, fout );
  +        IOUtils.copy( str, fout );
           fout.flush();
   
           checkFile( destination );
  @@ -350,7 +350,7 @@
           throws Exception
       {
           final FileInputStream fin = new FileInputStream( m_testFile );
  -        final byte[] out = IOUtil.toByteArray( fin );
  +        final byte[] out = IOUtils.toByteArray( fin );
           assertNotNull( out );
           assertTrue( "Not all bytes were read", fin.available() == 0 );
           assertTrue( "Wrong output size: out.length=" + out.length +
  @@ -365,9 +365,9 @@
           final FileReader fin = new FileReader( m_testFile );
   
           // Create our String. Rely on testReaderToString() to make sure this is valid.
  -        final String str = IOUtil.toString( fin );
  +        final String str = IOUtils.toString( fin );
   
  -        final byte[] out = IOUtil.toByteArray( str );
  +        final byte[] out = IOUtils.toByteArray( str );
           assertEqualContent( str.getBytes(), out );
           fin.close();
       }
  @@ -380,8 +380,8 @@
           final FileInputStream fin = new FileInputStream( m_testFile );
   
           // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
  -        final byte[] in = IOUtil.toByteArray( fin );
  -        IOUtil.copy( in, fout );
  +        final byte[] in = IOUtils.toByteArray( fin );
  +        IOUtils.copy( in, fout );
           fout.flush();
           checkFile( destination );
           checkWrite( fout );
  @@ -394,9 +394,9 @@
           throws Exception
       {
           final FileInputStream fin = new FileInputStream( m_testFile );
  -        final byte[] in = IOUtil.toByteArray( fin );
  +        final byte[] in = IOUtils.toByteArray( fin );
           // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
  -        String str = IOUtil.toString( in );
  +        String str = IOUtils.toString( in );
           assertEqualContent( in, str.getBytes() );
           fin.close();
       }
  @@ -409,9 +409,9 @@
           final FileInputStream fin = new FileInputStream( m_testFile );
   
           // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
  -        final byte[] in = IOUtil.toByteArray( fin );
  +        final byte[] in = IOUtils.toByteArray( fin );
   
  -        IOUtil.copy( in, fout );
  +        IOUtils.copy( in, fout );
   
           fout.flush();
   
  
  
  
  1.4       +15 -4     jakarta-commons-sandbox/io/src/test/org/apache/commons/io/IOTestSuite.java
  
  Index: IOTestSuite.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/io/src/test/org/apache/commons/io/IOTestSuite.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IOTestSuite.java	27 Jan 2003 02:23:27 -0000	1.3
  +++ IOTestSuite.java	25 Jul 2003 07:51:26 -0000	1.4
  @@ -61,20 +61,31 @@
   
   package org.apache.commons.io;
   
  +import org.apache.commons.io.filefilter.FileFilterTestCase;
  +
   import junit.framework.Test;
   import junit.framework.TestSuite;
  +import junit.textui.TestRunner;
   
   /**
    * A basic test suite that tests all the IO package.
  + * 
  + * @author Matthew Hawthorne
  + * @see org.apache.commons.io
    */
   public class IOTestSuite
   {
  +    
  +    public static void main(String[] args) {
  +        TestRunner.run(suite());
  +    }
  +    
       public static Test suite()
       {
           final TestSuite suite = new TestSuite( "IO Utilities" );
           suite.addTest( new TestSuite( FileUtilsTestCase.class ) );
           suite.addTest( new TestSuite( IOUtilTestCase.class ) );
  -        suite.addTest( new TestSuite( org.apache.commons.io.filefilter.FileFilterTestCase.class ) );
  +        suite.addTest( new TestSuite( FileFilterTestCase.class ) );
           suite.addTest( new TestSuite( DemuxTestCase.class ) );
           suite.addTest( new TestSuite( HexDumpTest.class ) );
           return suite;
  
  
  
  1.2       +8 -8      jakarta-commons-sandbox/io/src/java/org/apache/commons/io/input/SwappedDataInputStream.java
  
  Index: SwappedDataInputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/input/SwappedDataInputStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SwappedDataInputStream.java	11 Nov 2002 19:34:02 -0000	1.1
  +++ SwappedDataInputStream.java	25 Jul 2003 07:51:26 -0000	1.2
  @@ -59,7 +59,7 @@
   import java.io.IOException;
   import java.io.InputStream;
   
  -import org.apache.commons.io.EndianUtil;
  +import org.apache.commons.io.EndianUtils;
   
   /**
    * DataInput for systems relying on little endian data formats.
  @@ -100,13 +100,13 @@
       public double readDouble()
           throws IOException, EOFException
       {
  -        return EndianUtil.readSwappedDouble( m_input );
  +        return EndianUtils.readSwappedDouble( m_input );
       }
   
       public float readFloat()
           throws IOException, EOFException
       {
  -        return EndianUtil.readSwappedFloat( m_input );
  +        return EndianUtils.readSwappedFloat( m_input );
       }
   
       public void readFully( final byte[] data )
  @@ -137,7 +137,7 @@
       public int readInt()
           throws IOException, EOFException
       {
  -        return EndianUtil.readSwappedInteger( m_input );
  +        return EndianUtils.readSwappedInteger( m_input );
       }
   
       public String readLine()
  @@ -149,13 +149,13 @@
       public long readLong()
           throws IOException, EOFException
       {
  -        return EndianUtil.readSwappedLong( m_input );
  +        return EndianUtils.readSwappedLong( m_input );
       }
   
       public short readShort()
           throws IOException, EOFException
       {
  -        return EndianUtil.readSwappedShort( m_input );
  +        return EndianUtils.readSwappedShort( m_input );
       }
   
       public int readUnsignedByte()
  @@ -167,7 +167,7 @@
       public int readUnsignedShort()
           throws IOException, EOFException
       {
  -        return EndianUtil.readSwappedUnsignedShort( m_input );
  +        return EndianUtils.readSwappedUnsignedShort( m_input );
       }
   
       public String readUTF()
  
  
  

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