org.jboss.portal.common.io
Class IOTools

java.lang.Object
  extended by org.jboss.portal.common.io.IOTools

public class IOTools
extends java.lang.Object

IO tools.

Version:
$Revision: 1.1 $
Author:
Julien Viet

Field Summary
static org.apache.log4j.Logger log
          The logger.
 
Constructor Summary
IOTools()
           
 
Method Summary
static java.lang.Object clone(java.io.Serializable serializable)
          Clone an object implementing the Serializable interface.
static void copy(java.io.InputStream in, java.io.OutputStream out)
           
static void copy(java.io.InputStream in, java.io.OutputStream out, int bufferSize)
          Pipe an incoming stream in an outcoming stream until no bytes is available from the input stream.
static void copy(java.io.Reader reader, java.io.Writer writer)
          Pipe an input stream in an output stream.
static void copy(java.io.Reader reader, java.io.Writer writer, int bufferSize)
          Pipe an incoming stream in an outcoming stream.
static byte[] getBytes(java.io.InputStream in)
           
static byte[] getBytes(java.io.InputStream in, int bufferSize)
          Get the bytes from the provided input stream.
static java.io.BufferedInputStream safeBufferedWrapper(java.io.InputStream in)
          Check that the provided input stream is buffered.
static java.io.BufferedOutputStream safeBufferedWrapper(java.io.OutputStream out)
          Check that the provided output stream is buffered.
static void safeClose(java.io.InputStream in)
          Attempt to close an InputStream.
static void safeClose(java.lang.Object closable)
          Attempt to close an object.
static void safeClose(java.io.OutputStream out)
          Attempt to close an OutputStream.
static void safeClose(java.io.Reader reader)
          Attempt to close an Reader.
static void safeClose(java.io.Writer writer)
          Attempt to close an Writer.
static byte[] serialize(java.io.Serializable serializable)
           
static
<T> byte[]
serialize(Serialization<T> serialization, SerializationFilter filter, T t)
           
static
<T> byte[]
serialize(Serialization<T> serialization, T t)
           
static java.io.Serializable unserialize(byte[] bytes)
           
static
<T> T
unserialize(Serialization<T> serialization, byte[] bytes)
           
static
<T> T
unserialize(Serialization<T> serialization, SerializationFilter filter, byte[] bytes)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final org.apache.log4j.Logger log
The logger.

Constructor Detail

IOTools

public IOTools()
Method Detail

safeClose

public static void safeClose(java.lang.Object closable)

Attempt to close an object. Null argument value is authorized and no operation will be performed in that use case.

It will try to obtain a close() method by reflection and it will be invoked only if the method is public and not static. If the method is called, any Error or RuntimeException will be rethrown, any other kind of throwable will not be rethrown in any form.

Parameters:
closable - the object to close

safeClose

public static void safeClose(java.io.OutputStream out)

Attempt to close an OutputStream. Null argument value is authorized and no operation will be performed in that use case.

Parameters:
out - the stream to close

safeClose

public static void safeClose(java.io.InputStream in)

Attempt to close an InputStream. Null argument value is authorized and no operation will be performed in that use case.

Parameters:
in - the stream to close

safeClose

public static void safeClose(java.io.Reader reader)

Attempt to close an Reader. Null argument value is authorized and no operation will be performed in that use case.

Parameters:
reader - the stream to close

safeClose

public static void safeClose(java.io.Writer writer)

Attempt to close an Writer. Null argument value is authorized and no operation will be performed in that use case.

Parameters:
writer - the stream to close

getBytes

public static byte[] getBytes(java.io.InputStream in)
                       throws java.io.IOException,
                              java.lang.IllegalArgumentException
Parameters:
in - the input stream
Returns:
the bytes read from the stream
Throws:
java.io.IOException
java.lang.IllegalArgumentException - if the input stream is null
See Also:
getBytes(java.io.InputStream, int)

getBytes

public static byte[] getBytes(java.io.InputStream in,
                              int bufferSize)
                       throws java.io.IOException,
                              java.lang.IllegalArgumentException
Get the bytes from the provided input stream. No attempt will be made to close the stream.

Parameters:
in - the input stream
bufferSize - the buffer size used to copy the bytes
Returns:
the bytes read from the stream
Throws:
java.io.IOException
java.lang.IllegalArgumentException - if the input stream is null or the buffer size < 1

copy

public static void copy(java.io.InputStream in,
                        java.io.OutputStream out)
                 throws java.io.IOException
Parameters:
in - the incoming stream
out - the outcoming stream
Throws:
java.lang.IllegalArgumentException - if an argument is null
java.io.IOException
See Also:
copy(java.io.InputStream, java.io.OutputStream, int)

copy

public static void copy(java.io.InputStream in,
                        java.io.OutputStream out,
                        int bufferSize)
                 throws java.io.IOException
Pipe an incoming stream in an outcoming stream until no bytes is available from the input stream. No attempts will be made to close the streams.

Parameters:
in - the incoming stream
out - the outcoming stream
bufferSize - the buffer size
Throws:
java.lang.IllegalArgumentException - if bufferSize < 1 or an argument is null
java.io.IOException

copy

public static void copy(java.io.Reader reader,
                        java.io.Writer writer)
                 throws java.io.IOException
Pipe an input stream in an output stream.

Parameters:
reader - the incoming reader
writer - the outcoming writer
Throws:
java.lang.IllegalArgumentException - if an argument is null
java.io.IOException

copy

public static void copy(java.io.Reader reader,
                        java.io.Writer writer,
                        int bufferSize)
                 throws java.io.IOException
Pipe an incoming stream in an outcoming stream.

Parameters:
reader - the incoming reader
writer - the outcoming writer
bufferSize - the buffer size
Throws:
java.lang.IllegalArgumentException - if bufferSize < 1 or an argument is null
java.io.IOException

clone

public static java.lang.Object clone(java.io.Serializable serializable)
                              throws java.lang.IllegalArgumentException,
                                     java.io.IOException
Clone an object implementing the Serializable interface.

Parameters:
serializable -
Returns:
Throws:
java.lang.IllegalArgumentException - if the serializable object is null
java.io.IOException

serialize

public static byte[] serialize(java.io.Serializable serializable)
                        throws java.lang.IllegalArgumentException,
                               java.io.IOException
Throws:
java.lang.IllegalArgumentException
java.io.IOException

unserialize

public static java.io.Serializable unserialize(byte[] bytes)
                                        throws java.lang.IllegalArgumentException,
                                               java.io.IOException,
                                               java.lang.ClassNotFoundException
Throws:
java.lang.IllegalArgumentException
java.io.IOException
java.lang.ClassNotFoundException

serialize

public static <T> byte[] serialize(Serialization<T> serialization,
                                   T t)

serialize

public static <T> byte[] serialize(Serialization<T> serialization,
                                   SerializationFilter filter,
                                   T t)

unserialize

public static <T> T unserialize(Serialization<T> serialization,
                                byte[] bytes)

unserialize

public static <T> T unserialize(Serialization<T> serialization,
                                SerializationFilter filter,
                                byte[] bytes)

safeBufferedWrapper

public static java.io.BufferedInputStream safeBufferedWrapper(java.io.InputStream in)
Check that the provided input stream is buffered. If the argument is already an instance of BufferedInputStream no operation will be performed, otherwise a instance of BufferedInputStream will be created and returned. If the provided argument is null, the null value is returned.

Parameters:
in - the stream
Returns:
a buffered wrapper

safeBufferedWrapper

public static java.io.BufferedOutputStream safeBufferedWrapper(java.io.OutputStream out)
Check that the provided output stream is buffered. If the argument is already an instance of BufferedOutputStream no operation will be performed, otherwise a instance of BufferedOutputStream will be created and returned. If the provided argument is null, the null value is returned.

Parameters:
out - the stream
Returns:
a buffered wrapper