SizeLimitedOutputStream

public class SizeLimitedOutputStream
extends Object

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


A thread safe file backed ERROR(/OutputStream) that limits the maximum amount of data that can be written.

This is implemented by keeping a circular list of Files of fixed size. Once a File has reached a certain size, the class jumps to use the next File in the list. If the next File is non empty, it is deleted, and a new file created.

Summary

Public constructors

SizeLimitedOutputStream(long maxDataSize, int numFiles, String tempFilePrefix, String tempFileSuffix)

Creates a SizeLimitedOutputStream.

SizeLimitedOutputStream(long maxDataSize, String tempFilePrefix, String tempFileSuffix)

Creates a SizeLimitedOutputStream with default number of backing files.

Public methods

void close()

Closes the write stream

void delete()

Delete all accumulated data.

void flush()

InputStream getData()

Gets the collected output as a ERROR(/InputStream).

void write(byte[] b, int off, int len)
void write(int data)

Public constructors

SizeLimitedOutputStream

public SizeLimitedOutputStream (long maxDataSize, 
                int numFiles, 
                String tempFilePrefix, 
                String tempFileSuffix)

Creates a SizeLimitedOutputStream.

Parameters
maxDataSize long: the approximate max size in bytes to keep in the output stream

numFiles int: the max number of backing files to use to store data. Higher values will mean max data kept will be close to maxDataSize, but with a possible performance penalty.

tempFilePrefix String: prefix to use for temporary files

tempFileSuffix String: suffix to use for temporary files

SizeLimitedOutputStream

public SizeLimitedOutputStream (long maxDataSize, 
                String tempFilePrefix, 
                String tempFileSuffix)

Creates a SizeLimitedOutputStream with default number of backing files.

Parameters
maxDataSize long: the approximate max size to keep in the output stream

tempFilePrefix String: prefix to use for temporary files

tempFileSuffix String: suffix to use for temporary files

Public methods

close

public void close ()

Closes the write stream

delete

public void delete ()

Delete all accumulated data.

flush

public void flush ()

getData

public InputStream getData ()

Gets the collected output as a ERROR(/InputStream).

It is recommended to buffer returned stream before using.

Returns
InputStream The collected output as a ERROR(/InputStream).

write

public void write (byte[] b, 
                int off, 
                int len)

Parameters
b byte

off int

len int

write

public void write (int data)

Parameters
data int