org.apache.commons.fileupload.util
Class Streams

java.lang.Object
  extended by org.apache.commons.fileupload.util.Streams

public final class Streams
extends java.lang.Object

Utility class for working with streams.


Field Summary
private static int DEFAULT_BUFFER_SIZE
          Default buffer size for use in copy(InputStream, OutputStream, boolean).
 
Constructor Summary
private Streams()
          Private constructor, to prevent instantiation.
 
Method Summary
static java.lang.String asString(java.io.InputStream pStream)
          This convenience method allows to read a FileItemStream's content into a string.
static java.lang.String asString(java.io.InputStream pStream, java.lang.String pEncoding)
          This convenience method allows to read a FileItemStream's content into a string, using the given character encoding.
static long copy(java.io.InputStream pInputStream, java.io.OutputStream pOutputStream, boolean pClose)
          Copies the contents of the given InputStream to the given OutputStream.
static long copy(java.io.InputStream pIn, java.io.OutputStream pOut, boolean pClose, byte[] pBuffer)
          Copies the contents of the given InputStream to the given OutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

private static final int DEFAULT_BUFFER_SIZE
Default buffer size for use in copy(InputStream, OutputStream, boolean).

See Also:
Constant Field Values
Constructor Detail

Streams

private Streams()
Private constructor, to prevent instantiation. This class has only static methods.

Method Detail

copy

public static long copy(java.io.InputStream pInputStream,
                        java.io.OutputStream pOutputStream,
                        boolean pClose)
                 throws java.io.IOException
Copies the contents of the given InputStream to the given OutputStream. Shortcut for
   copy(pInputStream, pOutputStream, new byte[8192]);
 

Parameters:
pInputStream - The input stream, which is being read. It is guaranteed, that InputStream.close() is called on the stream.
pOutputStream - The output stream, to which data should be written. May be null, in which case the input streams contents are simply discarded.
pClose - True guarantees, that OutputStream.close() is called on the stream. False indicates, that only OutputStream.flush() should be called finally.
Returns:
Number of bytes, which have been copied.
Throws:
java.io.IOException - An I/O error occurred.

copy

public static long copy(java.io.InputStream pIn,
                        java.io.OutputStream pOut,
                        boolean pClose,
                        byte[] pBuffer)
                 throws java.io.IOException
Copies the contents of the given InputStream to the given OutputStream.

Parameters:
pIn - The input stream, which is being read. It is guaranteed, that InputStream.close() is called on the stream.
pOut - The output stream, to which data should be written. May be null, in which case the input streams contents are simply discarded.
pClose - True guarantees, that OutputStream.close() is called on the stream. False indicates, that only OutputStream.flush() should be called finally.
pBuffer - Temporary buffer, which is to be used for copying data.
Returns:
Number of bytes, which have been copied.
Throws:
java.io.IOException - An I/O error occurred.

asString

public static java.lang.String asString(java.io.InputStream pStream)
                                 throws java.io.IOException
This convenience method allows to read a FileItemStream's content into a string. The platform's default character encoding is used for converting bytes into characters.

Parameters:
pStream - The input stream to read.
Returns:
The streams contents, as a string.
Throws:
java.io.IOException - An I/O error occurred.
See Also:
asString(InputStream, String)

asString

public static java.lang.String asString(java.io.InputStream pStream,
                                        java.lang.String pEncoding)
                                 throws java.io.IOException
This convenience method allows to read a FileItemStream's content into a string, using the given character encoding.

Parameters:
pStream - The input stream to read.
pEncoding - The character encoding, typically "UTF-8".
Returns:
The streams contents, as a string.
Throws:
java.io.IOException - An I/O error occurred.
See Also:
asString(InputStream)