commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nicola...@apache.org
Subject cvs commit: jakarta-commons-sandbox/io/src/java/org/apache/commons/io AndFileFilter.java ClassLoaderObjectInputStream.java DemuxInputStream.java DemuxOutputStream.java DirectoryFileFilter.java EndianUtil.java ExtensionFileFilter.java FileUtil.java InvertedFileFilter.java IOUtil.java OrFileFilter.java package.html PrefixFileFilter.java SwappedDataInputStream.java
Date Mon, 08 Jul 2002 22:14:46 GMT
nicolaken    2002/07/08 15:14:46

  Added:       io/src/java/org/apache/commons/io AndFileFilter.java
                        ClassLoaderObjectInputStream.java
                        DemuxInputStream.java DemuxOutputStream.java
                        DirectoryFileFilter.java EndianUtil.java
                        ExtensionFileFilter.java FileUtil.java
                        InvertedFileFilter.java IOUtil.java
                        OrFileFilter.java package.html
                        PrefixFileFilter.java SwappedDataInputStream.java
  Log:
  New io classes from Avalon excalibur.
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/AndFileFilter.java
  
  Index: AndFileFilter.java
  ===================================================================
  package org.apache.commons.io;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "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.
   *
   * 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.
   *
   * 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/>.
   */
  
  import java.io.File;
  import java.io.FilenameFilter;
  
  /**
   * Accepts a selection if it is acceptable to both of two {@link FilenameFilter}s.
   * This takes two {@link FilenameFilter}s as input.
   *
   * <p>Eg., to print all files beginning with <code>A</code> and ending with <code>.java</code>:</p>
   *
   * <pre>
   * File dir = new File(".");
   * String[] files = dir.list( new AndFileFilter(
   *         new PrefixFileFilter("A"),
   *         new ExtensionFileFilter(".java")
   *         )
   *     );
   * for ( int i=0; i&lt;files.length; i++ )
   * {
   *     System.out.println(files[i]);
   * }
   * </pre>
   *
   * @author Harmeet Bedi <harmeet@kodemuse.com>
   * @version $Revision: 1.1 $ $Date: 2002/07/08 22:14:46 $
   * @since 4.0
   */
  public class AndFileFilter
      implements FilenameFilter
  {
      private final FilenameFilter m_filter1;
      private final FilenameFilter m_filter2;
  
      public AndFileFilter( final FilenameFilter filter1, final FilenameFilter filter2 )
      {
          m_filter1 = filter1;
          m_filter2 = filter2;
      }
  
      public boolean accept( final File file, final String name )
      {
          return m_filter1.accept( file, name ) && m_filter2.accept( file, name );
      }
  }
  
  
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/ClassLoaderObjectInputStream.java
  
  Index: ClassLoaderObjectInputStream.java
  ===================================================================
  package org.apache.commons.io;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "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.
   *
   * 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.
   *
   * 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/>.
   */
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.ObjectInputStream;
  import java.io.ObjectStreamClass;
  import java.io.StreamCorruptedException;
  
  /**
   * A special ObjectInputStream to handle highly transient classes hosted
   * by Avalon components that are juggling many classloaders.
   *
   * @author <a href="mailto:paul_hammant@yahoo.com">Paul Hammant</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/08 22:14:46 $
   */
  public class ClassLoaderObjectInputStream
      extends ObjectInputStream
  {
      private ClassLoader m_classLoader;
  
      public ClassLoaderObjectInputStream( final ClassLoader classLoader,
                                           final InputStream inputStream )
          throws IOException, StreamCorruptedException
      {
          super( inputStream );
          m_classLoader = classLoader;
      }
  
      protected Class resolveClass( final ObjectStreamClass objectStreamClass )
          throws IOException, ClassNotFoundException
      {
          final Class clazz =
              Class.forName( objectStreamClass.getName(), false, m_classLoader );
  
          if( null != clazz )
          {
              return clazz; // the classloader knows of the class
          }
          else
          {
              // classloader knows not of class, let the super classloader do it
              return super.resolveClass( objectStreamClass );
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/DemuxInputStream.java
  
  Index: DemuxInputStream.java
  ===================================================================
  package org.apache.commons.io;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "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.
   *
   * 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.
   *
   * 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/>.
   */
  
  import java.io.IOException;
  import java.io.InputStream;
  
  /**
   * Data written to this stream is forwarded to a stream that has been associated
   * with this thread.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/08 22:14:46 $
   */
  public final class DemuxInputStream
      extends InputStream
  {
      private final InheritableThreadLocal m_streams = new InheritableThreadLocal();
  
      /**
       * Bind the specified stream to the current thread.
       *
       * @param input the stream to bind
       */
      public InputStream bindStream( final InputStream input )
      {
          final InputStream oldValue = getStream();
          m_streams.set( input );
          return oldValue;
      }
  
      /**
       * Closes stream associated with current thread.
       *
       * @throws IOException if an error occurs
       */
      public void close()
          throws IOException
      {
          final InputStream input = getStream();
          if( null != input )
          {
              input.close();
          }
      }
  
      /**
       * Read byte from stream associated with current thread.
       *
       * @return the byte read from stream
       * @throws IOException if an error occurs
       */
      public int read()
          throws IOException
      {
          final InputStream input = getStream();
          if( null != input )
          {
              return input.read();
          }
          else
          {
              return -1;
          }
      }
  
      /**
       * Utility method to retrieve stream bound to current thread (if any).
       */
      private InputStream getStream()
      {
          return (InputStream)m_streams.get();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/DemuxOutputStream.java
  
  Index: DemuxOutputStream.java
  ===================================================================
  package org.apache.commons.io;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "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.
   *
   * 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.
   *
   * 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/>.
   */
  
  import java.io.IOException;
  import java.io.OutputStream;
  
  /**
   * Data written to this stream is forwarded to a stream that has been associated
   * with this thread.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/08 22:14:46 $
   */
  public final class DemuxOutputStream
      extends OutputStream
  {
      private final InheritableThreadLocal m_streams = new InheritableThreadLocal();
  
      /**
       * Bind the specified stream to the current thread.
       *
       * @param output the stream to bind
       */
      public OutputStream bindStream( final OutputStream output )
      {
          final OutputStream stream = getStream();
          m_streams.set( output );
          return stream;
      }
  
      /**
       * Closes stream associated with current thread.
       *
       * @throws IOException if an error occurs
       */
      public void close()
          throws IOException
      {
          final OutputStream output = getStream();
          if( null != output )
          {
              output.close();
          }
      }
  
      /**
       * Flushes stream associated with current thread.
       *
       * @throws IOException if an error occurs
       */
      public void flush()
          throws IOException
      {
          final OutputStream output = getStream();
          if( null != output )
          {
              output.flush();
          }
      }
  
      /**
       * Writes byte to stream associated with current thread.
       *
       * @param ch the byte to write to stream
       * @throws IOException if an error occurs
       */
      public void write( final int ch )
          throws IOException
      {
          final OutputStream output = getStream();
          if( null != output )
          {
              output.write( ch );
          }
      }
  
      /**
       * Utility method to retrieve stream bound to current thread (if any).
       */
      private OutputStream getStream()
      {
          return (OutputStream)m_streams.get();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/DirectoryFileFilter.java
  
  Index: DirectoryFileFilter.java
  ===================================================================
  package org.apache.commons.io;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "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.
   *
   * 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.
   *
   * 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/>.
   */
  import java.io.File;
  import java.io.FilenameFilter;
  
  /**
   * This filter accepts <code>File</code>s that are directories.
   * <p>Eg., here is how to print out a list of the current directory's subdirectories:</p>
   *
   * <pre>
   * File dir = new File(".");
   * String[] files = dir.list( new DirectoryFileFilter() );
   * for ( int i=0; i&lt;files.length; i++ )
   * {
   *     System.out.println(files[i]);
   * }
   * </pre>
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/08 22:14:46 $
   * @since 4.0
   */
  public class DirectoryFileFilter
      implements FilenameFilter
  {
      public boolean accept( final File file, final String name )
      {
          return new File( file, name ).isDirectory();
      }
  }
  
  
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/EndianUtil.java
  
  Index: EndianUtil.java
  ===================================================================
  package org.apache.commons.io;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "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.
   *
   * 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.
   *
   * 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/>.
   */
  
  import java.io.EOFException;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  
  /**
   * Utility code for dealing with different endian systems.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/07/08 22:14:46 $
   * @since 4.0
   */
  public final class EndianUtil
  {
      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;
  
      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.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/ExtensionFileFilter.java
  
  Index: ExtensionFileFilter.java
  ===================================================================
  package org.apache.commons.io;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "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.
   *
   * 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.
   *
   * 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/>.
   */
  
  import java.io.File;
  import java.io.FilenameFilter;
  
  /**
   * This filters files based on the extension (what the filename
   * ends with). This is used in retrieving all the files of a
   * particular type.
   *
   * <p>Eg., to retrieve and print all <code>*.java</code> files in the current directory:</p>
   *
   * <pre>
   * File dir = new File(".");
   * String[] files = dir.list( new ExtensionFileFilter( new String[]{"java"} ) );
   * for (int i=0; i&lt;files.length; i++)
   * {
   *     System.out.println(files[i]);
   * }
   * </pre>
   *
   * @author  Federico Barbieri <fede@apache.org>
   * @author Serge Knystautas <sergek@lokitech.com>
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/07/08 22:14:46 $
   * @since 4.0
   */
  public class ExtensionFileFilter
      implements FilenameFilter
  {
      private String[] m_extensions;
  
      public ExtensionFileFilter( final String[] extensions )
      {
          m_extensions = extensions;
      }
  
      public ExtensionFileFilter( final String extension )
      {
          m_extensions = new String[]{extension};
      }
  
      public boolean accept( final File file, final String name )
      {
          for( int i = 0; i < m_extensions.length; i++ )
          {
              if( name.endsWith( m_extensions[ i ] ) )
              {
                  return true;
              }
          }
          return false;
      }
  }
  
  
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/FileUtil.java
  
  Index: FileUtil.java
  ===================================================================
  package org.apache.commons.io;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "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.
   *
   * 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.
   *
   * 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/>.
   */
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.URL;
  
  /**
   * This class provides basic facilities for manipulating files and file paths.
   *
   * <h3>Path-related methods</h3>
   *
   * <p>Methods exist to retrieve the components of a typical file path. For example
   * <code>/www/hosted/mysite/index.html</code>, can be broken into:
   * <ul>
   *   <li><code>/www/hosted/mysite/</code> -- retrievable through {@link #getPath}</li>
   *   <li><code>index.html</code> -- retrievable through {@link #removePath}</li>
   *   <li><code>/www/hosted/mysite/index</code> -- retrievable through {@link #removeExtension}</li>
   *   <li><code>html</code> -- retrievable through {@link #getExtension}</li>
   * </ul>
   * There are also methods to {@link #catPath concatenate two paths}, {@link #resolveFile resolve a
   * path relative to a File} and {@link #normalize} a path.
   * </p>
   *
   * <h3>File-related methods</h3>
   * <p>
   * There are methods to  create a {@link #toFile File from a URL}, copy a
   * {@link #copyFileToDirectory File to a directory},
   * copy a {@link #copyFile File to another File},
   * copy a {@link #copyURLToFile URL's contents to a File},
   * as well as methods to {@link #deleteDirectory(File) delete} and {@link #cleanDirectory(File)
   * clean} a directory.
   * </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: 2002/07/08 22:14:46 $
   * @since 4.0
   */
  public final class FileUtil
  {
      /**
       * Private constructor to prevent instantiation.
       *
       */
      private FileUtil()
      {
      }
  
      /**
       * Compare the contents of two files to determine if they are equal or not.
       *
       * @param file1 the first file
       * @param file2 the second file
       * @return true if the content of the files are equal or they both don't exist, false otherwise
       */
      public static boolean contentEquals( final File file1, final File file2 )
          throws IOException
      {
          final boolean file1Exists = file1.exists();
          if( file1Exists != file2.exists() )
          {
              return false;
          }
  
          if( !file1Exists )
          {
              // two not existing files are equal
              return true;
          }
  
          if( file1.isDirectory() || file2.isDirectory() )
          {
              // don't want to compare directory contents
              return false;
          }
  
          InputStream input1 = null;
          InputStream input2 = null;
          try
          {
              input1 = new FileInputStream( file1 );
              input2 = new FileInputStream( file2 );
              return IOUtil.contentEquals( input1, input2 );
  
          }
          finally
          {
              IOUtil.shutdownStream( input1 );
              IOUtil.shutdownStream( input2 );
          }
      }
  
      /**
       * Convert from a <code>URL</code> to a <code>File</code>.
       * @param url File URL.
       * @return The equivalent <code>File</code> object, or <code>null</code> if the URL's protocol
       * is not <code>file</code>
       */
      public static File toFile( final URL url )
      {
          if( url.getProtocol().equals( "file" ) == false )
          {
              return null;
          }
          else
          {
              final String filename = url.getFile().replace( '/', File.separatorChar );
              return new File( filename );
          }
      }
  
      /**
       * Convert the array of Files into a list of URLs.
       *
       * @param files the array of files
       * @return the array of URLs
       * @throws IOException if an error occurs
       */
      public static URL[] toURLs( final File[] files )
          throws IOException
      {
          final URL[] urls = new URL[ files.length ];
  
          for( int i = 0; i < urls.length; i++ )
          {
              urls[ i ] = files[ i ].toURL();
          }
  
          return urls;
      }
  
      /**
       * Remove extension from filename.
       * ie
       * <pre>
       * foo.txt    --> foo
       * a\b\c.jpg --> a\b\c
       * a\b\c     --> a\b\c
       * </pre>
       *
       * @param filename the filename
       * @return the filename minus extension
       * @deprecated Use removeExtension as removeExtention is mispelled
       */
      public static String removeExtention( final String filename )
      {
          return removeExtension( filename );
      }
  
      /**
       * Remove extension from filename.
       * ie
       * <pre>
       * foo.txt    --> foo
       * a\b\c.jpg --> a\b\c
       * a\b\c     --> a\b\c
       * </pre>
       *
       * @param filename the filename
       * @return the filename minus extension
       */
      public static String removeExtension( final String filename )
      {
          final int index = filename.lastIndexOf( '.' );
  
          if( -1 == index )
          {
              return filename;
          }
          else
          {
              return filename.substring( 0, index );
          }
      }
  
      /**
       * Get extension from filename.
       * ie
       * <pre>
       * foo.txt    --> "txt"
       * a\b\c.jpg --> "jpg"
       * a\b\c     --> ""
       * </pre>
       *
       * @param filename the filename
       * @return the extension of filename or "" if none
       */
      public static String getExtension( final String filename )
      {
          final int index = filename.lastIndexOf( '.' );
  
          if( -1 == index )
          {
              return "";
          }
          else
          {
              return filename.substring( index + 1 );
          }
      }
  
      /**
       * Remove path from filename. Equivalent to the unix command <code>basename</code>
       * ie.
       * <pre>
       * a/b/c.txt --> c.txt
       * a.txt     --> a.txt
       * </pre>
       *
       * @param filepath the filepath
       * @return the filename minus path
       */
      public static String removePath( final String filepath )
      {
          return removePath( filepath, File.separatorChar );
      }
  
      /**
       * Remove path from filename.
       * ie.
       * <pre>
       * a/b/c.txt --> c.txt
       * a.txt     --> a.txt
       * </pre>
       *
       * @param filepath the filepath
       * @return the filename minus path
       */
      public static String removePath( final String filepath, final char fileSeparatorChar )
      {
          final int index = filepath.lastIndexOf( fileSeparatorChar );
  
          if( -1 == index )
          {
              return filepath;
          }
          else
          {
              return filepath.substring( index + 1 );
          }
      }
  
      /**
       * Get path from filename. Roughly equivalent to the unix command <code>dirname</code>.
       * ie.
       * <pre>
       * a/b/c.txt --> a/b
       * a.txt     --> ""
       * </pre>
       *
       * @param filepath the filepath
       * @return the filename minus path
       */
      public static String getPath( final String filepath )
      {
          return getPath( filepath, File.separatorChar );
      }
  
      /**
       * Get path from filename.
       * ie.
       * <pre>
       * a/b/c.txt --> a/b
       * a.txt     --> ""
       * </pre>
       *
       * @param filepath the filepath
       * @return the filename minus path
       */
      public static String getPath( final String filepath, final char fileSeparatorChar )
      {
          final int index = filepath.lastIndexOf( fileSeparatorChar );
          if( -1 == index )
          {
              return "";
          }
          else
          {
              return filepath.substring( 0, index );
          }
      }
  
      /**
       * Copy file from source to destination. If <code>destinationDirectory</code> does not exist, it
       * (and any parent directories) will be created. If a file <code>source</code> in
       * <code>destinationDirectory</code> exists, it will be overwritten.
       *
       * @param source An existing <code>File</code> to copy.
       * @param destinationDirectory A directory to copy <code>source</code> into.
       *
       * @throws FileNotFoundException if <code>source</code> isn't a normal file.
       * @throws IllegalArgumentException if <code>destinationDirectory</code> isn't a directory.
       * @throws IOException if <code>source</code> does not exist, the file in
       * <code>destinationDirectory</code> cannot be written to, or an IO error occurs during copying.
       */
      public static void copyFileToDirectory( final String source,
                                              final String destinationDirectory )
          throws IOException
      {
          copyFileToDirectory( new File( source ),
                               new File( destinationDirectory ) );
      }
  
      /**
       * Copy file from source to destination. If <code>destinationDirectory</code> does not exist, it
       * (and any parent directories) will be created. If a file <code>source</code> in
       * <code>destinationDirectory</code> exists, it will be overwritten.
       *
       * @param source An existing <code>File</code> to copy.
       * @param destinationDirectory A directory to copy <code>source</code> into.
       *
       * @throws FileNotFoundException if <code>source</code> isn't a normal file.
       * @throws IllegalArgumentException if <code>destinationDirectory</code> isn't a directory.
       * @throws IOException if <code>source</code> does not exist, the file in
       * <code>destinationDirectory</code> cannot be written to, or an IO error occurs during copying.
       */
      public static void copyFileToDirectory( final File source,
                                              final File destinationDirectory )
          throws IOException
      {
          if( destinationDirectory.exists() && !destinationDirectory.isDirectory() )
          {
              throw new IllegalArgumentException( "Destination is not a directory" );
          }
  
          copyFile( source, new File( destinationDirectory, source.getName() ) );
      }
  
      /**
       * Copy file from source to destination. The directories up to <code>destination</code> will be
       * created if they don't already exist. <code>destination</code> will be overwritten if it
       * already exists.
       *
       * @param source An existing non-directory <code>File</code> to copy bytes from.
       * @param destination A non-directory <code>File</code> to write bytes to (possibly
       * overwriting).
       *
       * @throws IOException if <code>source</code> does not exist, <code>destination</code> cannot be
       * written to, or an IO error occurs during copying.
       *
       * @throws FileNotFoundException if <code>destination</code> is a directory
       * (use {@link #copyFileToDirectory}).
       */
      public static void copyFile( final File source, final File destination )
          throws IOException
      {
          //check source exists
          if( !source.exists() )
          {
              final String message = "File " + source + " does not exist";
              throw new IOException( message );
          }
  
          //does destinations directory exist ?
          if( destination.getParentFile() != null &&
              !destination.getParentFile().exists() )
          {
              destination.getParentFile().mkdirs();
          }
  
          //make sure we can write to destination
          if( destination.exists() && !destination.canWrite() )
          {
              final String message = "Unable to open file " +
                  destination + " for writing.";
              throw new IOException( message );
          }
  
          final FileInputStream input = new FileInputStream( source );
          final FileOutputStream output = new FileOutputStream( destination );
          IOUtil.copy( input, output );
          IOUtil.shutdownStream( input );
          IOUtil.shutdownStream( output );
  
          if( source.length() != destination.length() )
          {
              final String message = "Failed to copy full contents from " + source +
                  " to " + destination;
              throw new IOException( message );
          }
      }
  
      /**
       * Copies bytes from the URL <code>source</code> to a file <code>destination</code>.
       * The directories up to <code>destination</code> will be created if they don't already exist.
       * <code>destination</code> will be overwritten if it already exists.
       *
       * @param source A <code>URL</code> to copy bytes from.
       * @param destination A non-directory <code>File</code> to write bytes to (possibly
       * overwriting).
       *
       * @throws IOException if
       * <ul>
       *  <li><code>source</code> URL cannot be opened</li>
       *  <li><code>destination</code> cannot be written to</li>
       *  <li>an IO error occurs during copying</li>
       * </ul>
       */
      public static void copyURLToFile( final URL source, final File destination )
          throws IOException
      {
          //does destination directory exist ?
          if( destination.getParentFile() != null &&
              !destination.getParentFile().exists() )
          {
              destination.getParentFile().mkdirs();
          }
  
          //make sure we can write to destination
          if( destination.exists() && !destination.canWrite() )
          {
              final String message = "Unable to open file " +
                  destination + " for writing.";
              throw new IOException( message );
          }
  
          final InputStream input = source.openStream();
          final FileOutputStream output = new FileOutputStream( destination );
          IOUtil.copy( input, output );
          IOUtil.shutdownStream( input );
          IOUtil.shutdownStream( output );
      }
  
      /**
       * Normalize a path.
       * Eliminates "/../" and "/./" in a string. Returns <code>null</code> if the ..'s went past the
       * root.
       * Eg:
       * <pre>
       * /foo//               -->     /foo/
       * /foo/./              -->     /foo/
       * /foo/../bar          -->     /bar
       * /foo/../bar/         -->     /bar/
       * /foo/../bar/../baz   -->     /baz
       * //foo//./bar         -->     /foo/bar
       * /../                 -->     null
       * </pre>
       *
       * @param path the path to normalize
       * @return the normalized String, or <code>null</code> if too many ..'s.
       */
      public static String normalize( final String path )
      {
          String normalized = path;
          // Resolve occurrences of "//" in the normalized path
          while( true )
          {
              int index = normalized.indexOf( "//" );
              if( index < 0 )
                  break;
              normalized = normalized.substring( 0, index ) +
                  normalized.substring( index + 1 );
          }
  
          // Resolve occurrences of "/./" in the normalized path
          while( true )
          {
              int index = normalized.indexOf( "/./" );
              if( index < 0 )
                  break;
              normalized = normalized.substring( 0, index ) +
                  normalized.substring( index + 2 );
          }
  
          // Resolve occurrences of "/../" in the normalized path
          while( true )
          {
              int index = normalized.indexOf( "/../" );
              if( index < 0 )
                  break;
              if( index == 0 )
                  return null;  // Trying to go outside our context
              int index2 = normalized.lastIndexOf( '/', index - 1 );
              normalized = normalized.substring( 0, index2 ) +
                  normalized.substring( index + 3 );
          }
  
          // Return the normalized path that we have completed
          return normalized;
      }
  
      /**
       * Will concatenate 2 paths.  Paths with <code>..</code> will be
       * properly handled.
       * <p>Eg.,<br />
       * <code>/a/b/c</code> + <code>d</code> = <code>/a/b/d</code><br />
       * <code>/a/b/c</code> + <code>../d</code> = <code>/a/d</code><br />
       * </p>
       *
       * Thieved from Tomcat sources...
       *
       * @return The concatenated paths, or null if error occurs
       */
      public static String catPath( final String lookupPath, final String path )
      {
          // Cut off the last slash and everything beyond
          int index = lookupPath.lastIndexOf( "/" );
          String lookup = lookupPath.substring( 0, index );
          String pth = path;
  
          // Deal with .. by chopping dirs off the lookup path
          while( pth.startsWith( "../" ) )
          {
              if( lookup.length() > 0 )
              {
                  index = lookup.lastIndexOf( "/" );
                  lookup = lookup.substring( 0, index );
              }
              else
              {
                  // More ..'s than dirs, return null
                  return null;
              }
  
              index = pth.indexOf( "../" ) + 3;
              pth = pth.substring( index );
          }
  
          return new StringBuffer( lookup ).append( "/" ).append( pth ).toString();
      }
  
      /**
       * Resolve a file <code>filename</code> to it's canonical form. If <code>filename</code> is
       * relative (doesn't start with <code>/</code>), it will be resolved relative to
       * <code>baseFile</code>, otherwise it is treated as a normal root-relative path.
       *
       * @param baseFile Where to resolve <code>filename</code> from, if <code>filename</code> is
       * relative.
       * @param filename Absolute or relative file path to resolve.
       * @return The canonical <code>File</code> of <code>filename</code>.
       */
      public static File resolveFile( final File baseFile, String filename )
      {
          String filenm = filename;
          if( '/' != File.separatorChar )
          {
              filenm = filename.replace( '/', File.separatorChar );
          }
  
          if( '\\' != File.separatorChar )
          {
              filenm = filename.replace( '\\', File.separatorChar );
          }
  
          // deal with absolute files
          if( filenm.startsWith( File.separator ) )
          {
              File file = new File( filenm );
  
              try
              {
                  file = file.getCanonicalFile();
              }
              catch( final IOException ioe )
              {
              }
  
              return file;
          }
          // FIXME: I'm almost certain this // removal is unnecessary, as getAbsoluteFile() strips
          // them. However, I'm not sure about this UNC stuff. (JT)
          final char[] chars = filename.toCharArray();
          final StringBuffer sb = new StringBuffer();
  
          //remove duplicate file separators in succession - except
          //on win32 at start of filename as UNC filenames can
          //be \\AComputer\AShare\myfile.txt
          int start = 0;
          if( '\\' == File.separatorChar )
          {
              sb.append( filenm.charAt( 0 ) );
              start++;
          }
  
          for( int i = start; i < chars.length; i++ )
          {
              final boolean doubleSeparator =
                  File.separatorChar == chars[ i ] && File.separatorChar == chars[ i - 1 ];
  
              if( !doubleSeparator )
              {
                  sb.append( chars[ i ] );
              }
          }
  
          filenm = sb.toString();
  
          //must be relative
          File file = ( new File( baseFile, filenm ) ).getAbsoluteFile();
  
          try
          {
              file = file.getCanonicalFile();
          }
          catch( final IOException ioe )
          {
          }
  
          return file;
      }
  
      /**
       * Delete a file. If file is directory delete it and all sub-directories.
       */
      public static void forceDelete( final String file )
          throws IOException
      {
          forceDelete( new File( file ) );
      }
  
      /**
       * Delete a file. If file is directory delete it and all sub-directories.
       */
      public static void forceDelete( final File file )
          throws IOException
      {
          if( file.isDirectory() )
          {
              deleteDirectory( file );
          }
          else
          {
              if( !file.delete() )
              {
                  final String message =
                      "File " + file + " unable to be deleted.";
                  throw new IOException( message );
              }
          }
      }
  
      /**
       * Schedule a file to be deleted when JVM exits.
       * If file is directory delete it and all sub-directories.
       */
      public static void forceDeleteOnExit( final File file )
          throws IOException
      {
          if( file.isDirectory() )
          {
              deleteDirectoryOnExit( file );
          }
          else
          {
              file.deleteOnExit();
          }
      }
  
      /**
       * Recursively schedule directory for deletion on JVM exit.
       */
      private static void deleteDirectoryOnExit( final File directory )
          throws IOException
      {
          if( !directory.exists() )
          {
              return;
          }
  
          cleanDirectoryOnExit( directory );
          directory.deleteOnExit();
      }
  
      /**
       * Clean a directory without deleting it.
       */
      private static void cleanDirectoryOnExit( final File directory )
          throws IOException
      {
          if( !directory.exists() )
          {
              final String message = directory + " does not exist";
              throw new IllegalArgumentException( message );
          }
  
          if( !directory.isDirectory() )
          {
              final String message = directory + " is not a directory";
              throw new IllegalArgumentException( message );
          }
  
          IOException exception = null;
  
          final File[] files = directory.listFiles();
          for( int i = 0; i < files.length; i++ )
          {
              final File file = files[ i ];
              try
              {
                  FileUtil.forceDeleteOnExit( file );
              }
              catch( final IOException ioe )
              {
                  exception = ioe;
              }
          }
  
          if( null != exception )
          {
              throw exception;
          }
      }
  
  
      /**
       * Make a directory. If there already exists a file with specified name or
       * the directory is unable to be created then an exception is thrown.
       */
      public static void forceMkdir( final File file )
          throws IOException
      {
          if( file.exists() )
          {
              if( file.isFile() )
              {
                  final String message = "File " + file + " exists and is " +
                      "not a directory. Unable to create directory.";
                  throw new IOException( message );
              }
          }
          else
          {
              if( false == file.mkdirs() )
              {
                  final String message = "Unable to create directory " + file;
                  throw new IOException( message );
              }
          }
      }
  
      /**
       * Recursively delete a directory.
       */
      public static void deleteDirectory( final String directory )
          throws IOException
      {
          deleteDirectory( new File( directory ) );
      }
  
      /**
       * Recursively delete a directory.
       */
      public static void deleteDirectory( final File directory )
          throws IOException
      {
          if( !directory.exists() )
          {
              return;
          }
  
          cleanDirectory( directory );
          if( !directory.delete() )
          {
              final String message =
                  "Directory " + directory + " unable to be deleted.";
              throw new IOException( message );
          }
      }
  
      /**
       * Clean a directory without deleting it.
       */
      public static void cleanDirectory( final String directory )
          throws IOException
      {
          cleanDirectory( new File( directory ) );
      }
  
      /**
       * Clean a directory without deleting it.
       */
      public static void cleanDirectory( final File directory )
          throws IOException
      {
          if( !directory.exists() )
          {
              final String message = directory + " does not exist";
              throw new IllegalArgumentException( message );
          }
  
          if( !directory.isDirectory() )
          {
              final String message = directory + " is not a directory";
              throw new IllegalArgumentException( message );
          }
  
          IOException exception = null;
  
          final File[] files = directory.listFiles();
          for( int i = 0; i < files.length; i++ )
          {
              final File file = files[ i ];
              try
              {
                  FileUtil.forceDelete( file );
              }
              catch( final IOException ioe )
              {
                  exception = ioe;
              }
          }
  
          if( null != exception )
          {
              throw exception;
          }
      }
  
      /**
       * Recursively count size of a directory.
       *
       * @return size of directory in bytes.
       */
      public static long sizeOfDirectory( final String directory )
      {
          return sizeOfDirectory( new File( directory ) );
      }
  
      /**
       * Recursively count size of a directory.
       *
       * @return size of directory in bytes.
       */
      public static long sizeOfDirectory( final File directory )
      {
          if( !directory.exists() )
          {
              final String message = directory + " does not exist";
              throw new IllegalArgumentException( message );
          }
  
          if( !directory.isDirectory() )
          {
              final String message = directory + " is not a directory";
              throw new IllegalArgumentException( message );
          }
  
          long size = 0;
  
          final File[] files = directory.listFiles();
          for( int i = 0; i < files.length; i++ )
          {
              final File file = files[ i ];
  
              if( file.isDirectory() )
              {
                  size += sizeOfDirectory( file );
              }
              else
              {
                  size += file.length();
              }
          }
  
          return size;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/InvertedFileFilter.java
  
  Index: InvertedFileFilter.java
  ===================================================================
  package org.apache.commons.io;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "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.
   *
   * 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.
   *
   * 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/>.
   */
  
  import java.io.File;
  import java.io.FilenameFilter;
  
  /**
   * This takes a <code>FilenameFilter<code> as input and inverts the selection.
   * This is used in retrieving files that are not accepted by a filter.
   *
   * <p>
   * Eg., here is how one could use <code>InvertedFileFilter</code> in conjunction with
   * {@link org.apache.commons.io.ExtensionFileFilter} to print all files not ending in
   * <code>.bak</code> or <code>.BAK</code> in the current directory:
   * </p>
   *
   * <pre>
   * File dir = new File(".");
   * String[] files = dir.list(
   *     new InvertedFileFilter(
   *         new ExtensionFileFilter( new String[]{".bak", ".BAK"} )
   *         )
   *     );
   * for ( int i=0; i&lt;files.length; i++ )
   * {
   *     System.out.println(files[i]);
   * }
   * </pre>
   *
   * @author Harmeet Bedi <harmeet@kodemuse.com>
   * @version CVS $Revision: 1.1 $ $Date: 2002/07/08 22:14:46 $
   * @since 4.0
   */
  public class InvertedFileFilter
      implements FilenameFilter
  {
      private final FilenameFilter m_originalFilter;
  
      public InvertedFileFilter( final FilenameFilter originalFilter )
      {
          m_originalFilter = originalFilter;
      }
  
      public boolean accept( final File file, final String name )
      {
          return !m_originalFilter.accept( file, name );
      }
  }
  
  
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/IOUtil.java
  
  Index: IOUtil.java
  ===================================================================
  package org.apache.commons.io;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "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.
   *
   * 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.
   *
   * 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/>.
   */
  
  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: 2002/07/08 22:14:46 $
   * @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 IOUtil
  {
      private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
  
      /**
       * Private constructor to prevent instantiation.
       */
      private IOUtil()
      {
      }
  
      /**
       * 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( null == input )
          {
              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( null == output )
          {
              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( null == output )
          {
              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( null == input )
          {
              return;
          }
  
          try
          {
              input.close();
          }
          catch( final IOException ioe )
          {
          }
      }
  
      ///////////////////////////////////////////////////////////////
      // Core copy methods
      ///////////////////////////////////////////////////////////////
  
      /**
       * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
       */
      public static void copy( final InputStream input, final OutputStream output )
          throws IOException
      {
          copy( input, output, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
       * @param bufferSize Size of internal buffer to use.
       */
      public static void copy( final InputStream input,
                               final OutputStream output,
                               final int bufferSize )
          throws IOException
      {
          final byte[] buffer = new byte[ bufferSize ];
          int n = 0;
          while( -1 != ( n = input.read( buffer ) ) )
          {
              output.write( buffer, 0, n );
          }
      }
  
      /**
       * Copy chars from a <code>Reader</code> to a <code>Writer</code>.
       */
      public static void copy( final Reader input, final Writer output )
          throws IOException
      {
          copy( input, output, DEFAULT_BUFFER_SIZE );
      }
  
      /**
       * Copy chars from a <code>Reader</code> to a <code>Writer</code>.
       * @param bufferSize Size of internal buffer to use.
       */
      public static void copy( final Reader input, final Writer output, final int bufferSize )
          throws IOException
      {
          final char[] buffer = new char[ bufferSize ];
          int n = 0;
          while( -1 != ( n = input.read( buffer ) ) )
          {
              output.write( buffer, 0, n );
          }
      }
  
      ///////////////////////////////////////////////////////////////
      // 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.
       */
      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 bufferSize Size of internal buffer to use.
       */
      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 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.
       */
      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 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.
       */
      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.
       */
      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 bufferSize Size of internal buffer to use.
       */
      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 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.
       */
      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 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.
       */
      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>.
       */
      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 bufferSize Size of internal buffer to use.
       */
      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>.
       */
      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 bufferSize Size of internal buffer to use.
       */
      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.
       */
      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 bufferSize Size of internal buffer to use.
       */
      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>.
       */
      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 bufferSize Size of internal buffer to use.
       */
      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>.
       */
      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 bufferSize Size of internal buffer to use.
       */
      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>.
       */
      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.
       */
      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>.
       */
      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 bufferSize Size of internal buffer to use.
       */
      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.
       */
      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 bufferSize Size of internal buffer to use.
       */
      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 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.
       */
      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 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.
       */
      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.
       */
      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 bufferSize Size of internal buffer to use.
       */
      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 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.
       */
      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 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.
       */
      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>.
       */
      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 bufferSize Size of internal buffer to use.
       */
      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
       */
      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/OrFileFilter.java
  
  Index: OrFileFilter.java
  ===================================================================
  package org.apache.commons.io;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "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.
   *
   * 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.
   *
   * 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/>.
   */
  
  import java.io.File;
  import java.io.FilenameFilter;
  
  /**
   * Accepts a selection if it is acceptable to either of two {@link FilenameFilter}s.
   * This takes two {@link FilenameFilter}s as input.
   *
   * <p>Eg., to print all directories or <code>*.gif</code> files in the current directory:</p>
   *
   * <pre>
   * File dir = new File(".");
   * String[] files = dir.list( new OrFileFilter(
   *         new DirectoryFileFilter(),
   *         new ExtensionFileFilter(".gif")
   *         )
   *     );
   * for ( int i=0; i&lt;files.length; i++ )
   * {
   *     System.out.println(files[i]);
   * }
   * </pre>
   *
   * @author Harmeet Bedi <harmeet@kodemuse.com>
   * @version CVS $Revision: 1.1 $ $Date: 2002/07/08 22:14:46 $
   * @since 4.0
   */
  public class OrFileFilter
      implements FilenameFilter
  {
      private final FilenameFilter m_filter1;
      private final FilenameFilter m_filter2;
  
      public OrFileFilter( final FilenameFilter filter1, final FilenameFilter filter2 )
      {
          m_filter1 = filter1;
          m_filter2 = filter2;
      }
  
      public boolean accept( final File file, final String name )
      {
          return m_filter1.accept( file, name ) || m_filter2.accept( file, name );
      }
  }
  
  
  
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/package.html
  
  Index: package.html
  ===================================================================
  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <html>
  <head>
    <title>Package Documentation for org.apache.avalon.excalibur.io Package</title>
  </head>
     <body bgcolor="white">
       Utility code for IO operations.     <br>
  <span style="font-style: italic;">NOTE: Some classes are not yet included
  in this description</span><br>
  <br>
       <a name="doc.Description"></a>     
  <div align="center">       <a href="#doc.Intro">[Introduction]</a>      
  <a href="#doc.FilenameFilters">[FilenameFilters]</a>       <a
   href="#doc.IOUtil">[IO Utilities]</a>       <a href="#doc.FileUtil">[File
  Utilities]</a>       <a href="#doc.Endian">[Endian Utilities]</a>     </div>
        <a name="doc.Intro"></a>     
  <h2>Introduction</h2>
       
  <p>The <code>org.apache.commons.io</code> package contains utility code for
  file-     and stream-based IO operation. There are three main types of class: 
      </p>
         <a name="doc.FilenameFilters"></a>     
  <h2>FilenameFilters</h2>
       
  <p>     The Java API defines an interface {@link java.io.FilenameFilter},
  which is used to filter     directory listings. This is commonly used in
  the {@link     java.io.File#list(java.io.FilenameFilter)} method, and in
  <code>java.awt.FileDialog</code>.     </p>
       
  <p>There are three "primitive" FilenameFilters:</p>
       
  <table>
         <tbody>
      <tr>
        <td><a href="DirectoryFileFilter.html">DirectoryFilter</a></td>
        <td>Only accept directories</td>
      </tr>
         <tr>
        <td><a href="PrefixFileFilter.html">PrefixFileFilter</a></td>
        <td>Filter based on prefix</td>
      </tr>
         <tr>
        <td><a href="ExtensionFileFilter.html">ExtensionFileFilter</a></td>
        <td>Filter based on extension</td>
      </tr>
        
    </tbody>
  </table>
       
  <p>And there are three "boolean" FilenameFilters:</p>
       
  <table>
         <tbody>
      <tr>
        <td><a href="AndFileFilter.html">AndFileFilter</a></td>
        <td>Accept if two subfilters both accept</td>
      </tr>
         <tr>
        <td><a href="InvertedFileFilter.html">InvertedFileFilter</a></td>
        <td>Accept if a subfilter rejects</td>
      </tr>
         <tr>
        <td><a href="OrFileFilter.html">OrFileFilter</a></td>
        <td>Accept if either of two subfilters accepts</td>
      </tr>
       
    </tbody>
  </table>
        
  <p>These boolean FilenameFilters can be nested, to allow arbitrary expressions.
  For example,     here is how one could print all non-directory files in the
  current directory, starting with     "A", and ending in ".java" or ".class":</p>
       
  <pre>File dir = new File(".");<br>String[] files = dir.list( new AndFileFilter(<br>      new AndFileFilter( <br>        new PrefixFileFilter("A"),<br>        new OrFileFilter(<br>          new ExtensionFileFilter(".class"),<br>          new ExtensionFileFilter(".java")<br>          )<br>        ),<br>      new InvertedFileFilter(<br>        new DirectoryFileFilter()<br>        )<br>      )<br>    );<br>for ( int i=0; i&lt;files.length; i++ )<br>{<br>  System.out.println(files[i]);<br>}<br>    </pre>
          <a name="doc.IOUtil"></a>     
  <h2>The <a href="IOUtil.html">org.apache.commons.io.IOUtil</a> class</h2>
       
  <p>     The <a href="IOUtil.html">IOUtil</a> class contains a     comprehensive
  set of static methods for copying from:     </p>
  <ul>
         <li><code>String</code></li>
         <li><code>byte[]</code></li>
         <li><code>InputStream</code></li>
         <li><code>Reader</code></li>
       
  </ul>
       To:     
  <ul>
         <li><code>String</code></li>
         <li><code>byte[]</code></li>
         <li><code>OutputStream</code></li>
         <li><code>Writer</code></li>
       
  </ul>
       
  <p></p>
        
  <p>As an example, consider the task of reading bytes from a URL, and printing
  them. This would     typically done like this:</p>
       
  <pre>import java.net.URL;<br>import java.io.*;<br><br>public class ManualCopy {<br>  public static void main(String args[]) throws IOException {<br>    InputStream in = new URL( "http://jakarta.apache.org" ).openStream();<br>    <font
   color="blue">
        InputStreamReader inR = new InputStreamReader( in );
      BufferedReader buf = new BufferedReader( inR );
      String line;
      while ( ( line = buf.readLine() ) != null )
      {
        System.out.println( line );
      }
      </font>
        in.close();
    }
  }
     </pre>
       
  <p>With the IOUtil class, that could be done with:</p>
       
  <pre>import java.net.URL;<br>import java.io.*;<br>import org.apache.commons.io.IOUtil;<br><br>public class IOUtilCopy {<br>  public static void main(String args[]) throws IOException {<br>    InputStream in = new URL( "http://jakarta.apache.org" ).openStream();<br>    <font
   color="blue">System.out.println( IOUtil.toString( in ) );</font>
        in.close();
    }   
  }
      </pre>
       
  <p>In certain application domains, such IO operations are common, and this
  class can save a     great deal of time.</p>
       
  <p>For utility code such as this, flexibility and speed are of primary importance.
  In IOUtil,     each kind of copy method has a variant which allows the buffer
  size to be set. For methods that     convert bytes to chars, the encoding
  method may also be set.</p>
         <a name="doc.FileUtil"></a>     
  <h2>The <a href="FileUtil.html">org.apache.commons.io.FileUtil</a> class</h2>
        
  <p>The <a href="FileUtil.html">FileUtil</a> class contains     methods for
  retrieving different components of a file path (directory name, file base
  name, file     extension), methods for copying Files to other files and directories,
  and methods for deleting     and cleaning directories. For more information,
  see the <a href="FileUtil.html">class       description</a>     </p>
         <a name="doc.Endian"></a>     
  <h2>The Endian classes</h2>
         
  <p>Different computer architectures adopt different conventions for byte
  ordering. In so-called     "Little Endian" architectures (eg Intel), the
  low-order byte is stored in memory at the lowest     address, and subsequent
  bytes at higher addresses. For "Big Endian" architectures (eg Motorola), 
     the situation is reversed.</p>
       
  <p>There are two classes in this package of relevance:     </p>
  <ul>
         <li>The <a href="EndianUtil.html">org.apache.commons.io.EndianUtil</a>
  class       contains static methods for swapping the Endian-ness of Java
  primitives and streams.</li>
         <li>The       <a href="SwappedDataInputStream.html">org.apache.avalon.excalibur.io.SwappedDataInputStream</a> 
        class is an implementation of the {@link java.io.DataInput} interface.
  With this, one can read       data from files of non-native Endian-ness.</li>
       
  </ul>
        
  <p>For more information, see <a
   href="http://www.cs.umass.edu/%7Everts/cs32/endian.html">http://www.cs.umass.edu/~verts/cs32/endian.html</a>. 
        @since 4.0    </p>
  <br>
  </body>
  </html>
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/PrefixFileFilter.java
  
  Index: PrefixFileFilter.java
  ===================================================================
  package org.apache.commons.io;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "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.
   *
   * 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.
   *
   * 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/>.
   */
  
  import java.io.File;
  import java.io.FilenameFilter;
  
  /**
   * This filters filenames for a certain prefix.
   *
   * <p>Eg., to print all files and directories in the current directory whose name starts with</p>
   * <code>foo</code>:
   *
   * <pre>
   * File dir = new File(".");
   * String[] files = dir.list( new PrefixFileFilter("foo"));
   * for ( int i=0; i&lt;files.length; i++ )
   * {
   *     System.out.println(files[i]);
   * }
   * </pre>
   *
   *
   * @author  Federico Barbieri <fede@apache.org>
   * @author Serge Knystautas <sergek@lokitech.com>
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/07/08 22:14:46 $
   * @since 4.0
   */
  public class PrefixFileFilter
      implements FilenameFilter
  {
      private String[] m_prefixs;
  
      public PrefixFileFilter( final String[] prefixs )
      {
          m_prefixs = prefixs;
      }
  
      public PrefixFileFilter( final String prefix )
      {
          m_prefixs = new String[]{prefix};
      }
  
      public boolean accept( final File file, final String name )
      {
          for( int i = 0; i < m_prefixs.length; i++ )
          {
              if( name.startsWith( m_prefixs[ i ] ) )
              {
                  return true;
              }
          }
          return false;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/SwappedDataInputStream.java
  
  Index: SwappedDataInputStream.java
  ===================================================================
  package org.apache.commons.io;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "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.
   *
   * 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.
   *
   * 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/>.
   */
  
  import java.io.DataInput;
  import java.io.EOFException;
  import java.io.IOException;
  import java.io.InputStream;
  
  /**
   * DataInput for systems relying on little endian data formats.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/07/08 22:14:46 $
   * @since 4.0
   */
  public class SwappedDataInputStream
      implements DataInput
  {
      //The underlying input stream
      private InputStream m_input;
  
      public SwappedDataInputStream( final InputStream input )
      {
          m_input = input;
      }
  
      public boolean readBoolean()
          throws IOException, EOFException
      {
          return ( 0 == readByte() );
      }
  
      public byte readByte()
          throws IOException, EOFException
      {
          return (byte)m_input.read();
      }
  
      public char readChar()
          throws IOException, EOFException
      {
          return (char)readShort();
      }
  
      public double readDouble()
          throws IOException, EOFException
      {
          return EndianUtil.readSwappedDouble( m_input );
      }
  
      public float readFloat()
          throws IOException, EOFException
      {
          return EndianUtil.readSwappedFloat( m_input );
      }
  
      public void readFully( final byte[] data )
          throws IOException, EOFException
      {
          readFully( data, 0, data.length );
      }
  
      public void readFully( final byte[] data, final int offset, final int length )
          throws IOException, EOFException
      {
          int remaining = length;
  
          while( remaining > 0 )
          {
              final int location = offset + ( length - remaining );
              final int count = read( data, location, remaining );
  
              if( -1 == count )
              {
                  throw new EOFException();
              }
  
              remaining -= count;
          }
      }
  
      public int readInt()
          throws IOException, EOFException
      {
          return EndianUtil.readSwappedInteger( m_input );
      }
  
      public String readLine()
          throws IOException, EOFException
      {
          throw new IOException( "Operation not supported" );
      }
  
      public long readLong()
          throws IOException, EOFException
      {
          return EndianUtil.readSwappedLong( m_input );
      }
  
      public short readShort()
          throws IOException, EOFException
      {
          return EndianUtil.readSwappedShort( m_input );
      }
  
      public int readUnsignedByte()
          throws IOException, EOFException
      {
          return m_input.read();
      }
  
      public int readUnsignedShort()
          throws IOException, EOFException
      {
          return EndianUtil.readSwappedUnsignedShort( m_input );
      }
  
      public String readUTF()
          throws IOException, EOFException
      {
          throw new IOException( "Operation not supported" );
      }
  
      public int skipBytes( final int count )
          throws IOException, EOFException
      {
          return (int)m_input.skip( count );
      }
  
      public int available()
          throws IOException, EOFException
      {
          return m_input.available();
      }
  
      public void close()
          throws IOException, EOFException
      {
          m_input.close();
      }
  
      public int read()
          throws IOException, EOFException
      {
          return m_input.read();
      }
  
      public int read( final byte[] data )
          throws IOException, EOFException
      {
          return read( data, 0, data.length );
      }
  
      public int read( final byte[] data, final int offset, final int length )
          throws IOException, EOFException
      {
          return m_input.read( data, offset, length );
      }
  
      public long skip( final long count )
          throws IOException, EOFException
      {
          return m_input.skip( count );
      }
  
      public void mark( final int readLimit )
      {
          m_input.mark( readLimit );
      }
  
      public boolean markSupported()
      {
          return m_input.markSupported();
      }
  
      public void reset()
          throws IOException
      {
          m_input.reset();
      }
  }
  
  
  

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


Mime
View raw message