com.android.volley.toolbox
Class PoolingByteArrayOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.ByteArrayOutputStream
          extended by com.android.volley.toolbox.PoolingByteArrayOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class PoolingByteArrayOutputStream
extends ByteArrayOutputStream

A variation of ByteArrayOutputStream that uses a pool of byte[] buffers instead of always allocating them fresh, saving on heap churn.


Field Summary
 
Fields inherited from class java.io.ByteArrayOutputStream
buf, count
 
Constructor Summary
PoolingByteArrayOutputStream(ByteArrayPool pool)
          Constructs a new PoolingByteArrayOutputStream with a default size.
PoolingByteArrayOutputStream(ByteArrayPool pool, int size)
          Constructs a new ByteArrayOutputStream with a default size of size bytes.
 
Method Summary
 void close()
           
 void finalize()
           
 void write(byte[] buffer, int offset, int len)
           
 void write(int oneByte)
           
 
Methods inherited from class java.io.ByteArrayOutputStream
reset, size, toByteArray, toString, toString, toString, writeTo
 
Methods inherited from class java.io.OutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PoolingByteArrayOutputStream

public PoolingByteArrayOutputStream(ByteArrayPool pool)
Constructs a new PoolingByteArrayOutputStream with a default size. If more bytes are written to this instance, the underlying byte array will expand.


PoolingByteArrayOutputStream

public PoolingByteArrayOutputStream(ByteArrayPool pool,
                                    int size)
Constructs a new ByteArrayOutputStream with a default size of size bytes. If more than size bytes are written to this instance, the underlying byte array will expand.

Parameters:
size - initial size for the underlying byte array. The value will be pinned to a default minimum size.
Method Detail

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class ByteArrayOutputStream
Throws:
IOException

finalize

public void finalize()
Overrides:
finalize in class Object

write

public void write(byte[] buffer,
                  int offset,
                  int len)
Overrides:
write in class ByteArrayOutputStream

write

public void write(int oneByte)
Overrides:
write in class ByteArrayOutputStream