Package org.apache.hadoop.io
Class BoundedByteArrayOutputStream
java.lang.Object
java.io.OutputStream
org.apache.hadoop.io.BoundedByteArrayOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
@LimitedPrivate({"HDFS","MapReduce"})
@Unstable
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
ConstructorsModifierConstructorDescriptionprotectedBoundedByteArrayOutputStream(byte[] buf, int offset, int limit) BoundedByteArrayOutputStream(int capacity) Create a BoundedByteArrayOutputStream with the specified capacityBoundedByteArrayOutputStream(int capacity, int limit) Create a BoundedByteArrayOutputStream with the specified capacity and limit. -
Method Summary
Modifier and TypeMethodDescriptionintbyte[]Returns the underlying buffer.intgetLimit()Return the current limit.voidreset()Reset the buffervoidreset(int newlim) Reset the limitprotected voidresetBuffer(byte[] buf, int offset, int limit) intsize()Returns the length of the valid data currently in the buffer.voidwrite(byte[] b, int off, int len) voidwrite(int b) Methods inherited from class java.io.OutputStream
close, flush, nullOutputStream, write
-
Constructor Details
-
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 arraylimit- The maximum limit upto which data can be written
-
BoundedByteArrayOutputStream
protected BoundedByteArrayOutputStream(byte[] buf, int offset, int limit)
-
-
Method Details
-
resetBuffer
protected void resetBuffer(byte[] buf, int offset, int limit) -
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- 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.- Returns:
- limit.
-
getBuffer
public byte[] getBuffer()Returns the underlying buffer. Data is only valid tosize().- Returns:
- the underlying buffer.
-
size
public int size()Returns the length of the valid data currently in the buffer.- Returns:
- the length of the valid data.
-
available
public int available()
-