to top
public class

StreamUtil

extends Object
java.lang.Object
   ↳ com.android.tradefed.util.StreamUtil

Class Overview

Utility class for managing input streams.

Summary

Public Methods
static String calculateMd5(InputStream inputSource)
Helper method to calculate md5 for a inputStream.
static void cancel(InputStreamSource outputSource)
Cancels the given InputStreamSource if non-null.
static void close(Closeable closeable)
Closes the given Closeable.
static void closeGZipStream(GZIPOutputStream outStream)
Closes given gzip output stream.
static void closeStream(OutputStream out)
This method is deprecated. use close(Closeable) instead.
static void closeStream(InputStream in)
This method is deprecated. use close(Closeable) instead.
static void closeZipStream(ZipOutputStream outStream)
Closes given zip output stream.
static void copyStreamToWriter(InputStream inStream, Writer writer)
Copies contents of inStream to writer.
static void copyStreams(InputStream inStream, OutputStream outStream)
Copies contents of origStream to destStream.
static void flushAndCloseStream(OutputStream outStream)
Attempts to flush the given output stream, and then closes it.
static ByteArrayList getByteArrayListFromSource(InputStreamSource source)
Retrieves a ByteArrayList from an InputStreamSource.
static ByteArrayList getByteArrayListFromStream(InputStream stream)
Retrieves a ByteArrayList from a byte stream.
static String getStackTrace(Throwable throwable)
Gets the stack trace as a String.
static String getStringFromSource(InputStreamSource source)
Retrieves a String from an InputStreamSource.
static String getStringFromStream(InputStream stream)
Retrieves a String from a character stream.
static OutputStream nullOutputStream()
Create a OutputStream that discards all writes.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static String calculateMd5 (InputStream inputSource)

Helper method to calculate md5 for a inputStream. The inputStream will be consumed and closed.

Parameters
inputSource InputStream: used to create inputStream
Returns
String md5 of the stream
Throws
IOException

public static void cancel (InputStreamSource outputSource)

Cancels the given InputStreamSource if non-null.

Parameters
outputSource InputStreamSource

public static void close (Closeable closeable)

Closes the given Closeable.

Parameters
closeable Closeable: the Closeable. No action taken if null.

public static void closeGZipStream (GZIPOutputStream outStream)

Closes given gzip output stream.

Parameters
outStream GZIPOutputStream: the ZipOutputStream. No action taken if outStream is null.

public static void closeStream (OutputStream out)

This method is deprecated.
use close(Closeable) instead.

Parameters
out OutputStream

public static void closeStream (InputStream in)

This method is deprecated.
use close(Closeable) instead.

Parameters
in InputStream

public static void closeZipStream (ZipOutputStream outStream)

Closes given zip output stream.

Parameters
outStream ZipOutputStream: the ZipOutputStream. No action taken if outStream is null.

public static void copyStreamToWriter (InputStream inStream, Writer writer)

Copies contents of inStream to writer.

Recommended to provide a buffered stream for input and output

Parameters
inStream InputStream: the InputStream
writer Writer: the Writer destination
Throws
IOException

public static void copyStreams (InputStream inStream, OutputStream outStream)

Copies contents of origStream to destStream.

Recommended to provide a buffered stream for input and output

Parameters
inStream InputStream: the InputStream
outStream OutputStream: the OutputStream
Throws
IOException

public static void flushAndCloseStream (OutputStream outStream)

Attempts to flush the given output stream, and then closes it.

Parameters
outStream OutputStream: the OutputStream. No action taken if outStream is null.

public static ByteArrayList getByteArrayListFromSource (InputStreamSource source)

Retrieves a ByteArrayList from an InputStreamSource.

Parameters
source InputStreamSource: the InputStreamSource
Returns
ByteArrayList a ByteArrayList containing the stream contents
Throws
IOException if failure occurred reading the stream

public static ByteArrayList getByteArrayListFromStream (InputStream stream)

Retrieves a ByteArrayList from a byte stream.

Parameters
stream InputStream: the InputStream
Returns
ByteArrayList a ByteArrayList containing the stream contents
Throws
IOException if failure occurred reading the stream

public static String getStackTrace (Throwable throwable)

Gets the stack trace as a String.

Parameters
throwable Throwable: the Throwable to convert.
Returns
String a String stack trace

public static String getStringFromSource (InputStreamSource source)

Retrieves a String from an InputStreamSource.

Parameters
source InputStreamSource: the InputStreamSource
Returns
String a String containing the stream contents
Throws
IOException if failure occurred reading the stream

public static String getStringFromStream (InputStream stream)

Retrieves a String from a character stream.

Parameters
stream InputStream: the InputStream
Returns
String a String containing the stream contents
Throws
IOException if failure occurred reading the stream

public static OutputStream nullOutputStream ()

Create a OutputStream that discards all writes. TODO: replace with guava's ByteStreams.nullOutputStream() when guava is updated.

Returns
OutputStream