public class IOTools extends Object
| Constructor and Description |
|---|
IOTools() |
| Modifier and Type | Method and Description |
|---|---|
static <S extends Serializable> |
clone(S serializable)
Clone an object implementing the
Serializable interface. |
static <S extends Serializable> |
clone(S serializable,
ClassLoader classLoader)
Clone an object implementing the
Serializable interface. |
static void |
copy(InputStream in,
OutputStream out) |
static void |
copy(InputStream in,
OutputStream out,
int bufferSize)
Pipe an incoming stream in an outcoming stream until no bytes is available from the input stream.
|
static void |
copy(Reader reader,
Writer writer)
Pipe an input stream in an output stream.
|
static void |
copy(Reader reader,
Writer writer,
int bufferSize)
Pipe an incoming stream in an outcoming stream.
|
static byte[] |
getBytes(InputStream in) |
static byte[] |
getBytes(InputStream in,
int bufferSize)
Get the bytes from the provided input stream.
|
static BufferedInputStream |
safeBufferedWrapper(InputStream in)
Check that the provided input stream is buffered.
|
static BufferedOutputStream |
safeBufferedWrapper(OutputStream out)
Check that the provided output stream is buffered.
|
static void |
safeClose(Closeable out)
Attempt to close an
Closeable object. |
static void |
safeClose(Object closable)
Attempt to close an object.
|
static byte[] |
safeGetBytes(InputStream is) |
static byte[] |
serialize(Serializable serializable) |
static <T> byte[] |
serialize(Serialization<T> serialization,
SerializationFilter filter,
T t) |
static <T> byte[] |
serialize(Serialization<T> serialization,
T t) |
static Serializable |
unserialize(byte[] bytes)
Unserialize the bytes into an object.
|
static Serializable |
unserialize(byte[] bytes,
ClassLoader classLoader)
Unserialize the bytes into an object.
|
static <T> T |
unserialize(Serialization<T> serialization,
byte[] bytes) |
static <T> T |
unserialize(Serialization<T> serialization,
SerializationFilter filter,
byte[] bytes) |
public static final Logger log
public static void safeClose(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.
closable - the object to closepublic static void safeClose(Closeable out)
Attempt to close an Closeable object. Null argument value is authorized and no operation will be
performed in that use case. IOException thrown are logged using the error level but not
propagated.
out - the stream to closepublic static byte[] getBytes(InputStream in) throws IOException, IllegalArgumentException
in - the input streamIOExceptionIllegalArgumentException - if the input stream is nullgetBytes(java.io.InputStream, int)public static byte[] getBytes(InputStream in, int bufferSize) throws IOException, IllegalArgumentException
in - the input streambufferSize - the buffer size used to copy the bytesIOExceptionIllegalArgumentException - if the input stream is null or the buffer size < 1public static byte[] safeGetBytes(InputStream is)
public static void copy(InputStream in, OutputStream out) throws IOException
in - the incoming streamout - the outcoming streamIllegalArgumentException - if an argument is nullIOExceptioncopy(java.io.InputStream, java.io.OutputStream, int)public static void copy(InputStream in, OutputStream out, int bufferSize) throws IOException
in - the incoming streamout - the outcoming streambufferSize - the buffer sizeIllegalArgumentException - if bufferSize < 1 or an argument is nullIOExceptionpublic static void copy(Reader reader, Writer writer) throws IOException
reader - the incoming readerwriter - the outcoming writerIllegalArgumentException - if an argument is nullIOExceptionpublic static void copy(Reader reader, Writer writer, int bufferSize) throws IOException
reader - the incoming readerwriter - the outcoming writerbufferSize - the buffer sizeIllegalArgumentException - if bufferSize < 1 or an argument is nullIOExceptionpublic static <S extends Serializable> S clone(S serializable) throws IllegalArgumentException, IOException
Serializable interface.serializable - the serializable object to cloneIllegalArgumentException - if the serializable object is nullIOException - any IOExceptionpublic static <S extends Serializable> S clone(S serializable, ClassLoader classLoader) throws IllegalArgumentException, IOException, ClassNotFoundException
Serializable interface. The specified classloader will be used to
perform the unserialization. If no classloader is specified and the object is not null then the classloader used
is the one returned by serializable.getClass().getClassLoader().serializable - the serializable object to cloneIllegalArgumentException - if the serializable object is nullIOException - any IOExceptionClassNotFoundExceptionpublic static byte[] serialize(Serializable serializable) throws IllegalArgumentException, IOException
IllegalArgumentExceptionIOExceptionpublic static Serializable unserialize(byte[] bytes) throws IllegalArgumentException, IOException, ClassNotFoundException
bytes - the bytes to unserializeIllegalArgumentException - if the byte array is nullIOException - any IOExceptionClassNotFoundException - any ClassNotFoundExceptionpublic static Serializable unserialize(byte[] bytes, ClassLoader classLoader) throws IllegalArgumentException, IOException, ClassNotFoundException
bytes - the bytes to unserializeclassLoader - the classloaderIllegalArgumentException - if the byte array is nullIOException - any IOExceptionClassNotFoundException - any ClassNotFoundExceptionpublic static <T> byte[] serialize(Serialization<T> serialization, T t)
public static <T> byte[] serialize(Serialization<T> serialization, SerializationFilter filter, T t)
public static <T> T unserialize(Serialization<T> serialization, byte[] bytes)
public static <T> T unserialize(Serialization<T> serialization, SerializationFilter filter, byte[] bytes)
public static BufferedInputStream safeBufferedWrapper(InputStream in)
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.in - the streampublic static BufferedOutputStream safeBufferedWrapper(OutputStream out)
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.out - the streamCopyright © 2025 JBoss by Red Hat. All Rights Reserved.