Class IOUtils (1.43.2)

public class IOUtils

Utilities for I/O streams.

Inheritance

Object > IOUtils

Static Methods

<S>deserialize(byte[] bytes)

public static S <S>deserialize(byte[] bytes)

Deserializes the given byte array into to a newly allocated object.

Parameter
Name Description
bytes byte[]

byte array to deserialize or null for null result

Returns
Type Description
S

new allocated object or null for null input

Exceptions
Type Description
IOException

<S>deserialize(InputStream inputStream)

public static S <S>deserialize(InputStream inputStream)

Deserializes the given input stream into to a newly allocated object, and close the input stream.

Parameter
Name Description
inputStream InputStream

input stream to deserialize

Returns
Type Description
S
Exceptions
Type Description
IOException

computeLength(StreamingContent content)

public static long computeLength(StreamingContent content)

Computes and returns the byte content length for a streaming content by calling StreamingContent#writeTo(OutputStream) on a fake output stream that only counts bytes written.

Parameter
Name Description
content StreamingContent

streaming content

Returns
Type Description
long
Exceptions
Type Description
IOException

copy(InputStream inputStream, OutputStream outputStream) (deprecated)

public static void copy(InputStream inputStream, OutputStream outputStream)

Deprecated. use com.google.common.io.ByteStreams#copy(InputStream, OutputStream)

Writes the content provided by the given source input stream into the given destination output stream.

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(); } }

Parameters
Name Description
inputStream InputStream

source input stream

outputStream OutputStream

destination output stream

Exceptions
Type Description
IOException

copy(InputStream inputStream, OutputStream outputStream, boolean closeInputStream) (deprecated)

public static void copy(InputStream inputStream, OutputStream outputStream, boolean closeInputStream)

Deprecated. use com.google.common.io.ByteStreams#copy(InputStream, OutputStream)

Writes the content provided by the given source input stream into the given destination output stream, optionally closing the input stream.

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(); } }

Parameters
Name Description
inputStream InputStream

source input stream

outputStream OutputStream

destination output stream

closeInputStream boolean

whether the input stream should be closed at the end of this method

Exceptions
Type Description
IOException
public static boolean isSymbolicLink(File file)

Deprecated. use java.nio.file.Path#isSymbolicLink

Returns whether the given file is a symbolic link.

Parameter
Name Description
file File
Returns
Type Description
boolean
Exceptions
Type Description
IOException

serialize(Object value)

public static byte[] serialize(Object value)

Serializes the given object value to a newly allocated byte array.

Parameter
Name Description
value Object

object value to serialize

Returns
Type Description
byte[]
Exceptions
Type Description
IOException

serialize(Object value, OutputStream outputStream)

public static void serialize(Object value, OutputStream outputStream)

Serializes the given object value to an output stream, and close the output stream.

Parameters
Name Description
value Object

object value to serialize

outputStream OutputStream

output stream to serialize into

Exceptions
Type Description
IOException

Constructors

IOUtils()

public IOUtils()