Class IOUtil
java.lang.Object
org.jboss.shrinkwrap.impl.base.io.IOUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]Obtains the contents of the specified stream as a byte arraystatic StringObtains the contents of the specified stream as a String in UTF-8 charset.static voidbufferedWriteWithFlush(OutputStream output, byte[] content) Writing the specified contents to the specified OutputStream using an internal buffer.static <S extends 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 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(InputStream input, OutputStream output) Copies the contents from an InputStream to an OutputStream.static intcopy(InputStream input, OutputStream output, int len) Copies the specified number of bytes from an InputStream to an OutputStream.static voidcopyWithClose(InputStream input, OutputStream output) Copies the contents from an InputStream to an OutputStream and closes both streams.
-
Method Details
-
asByteArray
Obtains the contents of the specified stream as a byte array- Parameters:
in- The input stream to be read- Returns:
- the byte[] for the given InputStream
- Throws:
IllegalArgumentException- If the stream was not specified
-
asUTF8String
Obtains the contents of the specified stream as a String in UTF-8 charset.- Parameters:
in- The input stream to be read- Throws:
IllegalArgumentException- If the stream was not specified
-
copy
Copies 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- The input stream from which to read the dataoutput- The output stream to which the data will be written- Throws:
IOException- If a problem occurred during any I/O operations
-
copy
Copies 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- The input stream from which to read the dataoutput- The output stream to which the data will be writtenlen- the number of bytes to copy- Returns:
- number of bytes copied
- Throws:
IOException- If a problem occurred during any I/O operations
-
bufferedWriteWithFlush
Writing 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:
IOException- If a problem occurred during any I/O operations
-
copyWithClose
Copies the contents from an InputStream to an OutputStream and closes both streams.- Parameters:
input- The input stream from which to read the dataoutput- The output stream to which the data will be written- Throws:
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
Helper method to run a specified task and automatically handle the closing of the stream.- Parameters:
stream- The stream to be closed after the task is executedtask- The task to be executed
-
closeOnComplete
public static <S extends 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- The type of the stream- Parameters:
stream- The stream to be closed after the task is executedtask- The task to be executederrorHandler- The error handler to handle any errors that occur during the execution of the task
-