donaldp     02/01/20 01:45:49

  Modified:    src/java/org/apache/avalon/excalibur/io IOUtil.java
  Log:
  Add Methods to unconditionally shutdown writers/readers
  
  Revision  Changes    Path
  1.9       +57 -22    
jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/io/IOUtil.java
  
  Index: IOUtil.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/io/IOUtil.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- IOUtil.java       11 Dec 2001 09:53:29 -0000      1.8
  +++ IOUtil.java       20 Jan 2002 09:45:49 -0000      1.9
  @@ -22,6 +22,7 @@
   import java.io.Writer;
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
  +import java.io.PrintStream;
   
   /**
    * General IO Stream manipulation.
  @@ -29,7 +30,7 @@
    * 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>). 
  + * <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
  @@ -70,34 +71,34 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Jeff Turner</a>
  - * @version CVS $Revision: 1.8 $ $Date: 2001/12/11 09:53:29 $
  + * @version CVS $Revision: 1.9 $ $Date: 2002/01/20 09:45:49 $
    * @since 4.0
    */
   
   /*
    * Behold, intrepid explorers; a map of this class:
    *
  - *       Method      Input               Output          Dependency 
  + *       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,
  @@ -116,6 +117,40 @@
       }
   
       /**
  +     * Unconditionally close an <code>Reader</code>.
  +     * Equivalent to [EMAIL PROTECTED] Reader#close()}, except any 
exceptions will be ignored.
  +     *
  +     * @param output 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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED] OutputStream#close()}, except any 
exceptions will be ignored.
        * @param output A (possibly null) OutputStream
  @@ -161,11 +196,11 @@
       }
   
       /**
  -     * Copy bytes from an <code>InputStream</code> to an 
<code>OutputStream</code>. 
  +     * 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, 
  +    public static void copy( final InputStream input,
  +                             final OutputStream output,
                                final int bufferSize )
           throws IOException
       {
  @@ -256,8 +291,8 @@
        *        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, 
  +    public static void copy( final InputStream input,
  +                             final Writer output,
                                final String encoding,
                                final int bufferSize )
           throws IOException
  @@ -312,8 +347,8 @@
        *   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, 
  +    public static String toString( final InputStream input,
  +                                   final String encoding,
                                      final int bufferSize )
           throws IOException
       {
  @@ -577,8 +612,8 @@
        *        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, 
  +    public static void copy( final byte[] input,
  +                             final Writer output,
                                final String encoding,
                                final int bufferSize )
           throws IOException
  @@ -633,8 +668,8 @@
        *   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, 
  +    public static String toString( final byte[] input,
  +                                   final String encoding,
                                      final int bufferSize )
           throws IOException
       {
  @@ -657,11 +692,11 @@
       }
   
       /**
  -     * Copy bytes from a <code>byte[]</code> to an 
<code>OutputStream</code>. 
  +     * 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, 
  +    public static void copy( final byte[] input,
  +                             final OutputStream output,
                                final int bufferSize )
           throws IOException
       {
  
  
  

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

Reply via email to