to top
public class

SizeLimitedOutputStream

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

Class Overview

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)
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)
[Expand]
Inherited Methods
From class java.io.OutputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable
From interface java.lang.AutoCloseable

Public Constructors

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

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

public void close ()

Closes the write stream

public void delete ()

Delete all accumulated data.

public void flush ()

public 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

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

Parameters
b byte
off int
len int
Throws
IOException

public void write (int data)

Parameters
data int
Throws
IOException