public class IOUtils extends Object
| Constructor and Description |
|---|
IOUtils()
|
| Modifier and Type | Method and Description |
|---|---|
static long |
computeLength(StreamingContent
Computes and returns the byte content length for a streaming content by calling
StreamingContent on a fake output stream that only counts bytes written.
|
static void |
copy(InputStream
Writes the content provided by the given source input stream into the given destination output stream.
|
static void |
copy(InputStream
Writes the content provided by the given source input stream into the given destination output stream, optionally closing the input stream.
|
static <S extends Serializable |
deserialize(byte[] bytes)
Deserializes the given byte array into to a newly allocated object.
|
static <S extends Serializable |
deserialize(InputStream
Deserializes the given input stream into to a newly allocated object, and close the input stream.
|
static boolean |
isSymbolicLink(File
Returns whether the given file is a symbolic link.
|
static byte[] |
serialize(Object
Serializes the given object value to a newly allocated byte array.
|
static void |
serialize(Object
Serializes the given object value to an output stream, and close the output stream.
|
public static void copy(InputStreaminputStream, OutputStream outputStream) throws IOException
The input stream is guaranteed to be closed at the end of this method.
Sample use:
static void copy(InputStream inputStream, File file) throws IOException {
FileOutputStream out = new FileOutputStream(file);
try {
IOUtils.copy(inputStream, out);
} finally {
out.close();
}
}
inputStream - source input stream
outputStream - destination output stream
IOException
public static void copy(InputStreaminputStream, OutputStream outputStream, boolean closeInputStream) throws IOException
Sample use:
static void copy(InputStream inputStream, File file) throws IOException {
FileOutputStream out = new FileOutputStream(file);
try {
IOUtils.copy(inputStream, out, true);
} finally {
out.close();
}
}
inputStream - source input stream
outputStream - destination output stream
closeInputStream - whether the input stream should be closed at the end of this method
IOException
public static long computeLength(StreamingContentcontent) throws IOException
StreamingContent.writeTo(OutputStream) on a fake output stream that only counts bytes written.
content - streaming content
IOException
public static byte[] serialize(Objectvalue) throws IOException
value - object value to serialize
IOException
public static void serialize(Objectvalue, OutputStream outputStream) throws IOException
value - object value to serialize
outputStream - output stream to serialize into
IOException
public static <S extends Serializable> S deserialize(byte[] bytes) throws IOException
bytes - byte array to deserialize or
null for
null result
null for
null input
IOException
public static <S extends Serializable> S deserialize(InputStream inputStream) throws IOException
inputStream - input stream to deserialize
IOException
public static boolean isSymbolicLink(Filefile) throws IOException
IOException