org.apache.hadoop.zebra.tfile
Class BoundedByteArrayOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.apache.hadoop.zebra.tfile.BoundedByteArrayOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class BoundedByteArrayOutputStream
extends OutputStream

A byte array backed output stream with a limit. The limit should be smaller than the buffer capacity. The object can be reused through reset API and choose different limits in each round.


Constructor Summary
BoundedByteArrayOutputStream(int capacity)
          Create a BoundedByteArrayOutputStream with the specified capacity
BoundedByteArrayOutputStream(int capacity, int limit)
          Create a BoundedByteArrayOutputStream with the specified capacity and limit.
 
Method Summary
 byte[] getBuffer()
          Returns the underlying buffer.
 int getLimit()
          Return the current limit
 void reset()
          Reset the buffer
 void reset(int newlim)
          Reset the limit
 int size()
          Returns the length of the valid data currently in the buffer.
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.io.OutputStream
close, flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BoundedByteArrayOutputStream

public BoundedByteArrayOutputStream(int capacity)
Create a BoundedByteArrayOutputStream with the specified capacity

Parameters:
capacity - The capacity of the underlying byte array

BoundedByteArrayOutputStream

public BoundedByteArrayOutputStream(int capacity,
                                    int limit)
Create a BoundedByteArrayOutputStream with the specified capacity and limit.

Parameters:
capacity - The capacity of the underlying byte array
limit - The maximum limit upto which data can be written
Method Detail

write

public void write(int b)
           throws IOException
Specified by:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Overrides:
write in class OutputStream
Throws:
IOException

reset

public void reset(int newlim)
Reset the limit

Parameters:
newlim - New Limit

reset

public void reset()
Reset the buffer


getLimit

public int getLimit()
Return the current limit


getBuffer

public byte[] getBuffer()
Returns the underlying buffer. Data is only valid to size().


size

public int size()
Returns the length of the valid data currently in the buffer.



Copyright © ${year} The Apache Software Foundation