Class IOUtil
- java.lang.Object
-
- org.jboss.shrinkwrap.impl.base.io.IOUtil
-
public final class IOUtil extends java.lang.ObjectGeneric input/output utilities- Version:
- $Revision: $
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringCHARSET_UTF8Name of UTF-8 Charsetprivate static StreamErrorHandlerDEFAULT_ERROR_HANDLERDefault Error Handlerprivate static java.util.logging.LoggerlogLogger
-
Constructor Summary
Constructors Modifier Constructor Description privateIOUtil()Internal constructor; should not be called
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]asByteArray(java.io.InputStream in)Obtains the contents of the specified stream as a byte arraystatic java.lang.StringasUTF8String(java.io.InputStream in)Obtains the contents of the specified stream as a String in UTF-8 charset.static voidbufferedWriteWithFlush(java.io.OutputStream output, byte[] content)Writing the specified contents to the specified OutputStream using an internal buffer.static <S extends java.io.Closeable>
voidcloseOnComplete(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>
voidcloseOnComplete(S stream, StreamTask<S> task, StreamErrorHandler errorHandler)Helper method to run a specified task and automatically handle the closing of the stream.static voidcopy(java.io.InputStream input, java.io.OutputStream output)Copies the contents from an InputStream to an OutputStream.static intcopy(java.io.InputStream input, java.io.OutputStream output, int len)Copies the specified number of bytes from an InputStream to an OutputStream.static voidcopyWithClose(java.io.InputStream input, java.io.OutputStream output)Copies the contents from an InputStream to an OutputStream and closes both streams.
-
-
-
Field Detail
-
log
private static final java.util.logging.Logger log
Logger
-
DEFAULT_ERROR_HANDLER
private static final StreamErrorHandler DEFAULT_ERROR_HANDLER
Default Error Handler
-
CHARSET_UTF8
private static final java.lang.String CHARSET_UTF8
Name of UTF-8 Charset- See Also:
- Constant Field Values
-
-
Method Detail
-
asByteArray
public static byte[] asByteArray(java.io.InputStream in) throws java.lang.IllegalArgumentExceptionObtains the contents of the specified stream as a byte array- Parameters:
in-- Returns:
- the byte[] for the given InputStream
- Throws:
java.lang.IllegalArgumentException- If the stream was not specified
-
asUTF8String
public static java.lang.String asUTF8String(java.io.InputStream in)
Obtains the contents of the specified stream as a String in UTF-8 charset.- Parameters:
in-- Throws:
java.lang.IllegalArgumentException- If the stream was not specified
-
copy
public static void copy(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOExceptionCopies the contents from an InputStream to an OutputStream. It is the responsibility of the caller to close the streams passed in when done, though theOutputStreamwill be fully flushed.- Parameters:
input-output-- Throws:
java.io.IOException- If a problem occurred during any I/O operations
-
copy
public static int copy(java.io.InputStream input, java.io.OutputStream output, int len) throws java.io.IOExceptionCopies the specified number of bytes from an InputStream to an OutputStream. It is the responsibility of the caller to close the streams passed in when done, though theOutputStreamwill be fully flushed.- Parameters:
input-output-len- the number of bytes to copy- Returns:
- number of bytes copied
- Throws:
java.io.IOException- If a problem occurred during any I/O operations
-
bufferedWriteWithFlush
public static void bufferedWriteWithFlush(java.io.OutputStream output, byte[] content) throws java.io.IOExceptionWriting the specified contents to the specified OutputStream using an internal buffer. Flushing the stream when completed. Caller is responsible for opening and closing the specified stream.- Parameters:
output- The OutputStreamcontent- The content to write to the specified stream- Throws:
java.io.IOException- If a problem occured during any I/O operations
-
copyWithClose
public static void copyWithClose(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOExceptionCopies the contents from an InputStream to an OutputStream and closes both streams.- Parameters:
input-output-- Throws:
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 atLevel.FINER
-
closeOnComplete
public static <S extends java.io.Closeable> void closeOnComplete(S stream, StreamTask<S> task)Helper method to run a specified task and automatically handle the closing of the stream.- Parameters:
stream-task-
-
closeOnComplete
public static <S extends java.io.Closeable> void closeOnComplete(S stream, StreamTask<S> task, StreamErrorHandler errorHandler)Helper method to run a specified task and automatically handle the closing of the stream.- Type Parameters:
S-- Parameters:
task-errorHandler-
-
-