public final class IOUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
CHARSET_UTF8
Name of UTF-8 Charset
|
private static StreamErrorHandler |
DEFAULT_ERROR_HANDLER
Default Error Handler
|
private static java.util.logging.Logger |
log
Logger
|
Modifier | Constructor and Description |
---|---|
private |
IOUtil()
Internal constructor; should not be called
|
Modifier and Type | Method and Description |
---|---|
static byte[] |
asByteArray(java.io.InputStream in)
Obtains the contents of the specified stream as a byte array
|
static java.lang.String |
asUTF8String(java.io.InputStream in)
Obtains the contents of the specified stream as a String in UTF-8 charset.
|
static void |
bufferedWriteWithFlush(java.io.OutputStream output,
byte[] content)
Writing the specified contents to the specified OutputStream using an internal buffer.
|
static <S extends java.io.Closeable> |
closeOnComplete(S stream,
StreamTask<S> task)
Helper method to run a specified task and automatically handle the closing of the stream.
|
static <S extends java.io.Closeable> |
closeOnComplete(S stream,
StreamTask<S> task,
StreamErrorHandler errorHandler)
Helper method to run a specified task and automatically handle the closing of the stream.
|
static void |
copy(java.io.InputStream input,
java.io.OutputStream output)
Copies the contents from an InputStream to an OutputStream.
|
static int |
copy(java.io.InputStream input,
java.io.OutputStream output,
int len)
Copies the specified number of bytes from an InputStream to an OutputStream.
|
static void |
copyWithClose(java.io.InputStream input,
java.io.OutputStream output)
Copies the contents from an InputStream to an OutputStream and closes both streams.
|
private static final java.util.logging.Logger log
private static final StreamErrorHandler DEFAULT_ERROR_HANDLER
private static final java.lang.String CHARSET_UTF8
public static byte[] asByteArray(java.io.InputStream in) throws java.lang.IllegalArgumentException
in
- java.lang.IllegalArgumentException
- If the stream was not specifiedpublic static java.lang.String asUTF8String(java.io.InputStream in)
in
- java.lang.IllegalArgumentException
- If the stream was not specifiedpublic static void copy(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOException
OutputStream
will be fully flushed.input
- output
- java.io.IOException
- If a problem occurred during any I/O operationspublic static int copy(java.io.InputStream input, java.io.OutputStream output, int len) throws java.io.IOException
OutputStream
will be fully flushed.input
- output
- len
- the number of bytes to copyjava.io.IOException
- If a problem occurred during any I/O operationspublic static void bufferedWriteWithFlush(java.io.OutputStream output, byte[] content) throws java.io.IOException
output
- The OutputStreamcontent
- The content to write to the specified streamjava.io.IOException
- If a problem occured during any I/O operationspublic static void copyWithClose(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOException
input
- output
- java.io.IOException
- If a problem occurred during any I/O operations during the copy, but on closing the streams these
will be ignored and logged at Level.FINER
public static <S extends java.io.Closeable> void closeOnComplete(S stream, StreamTask<S> task)
stream
- task
- public static <S extends java.io.Closeable> void closeOnComplete(S stream, StreamTask<S> task, StreamErrorHandler errorHandler)
S
- task
- errorHandler
-