Class IOUtils (1.42.3)

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
NameDescription
bytesbyte[]

byte array to deserialize or null for null result

Returns
TypeDescription
S

new allocated object or null for null input

Exceptions
TypeDescription
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
NameDescription
inputStreamInputStream

input stream to deserialize

Returns
TypeDescription
S
Exceptions
TypeDescription
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
NameDescription
contentStreamingContent

streaming content

Returns
TypeDescription
long
Exceptions
TypeDescription
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
NameDescription
inputStreamInputStream

source input stream

outputStreamOutputStream

destination output stream

Exceptions
TypeDescription
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
NameDescription
inputStreamInputStream

source input stream

outputStreamOutputStream

destination output stream

closeInputStreamboolean

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

Exceptions
TypeDescription
IOException
public static boolean isSymbolicLink(File file)

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

Returns whether the given file is a symbolic link.

Parameter
NameDescription
fileFile
Returns
TypeDescription
boolean
Exceptions
TypeDescription
IOException

serialize(Object value)

public static byte[] serialize(Object value)

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

Parameter
NameDescription
valueObject

object value to serialize

Returns
TypeDescription
byte[]
Exceptions
TypeDescription
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
NameDescription
valueObject

object value to serialize

outputStreamOutputStream

output stream to serialize into

Exceptions
TypeDescription
IOException

Constructors

IOUtils()

public IOUtils()