Package com.google.api.client.util
Class IOUtils
- java.lang.Object
-
- com.google.api.client.util.IOUtils
-
public class IOUtils extends Object
Utilities for I/O streams.- Since:
- 1.14
- Author:
- Yaniv Inbar
-
-
Constructor Summary
Constructors Constructor Description IOUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
computeLength(StreamingContent content)
Computes and returns the byte content length for a streaming content by callingStreamingContent.writeTo(OutputStream)
on a fake output stream that only counts bytes written.static void
copy(InputStream inputStream, OutputStream outputStream)
Writes the content provided by the given source input stream into the given destination output stream.static void
copy(InputStream inputStream, OutputStream outputStream, boolean closeInputStream)
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>
Sdeserialize(byte[] bytes)
Deserializes the given byte array into to a newly allocated object.static <S extends Serializable>
Sdeserialize(InputStream inputStream)
Deserializes the given input stream into to a newly allocated object, and close the input stream.static boolean
isSymbolicLink(File file)
Returns whether the given file is a symbolic link.static byte[]
serialize(Object value)
Serializes the given object value to a newly allocated byte array.static void
serialize(Object value, OutputStream outputStream)
Serializes the given object value to an output stream, and close the output stream.
-
-
-
Method Detail
-
copy
public static void copy(InputStream inputStream, OutputStream outputStream) throws IOException
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:
inputStream
- source input streamoutputStream
- destination output stream- Throws:
IOException
-
copy
public static void copy(InputStream inputStream, OutputStream outputStream, boolean closeInputStream) throws IOException
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:
inputStream
- source input streamoutputStream
- destination output streamcloseInputStream
- whether the input stream should be closed at the end of this method- Throws:
IOException
-
computeLength
public static long computeLength(StreamingContent content) throws IOException
Computes and returns the byte content length for a streaming content by callingStreamingContent.writeTo(OutputStream)
on a fake output stream that only counts bytes written.- Parameters:
content
- streaming content- Throws:
IOException
-
serialize
public static byte[] serialize(Object value) throws IOException
Serializes the given object value to a newly allocated byte array.- Parameters:
value
- object value to serialize- Throws:
IOException
- Since:
- 1.16
-
serialize
public static void serialize(Object value, OutputStream outputStream) throws IOException
Serializes the given object value to an output stream, and close the output stream.- Parameters:
value
- object value to serializeoutputStream
- output stream to serialize into- Throws:
IOException
- Since:
- 1.16
-
deserialize
public static <S extends Serializable> S deserialize(byte[] bytes) throws IOException
Deserializes the given byte array into to a newly allocated object.- Parameters:
bytes
- byte array to deserialize ornull
fornull
result- Returns:
- new allocated object or
null
fornull
input - Throws:
IOException
- Since:
- 1.16
-
deserialize
public static <S extends Serializable> S deserialize(InputStream inputStream) throws IOException
Deserializes the given input stream into to a newly allocated object, and close the input stream.- Parameters:
inputStream
- input stream to deserialize- Throws:
IOException
- Since:
- 1.16
-
isSymbolicLink
public static boolean isSymbolicLink(File file) throws IOException
Returns whether the given file is a symbolic link.- Throws:
IOException
- Since:
- 1.16
-
-