ShrinkWrap Aggregator and Build Parent 1.0.0-cr-1

org.jboss.shrinkwrap.impl.base.io
Class IOUtil

java.lang.Object
  extended by org.jboss.shrinkwrap.impl.base.io.IOUtil

public final class IOUtil
extends Object

Generic input/output utilities

Version:
$Revision: $
Author:
ALR

Method Summary
static byte[] asByteArray(InputStream in)
          Obtains the contents of the specified stream as a byte array
static String asUTF8String(InputStream in)
          Obtains the contents of the specified stream as a String in UTF-8 charset.
static void bufferedWriteWithFlush(OutputStream output, byte[] content)
          Writing the specified contents to the specified OutputStream using an internal buffer.
static
<S extends Closeable>
void
closeOnComplete(S stream, StreamTask<S> task)
          Helper method to run a specified task and automatically handle the closing of the stream.
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.
static void copy(InputStream input, OutputStream output)
          Copies the contents from an InputStream to an OutputStream.
static void copyWithClose(InputStream input, OutputStream output)
          Copies the contents from an InputStream to an OutputStream and closes both streams.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

asByteArray

public static byte[] asByteArray(InputStream in)
                          throws IllegalArgumentException
Obtains the contents of the specified stream as a byte array

Parameters:
in -
Returns:
the byte[] for the given InputStream
Throws:
IllegalArgumentException - If the stream was not specified

asUTF8String

public static String asUTF8String(InputStream in)
Obtains the contents of the specified stream as a String in UTF-8 charset.

Parameters:
in -
Throws:
IllegalArgumentException - If the stream was not specified

copy

public static void copy(InputStream input,
                        OutputStream output)
                 throws IOException
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 the OutputStream will be fully flushed.

Parameters:
input -
output -
Throws:
IOException - If a problem occurred during any I/O operations

bufferedWriteWithFlush

public static void bufferedWriteWithFlush(OutputStream output,
                                          byte[] content)
                                   throws IOException
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 OutputStream
content - The content to write to the specified stream
Throws:
IOException - If a problem occured during any I/O operations

copyWithClose

public static void copyWithClose(InputStream input,
                                 OutputStream output)
                          throws IOException
Copies the contents from an InputStream to an OutputStream and closes both streams.

Parameters:
input -
output -
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 at Level.FINER

closeOnComplete

public static <S extends 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 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 -

ShrinkWrap Aggregator and Build Parent 1.0.0-cr-1

Copyright © 2011 JBoss, a division of Red Hat, Inc.. All Rights Reserved.