public final class IOUtils
extends java.lang.Object
BufferedInputStream
or BufferedReader. The default buffer size of 4K has been shown
to be efficient in tests.
Wherever possible, the methods in this class do not flush or close
the stream. This is to avoid making non-portable assumptions about the
streams' origin and further use. Thus the caller is still responsible for
closing streams after use.
Origin of code: Excalibur.| Modifier and Type | Method and Description |
|---|---|
static int |
copy(java.io.InputStream input,
java.io.OutputStream output)
Copy bytes from an
InputStream to an
OutputStream. |
static long |
copyLarge(java.io.InputStream input,
java.io.OutputStream output)
Copy bytes from a large (over 2GB)
InputStream to an
OutputStream. |
static long |
copyLarge(java.io.InputStream input,
java.io.OutputStream output,
byte[] buffer)
Copy bytes from a large (over 2GB)
InputStream to an
OutputStream. |
static byte[] |
toByteArray(java.io.InputStream input) |
public static byte[] toByteArray(java.io.InputStream input)
throws java.io.IOException
java.io.IOExceptionpublic static int copy(java.io.InputStream input,
java.io.OutputStream output)
throws java.io.IOException
InputStream to an
OutputStream.
This method buffers the input internally, so there is no need to use a
BufferedInputStream.
Large streams (over 2GB) will return a bytes copied value of
-1 after the copy has completed since the correct
number of bytes cannot be returned as an int. For large streams
use the copyLarge(InputStream, OutputStream) method.input - the InputStream to read fromoutput - the OutputStream to write tojava.lang.NullPointerException - if the input or output is nulljava.io.IOException - if an I/O error occurspublic static long copyLarge(java.io.InputStream input,
java.io.OutputStream output)
throws java.io.IOException
InputStream to an
OutputStream.
This method buffers the input internally, so there is no need to use a
BufferedInputStream.
The buffer size is given by DEFAULT_BUFFER_SIZE.input - the InputStream to read fromoutput - the OutputStream to write tojava.lang.NullPointerException - if the input or output is nulljava.io.IOException - if an I/O error occurspublic static long copyLarge(java.io.InputStream input,
java.io.OutputStream output,
byte[] buffer)
throws java.io.IOException
InputStream to an
OutputStream.
This method uses the provided buffer, so there is no need to use a
BufferedInputStream.input - the InputStream to read fromoutput - the OutputStream to write tobuffer - the buffer to use for the copyjava.lang.NullPointerException - if the input or output is nulljava.io.IOException - if an I/O error occurs