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 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.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static void cancel (InputStreamSource outputSource)

Cancels the given InputStreamSource if non-null.

public static void close (Closeable closeable)

Closes the given Closeable.

Parameters
closeable the Closeable. No action taken if null.

public static void closeGZipStream (GZIPOutputStream outStream)

Closes given gzip output stream.

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

public static void closeStream (OutputStream out)

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

public static void closeStream (InputStream in)

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

public static void closeZipStream (ZipOutputStream outStream)

Closes given zip output stream.

Parameters
outStream 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 the InputStream
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 the InputStream
outStream the OutputStream
Throws
IOException

public static void flushAndCloseStream (OutputStream outStream)

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

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

public static ByteArrayList getByteArrayListFromSource (InputStreamSource source)

Retrieves a ByteArrayList from an InputStreamSource.

Parameters
source the InputStreamSource
Returns
Throws
IOException if failure occurred reading the stream

public static ByteArrayList getByteArrayListFromStream (InputStream stream)

Retrieves a ByteArrayList from a byte stream.

Parameters
stream the InputStream
Returns
Throws
IOException if failure occurred reading the stream

public static String getStackTrace (Throwable throwable)

Gets the stack trace as a String.

Parameters
throwable the Throwable to convert.
Returns

public static String getStringFromSource (InputStreamSource source)

Retrieves a String from an InputStreamSource.

Parameters
source the InputStreamSource
Returns
  • 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 the InputStream
Returns
  • a String containing the stream contents
Throws
IOException if failure occurred reading the stream