org.yajul.util
Class Copier

java.lang.Object
  extended by org.yajul.util.Copier

public class Copier
extends java.lang.Object

Provides stream and reader/writer copying functions.
User: jdavis Date: Jan 28, 2004 Time: 5:53:42 PM

Author:
jdavis

Field Summary
static int DEFAULT_BUFFER_SIZE
          The default buffer size.
static int UNLIMITED
          Use this to indicate a non-length limited copy.
 
Constructor Summary
Copier()
           
 
Method Summary
static int copy(java.io.InputStream in, java.io.OutputStream out, int bufsz, int limit)
          Copies the input stream into the output stream in an efficient manner.
static int copy(java.io.Reader in, java.io.Writer out, int bufsz, int limit)
          Copies the input stream (reader) into the output stream (writer) in an efficient manner.
static byte[] toByteArray(java.io.InputStream in)
          Reads the entire input stream into a byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

public static int DEFAULT_BUFFER_SIZE
The default buffer size. *


UNLIMITED

public static int UNLIMITED
Use this to indicate a non-length limited copy. *

Constructor Detail

Copier

public Copier()
Method Detail

copy

public static int copy(java.io.InputStream in,
                       java.io.OutputStream out,
                       int bufsz,
                       int limit)
                throws java.io.IOException
Copies the input stream into the output stream in an efficient manner. This version does not synchronize on the streams, so it is not safe to use when the streams are being accessed by multiple threads.

Parameters:
in - The input stream.
out - The output stream. If this is null, the input will be discarded, similar to piping to /dev/null on UN*X.
bufsz - The size of the buffer to use.
limit - The number of bytes to copy, or UNLIMITED (-1) to copy until the end of the input stream.
Returns:
int The number of bytes copied.
Throws:
java.io.IOException - When the stream could not be copied.

copy

public static int copy(java.io.Reader in,
                       java.io.Writer out,
                       int bufsz,
                       int limit)
                throws java.io.IOException
Copies the input stream (reader) into the output stream (writer) in an efficient manner. This version does not synchronize on the streams, so it is not safe to use when the streams are being accessed by multiple threads.

Parameters:
in - The input reader
out - The output writer. If this is null, the input will be discarded, similar to piping to /dev/null on UN*X.
bufsz - The size of the buffer to use.
limit - The number of bytes to copy, or UNLIMITED (-1) to copy until the end of the input stream.
Returns:
int The number of bytes copied.
Throws:
java.io.IOException - When the stream could not be copied.

toByteArray

public static byte[] toByteArray(java.io.InputStream in)
                          throws java.io.IOException
Reads the entire input stream into a byte array.

Parameters:
in - The input stream
Returns:
The contents of the input stream as a byte array.
Throws:
java.io.IOException - if something goes wrong while copying.


Copyright © 2008. All Rights Reserved.