StreamUtil

public class StreamUtil
extends Object

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


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 int countLinesFromSource(InputStreamSource source)

Count number of lines in an InputStreamSource

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.

Public methods

calculateMd5

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

cancel

void cancel (InputStreamSource outputSource)

Cancels the given InputStreamSource if non-null.

Parameters
outputSource InputStreamSource

close

void close (Closeable closeable)

Closes the given Closeable.

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

closeGZipStream

void closeGZipStream (GZIPOutputStream outStream)

Closes given gzip output stream.

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

closeStream

void closeStream (OutputStream out)

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

Parameters
out OutputStream

closeStream

void closeStream (InputStream in)

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

Parameters
in InputStream

closeZipStream

void closeZipStream (ZipOutputStream outStream)

Closes given zip output stream.

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

copyStreamToWriter

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

copyStreams

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

countLinesFromSource

int countLinesFromSource (InputStreamSource source)

Count number of lines in an InputStreamSource

Parameters
source InputStreamSource: the InputStreamSource
Returns
int number of lines
Throws
IOException if failure occurred reading the stream

flushAndCloseStream

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.

getByteArrayListFromSource

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

getByteArrayListFromStream

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

getStackTrace

String getStackTrace (Throwable throwable)

Gets the stack trace as a String.

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

getStringFromSource

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

getStringFromStream

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

nullOutputStream

OutputStream nullOutputStream ()

Create a OutputStream that discards all writes.

Returns
OutputStream