public final class IOUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static void |
closeQuietly(java.io.Closeable c)
Closes the given Closeable and swallows any IOException that may occur.
|
static long |
copy(java.io.InputStream input,
java.io.OutputStream output)
Copies the content of a InputStream into an OutputStream.
|
static long |
copy(java.io.InputStream input,
java.io.OutputStream output,
int buffersize)
Copies the content of a InputStream into an OutputStream
|
static int |
readFully(java.io.InputStream input,
byte[] b)
Reads as much from input as possible to fill the given array.
|
static int |
readFully(java.io.InputStream input,
byte[] b,
int offset,
int len)
Reads as much from input as possible to fill the given array
with the given amount of bytes.
|
static long |
skip(java.io.InputStream input,
long numToSkip)
Skips the given number of bytes by repeatedly invoking skip on
the given input stream if necessary.
|
static byte[] |
toByteArray(java.io.InputStream input)
Gets the contents of an
InputStream as a byte[]. |
public static long copy(java.io.InputStream input,
java.io.OutputStream output)
throws java.io.IOException
input - the InputStream to copyoutput - the target Streamjava.io.IOException - if an error occurspublic static long copy(java.io.InputStream input,
java.io.OutputStream output,
int buffersize)
throws java.io.IOException
input - the InputStream to copyoutput - the target Streambuffersize - the buffer size to usejava.io.IOException - if an error occurspublic static long skip(java.io.InputStream input,
long numToSkip)
throws java.io.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 innumToSkip - the number of bytes to skipjava.io.IOExceptionpublic static int readFully(java.io.InputStream input,
byte[] b)
throws java.io.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 fromb - buffer to filljava.io.IOExceptionpublic static int readFully(java.io.InputStream input,
byte[] b,
int offset,
int len)
throws java.io.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 fromb - buffer to filloffset - offset into the buffer to start filling atlen - of bytes to readjava.io.IOException - if an I/O error has occurredpublic static byte[] toByteArray(java.io.InputStream input)
throws java.io.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 fromjava.lang.NullPointerException - if the input is nulljava.io.IOException - if an I/O error occurspublic static void closeQuietly(java.io.Closeable c)
c - Closeable to close, can be null