SizeLimitedOutputStream

public class SizeLimitedOutputStream
extends OutputStream

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


A thread safe file backed 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 InputStream.

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

Public constructors

SizeLimitedOutputStream

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

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

void close ()

Closes the write stream

delete

void delete ()

Delete all accumulated data.

flush

void flush ()

getData

InputStream getData ()

Gets the collected output as a InputStream.

It is recommended to buffer returned stream before using.

Returns
InputStream The collected output as a InputStream.

Throws
IOException

write

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

Parameters
b byte

off int

len int

Throws
IOException

write

void write (int data)

Parameters
data int

Throws
IOException