ByteBuffer OutputStream.
This stream is similar to the java.io.ByteArrayOutputStream,
except that it maintains a reserve of bytes at the start of the
buffer and allows efficient prepending of data.
ByteBufferOutputStream
public ByteBufferOutputStream()
Constructor.
ByteBufferOutputStream
public ByteBufferOutputStream(int capacity)
Constructor.
capacity
- Buffer capacity
ByteBufferOutputStream
public ByteBufferOutputStream(int capacity,
int preReserve)
Constructor.
capacity
- Buffer capacity.preReserve
- The reserve of byte for prepending
ByteBufferOutputStream
public ByteBufferOutputStream(int bufferSize,
int preReserve,
int postReserve)
Constructor.
bufferSize
- The size of the buffer == capacity+preReserve+postReservepreReserve
- The reserve of byte for prependingpostReserve
- The reserve of byte for appending
bufferSize
public int bufferSize()
capacity
public int capacity()
- The capacity of the buffer excluding pre and post reserves.
close
public void close()
throws IOException
destroy
public void destroy()
ensureCapacity
public void ensureCapacity(int n)
throws IOException
ensureReserve
public void ensureReserve(int n)
ensureSize
public void ensureSize(int bufSize)
throws IOException
ensureSize
public void ensureSize(int bufSize,
int pre,
int post)
throws IOException
ensureSpareCapacity
public void ensureSpareCapacity(int n)
throws IOException
flush
public void flush()
throws IOException
isFixed
public boolean isFixed()
- True if the buffer cannot be expanded
postReserve
public int postReserve()
- The current post reserve.
postwrite
public void postwrite(byte[] b,
int offset,
int length)
throws IOException
Write bytes into the postreserve.
The capacity is not checked.
preReserve
public int preReserve()
prewrite
public void prewrite(byte[] b)
Write byte array to start of the buffer.
prewrite
public void prewrite(byte[] b,
int offset,
int length)
Write byte range to start of the buffer.
prewrite
public void prewrite(int b)
Write byte to start of the buffer.
reset
public void reset(int reserve)
resetStream
public void resetStream()
setFixed
public void setFixed(boolean fixed)
fixed
- True if the buffer cannot be expanded
size
public int size()
- The size of valid data in the buffer.
spareCapacity
public int spareCapacity()
- The available capacity of the buffer excluding pre and post
reserves and data already written.
write
public void write(byte[] b)
throws IOException
write
public void write(byte[] b,
int offset,
int length)
throws IOException
write
public void write(int b)
throws IOException
writeTo
public void writeTo(OutputStream out)
throws IOException