|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.OutputStream org.blinkenbyte.io.ByteArrayBuffer
public class ByteArrayBuffer
This class represents an output stream that uses two-dimensional byte arrays for storage. This allows it to allocate storage space incrementally without the usual create/copy cycle usually needed to expand an array. It also supports creating an InputStream that can read directly from the byte arrays.
Nested Class Summary | |
---|---|
static class |
ByteArrayBuffer.ByteArrayBufferInputStream
Class that can extends InputStream and can read directly from the internal buffers of the host ByteArrayBuffer. |
Field Summary | |
---|---|
protected int |
bytesUsed
The number of bytes currently used. |
protected int |
MAIN_BUFFER_SIZE
The size of the main buffer. |
protected byte[][] |
mainBuffer
The main buffer. |
protected int |
mainBuffersAllocated
The number of buffers allocated in the main buffer. |
protected int |
SUB_BUFFER_LOG
The base 2 logarithm of the size of the sub-buffers. |
protected int |
SUB_BUFFER_MASK
The bitmask used to break an index into a main index and a sub index. |
protected int |
SUB_BUFFER_SIZE
The size of the sub-buffers. |
protected int |
writePtr
The current location of the write pointer. |
Constructor Summary | |
---|---|
ByteArrayBuffer()
Constructs a new ByteArrayBuffer using default settings (64KB sub-buffers) |
|
ByteArrayBuffer(int mainBufferSize,
int subBufferLog)
Constructs a new ByteArrayBuffer with the specified dimensions. |
Method Summary | |
---|---|
void |
clean()
Nulls all pointers to aid with garbage collection. |
void |
close()
Inherited from OutputStream, but does nothing. |
void |
fillZeroes()
Fills all allocated buffers with 0's. |
void |
flush()
Inherited from OutputStream; does nothing. |
ByteArrayBuffer.ByteArrayBufferInputStream |
getInputStream()
Returns a ByteArrayBufferInputStream that can be used to read directly from the internal buffers of this object. |
ByteArrayBuffer.ByteArrayBufferInputStream |
getInputStream(boolean _sharedPointer)
Returns a ByteArrayBufferInputStream that can be used to read directly from the internal buffers of this object. |
int |
getWritePtr()
Gets the current value of the write pointer |
int |
length()
Returns the current number of bytes used in the buffer. |
int |
seek(int newWritePtr)
Changes the write pointer. |
void |
setLength(int newLength)
Adjusts the number of bytes used in the buffer. |
void |
write(byte[] b)
Writes the byte array b to the buffers. |
void |
write(byte[] b,
int offset,
int len)
Writes len bytes from a byte array starting at b[offset]. |
void |
write(int b)
Writes a single byte to the buffers. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int SUB_BUFFER_LOG
protected int SUB_BUFFER_SIZE
protected int SUB_BUFFER_MASK
protected int MAIN_BUFFER_SIZE
protected byte[][] mainBuffer
protected int bytesUsed
protected int writePtr
protected int mainBuffersAllocated
Constructor Detail |
---|
public ByteArrayBuffer()
public ByteArrayBuffer(int mainBufferSize, int subBufferLog)
mainBufferSize
- The size of the main buffer. The main buffer simply holds sub-buffers, and will automatically grow as needed.subBufferLog
- The base 2 logarithm of the size of the sub-buffer. Sub-buffers are allocated at their full size as needed.Method Detail |
---|
public void close()
close
in interface java.io.Closeable
close
in class java.io.OutputStream
public void clean()
public void flush()
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
public void write(byte[] b)
write
in class java.io.OutputStream
public void write(byte[] b, int offset, int len)
write
in class java.io.OutputStream
public void write(int b)
write
in class java.io.OutputStream
public int length()
public void setLength(int newLength)
public int seek(int newWritePtr)
public int getWritePtr()
public void fillZeroes()
public ByteArrayBuffer.ByteArrayBufferInputStream getInputStream()
public ByteArrayBuffer.ByteArrayBufferInputStream getInputStream(boolean _sharedPointer)
_sharedPointer
- Specifies whether the read pointer should be shared with the write pointer.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |