public final class IOUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
closeQuietly(Closeable
Closes the given Closeable and swallows any IOException that may occur.
|
static long |
copy(InputStream
Copies the content of a InputStream into an OutputStream.
|
static long |
copy(InputStream
Copies the content of a InputStream into an OutputStream
|
static int |
readFully(InputStream
Reads as much from input as possible to fill the given array.
|
static int |
readFully(InputStream
Reads as much from input as possible to fill the given array with the given amount of bytes.
|
static long |
skip(InputStream
Skips the given number of bytes by repeatedly invoking skip on the given input stream if necessary.
|
static byte[] |
toByteArray(InputStream
Gets the contents of an
InputStream as a
byte[].
|
public static long copy(InputStreaminput, OutputStream output) throws IOException
input - the InputStream to copy
output - the target Stream
IOException - if an error occurs
public static long copy(InputStreaminput, OutputStream output, int buffersize) throws IOException
input - the InputStream to copy
output - the target Stream
buffersize - the buffer size to use
IOException - if an error occurs
public static long skip(InputStreaminput, long numToSkip) throws IOException
This method will only skip less than the requested number of bytes if the end of the input stream has been reached.
input - stream to skip bytes in
numToSkip - the number of bytes to skip
IOException -
public static int readFully(InputStreaminput, byte[] b) throws IOException
This method may invoke read repeatedly to fill the array and only read less bytes than the length of the array if the end of the stream has been reached.
input - stream to read from
b - buffer to fill
IOException -
public static int readFully(InputStreaminput, byte[] b, int offset, int len) throws IOException
This method may invoke read repeatedly to read the bytes and only read less bytes than the requested length if the end of the stream has been reached.
input - stream to read from
b - buffer to fill
offset - offset into the buffer to start filling at
len - of bytes to read
IOException - if an I/O error has occurred
public static byte[] toByteArray(InputStreaminput) throws IOException
InputStream as a
byte[].
This method buffers the input internally, so there is no need to use a BufferedInputStream.
input - the
InputStream to read from
NullPointerException - if the input is null
IOException - if an I/O error occurs
public static void closeQuietly(Closeablec)
c - Closeable to close, can be null