FileDocCategorySizeDatePackage
StreamUtils.javaAPI DocApache log4j 1.2.154170Sat Aug 25 00:09:38 BST 2007org.apache.log4j.lf5.util

StreamUtils

public abstract class StreamUtils extends Object
Provides utility methods for input and output streams.
author
Richard Wan

Fields Summary
public static final int
DEFAULT_BUFFER_SIZE
Default value is 2048.
Constructors Summary
Methods Summary
public static voidcopy(java.io.InputStream input, java.io.OutputStream output)
Copies information from the input stream to the output stream using a default buffer size of 2048 bytes.

throws
java.io.IOException


  //--------------------------------------------------------------------------
  //   Protected Variables:
  //--------------------------------------------------------------------------

  //--------------------------------------------------------------------------
  //   Private Variables:
  //--------------------------------------------------------------------------

  //--------------------------------------------------------------------------
  //   Constructors:
  //--------------------------------------------------------------------------

  //--------------------------------------------------------------------------
  //   Public Methods:
  //--------------------------------------------------------------------------

                         
        
        
    copy(input, output, DEFAULT_BUFFER_SIZE);
  
public static voidcopy(java.io.InputStream input, java.io.OutputStream output, int bufferSize)
Copies information from the input stream to the output stream using the specified buffer size

throws
java.io.IOException

    byte[] buf = new byte[bufferSize];
    int bytesRead = input.read(buf);
    while (bytesRead != -1) {
      output.write(buf, 0, bytesRead);
      bytesRead = input.read(buf);
    }
    output.flush();
  
public static voidcopyThenClose(java.io.InputStream input, java.io.OutputStream output)
Copies information between specified streams and then closes both of the streams.

throws
java.io.IOException

    copy(input, output);
    input.close();
    output.close();
  
public static byte[]getBytes(java.io.InputStream input)

return
a byte[] containing the information contained in the specified InputStream.
throws
java.io.IOException

    ByteArrayOutputStream result = new ByteArrayOutputStream();
    copy(input, result);
    result.close();
    return result.toByteArray();