public class CompositeByteArrayRelativeWriter extends CompositeByteArrayRelativeBase implements IoRelativeWriter
CompositeByteArray.
Using this interface has the advantage that it can be automatically
determined when a component ByteArray can no longer be written
to, and thus components can be automatically flushed. This makes it easier to
use pooling for underlying ByteArrays.
By providing an appropriate Expander it is also possible to
automatically add more backing storage as more data is written.
| Modifier and Type | Class and Description |
|---|---|
static class |
CompositeByteArrayRelativeWriter.ChunkedExpander
Expands the supplied
CompositeByteArray by the number of
bytes provided in the constructor |
static interface |
CompositeByteArrayRelativeWriter.Expander
An object that knows how to expand a
CompositeByteArray. |
static interface |
CompositeByteArrayRelativeWriter.Flusher
An object that knows how to flush a
ByteArray. |
static class |
CompositeByteArrayRelativeWriter.NopExpander
No-op expander.
|
| Modifier and Type | Field and Description |
|---|---|
private boolean |
autoFlush
Whether or not to automatically flush a component once the cursor moves
past it.
|
private CompositeByteArrayRelativeWriter.Expander |
expander
The expander to use when the array underflows.
|
private CompositeByteArrayRelativeWriter.Flusher |
flusher
The flusher to use when flushing component
ByteArrays. |
cba, cursor| Constructor and Description |
|---|
CompositeByteArrayRelativeWriter(CompositeByteArray cba,
CompositeByteArrayRelativeWriter.Expander expander,
CompositeByteArrayRelativeWriter.Flusher flusher,
boolean autoFlush)
Creates a new instance of CompositeByteArrayRelativeWriter.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
cursorPassedFirstComponent()
Called whenever the cursor has passed from the
cba's
first component. |
void |
flush()
Flush to the current index.
|
void |
flushTo(int index)
Flush to the given index.
|
private void |
prepareForAccess(int size) |
void |
put(byte b)
Puts a
byte and advances the reader. |
void |
put(IoBuffer bb)
Puts enough bytes to fill the
IoBuffer and advances the reader. |
void |
putChar(char c)
Puts a
char and advances the reader. |
void |
putDouble(double d)
Puts a
double and advances the reader. |
void |
putFloat(float f)
Puts a
float and advances the reader. |
void |
putInt(int i)
Puts an
int and advances the reader. |
void |
putLong(long l)
Puts a
long and advances the reader. |
void |
putShort(short s)
Puts a
short and advances the reader. |
void |
skip(int length)
Advances the writer by the given number of bytes.
|
append, free, getIndex, getRemaining, hasRemaining, last, orderclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetRemaining, hasRemaining, orderprivate final CompositeByteArrayRelativeWriter.Expander expander
private final CompositeByteArrayRelativeWriter.Flusher flusher
ByteArrays.private final boolean autoFlush
public CompositeByteArrayRelativeWriter(CompositeByteArray cba, CompositeByteArrayRelativeWriter.Expander expander, CompositeByteArrayRelativeWriter.Flusher flusher, boolean autoFlush)
cba - The CompositeByteArray to use to back this classexpander - The expander. Will increase the size of the internal ByteArrayflusher - Flushed the ByteArray when necessaryautoFlush - Should this class automatically flush?private void prepareForAccess(int size)
public void flush()
public void flushTo(int index)
public void skip(int length)
IoRelativeWriterskip in interface IoRelativeWriterprotected void cursorPassedFirstComponent()
CompositeByteArrayRelativeBasecba's
first component. As the first component is no longer used, this provides
a good opportunity for subclasses to perform some action on it (such as
freeing it).cursorPassedFirstComponent in class CompositeByteArrayRelativeBasepublic void put(byte b)
IoRelativeWriterbyte and advances the reader.put in interface IoRelativeWriterpublic void put(IoBuffer bb)
IoRelativeWriterIoBuffer and advances the reader.put in interface IoRelativeWriterpublic void putShort(short s)
IoRelativeWritershort and advances the reader.putShort in interface IoRelativeWriterpublic void putInt(int i)
IoRelativeWriterint and advances the reader.putInt in interface IoRelativeWriterpublic void putLong(long l)
IoRelativeWriterlong and advances the reader.putLong in interface IoRelativeWriterpublic void putFloat(float f)
IoRelativeWriterfloat and advances the reader.putFloat in interface IoRelativeWriterpublic void putDouble(double d)
IoRelativeWriterdouble and advances the reader.putDouble in interface IoRelativeWriterpublic void putChar(char c)
IoRelativeWriterchar and advances the reader.putChar in interface IoRelativeWriter