Class CompositeByteArrayRelativeWriter
java.lang.Object
org.apache.mina.util.byteaccess.CompositeByteArrayRelativeBase
org.apache.mina.util.byteaccess.CompositeByteArrayRelativeWriter
- All Implemented Interfaces:
IoRelativeWriter
public class CompositeByteArrayRelativeWriter
extends CompositeByteArrayRelativeBase
implements IoRelativeWriter
Provides restricted, relative, write-only access to the bytes in a
TODO: Get flushing working.
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.
TODO: Get flushing working.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classExpands the suppliedCompositeByteArrayby the number of bytes provided in the constructorstatic interfaceAn object that knows how to expand aCompositeByteArray.static interfaceAn object that knows how to flush aByteArray.static classNo-op expander. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanWhether or not to automatically flush a component once the cursor moves past it.private final CompositeByteArrayRelativeWriter.ExpanderThe expander to use when the array underflows.private final CompositeByteArrayRelativeWriter.FlusherThe flusher to use when flushing componentByteArrays.Fields inherited from class CompositeByteArrayRelativeBase
cba, cursor -
Constructor Summary
ConstructorsConstructorDescriptionCompositeByteArrayRelativeWriter(CompositeByteArray cba, CompositeByteArrayRelativeWriter.Expander expander, CompositeByteArrayRelativeWriter.Flusher flusher, boolean autoFlush) Creates a new instance of CompositeByteArrayRelativeWriter. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCalled whenever the cursor has passed from thecba's first component.voidflush()Flush to the current index.voidflushTo(int index) Flush to the given index.private voidprepareForAccess(int size) voidput(byte b) Puts abyteand advances the reader.voidPuts enough bytes to fill theIoBufferand advances the reader.voidputChar(char c) Puts acharand advances the reader.voidputDouble(double d) Puts adoubleand advances the reader.voidputFloat(float f) Puts afloatand advances the reader.voidputInt(int i) Puts anintand advances the reader.voidputLong(long l) Puts alongand advances the reader.voidputShort(short s) Puts ashortand advances the reader.voidskip(int length) Advances the writer by the given number of bytes.Methods inherited from class CompositeByteArrayRelativeBase
append, free, getIndex, getRemaining, hasRemaining, last, orderMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface IoRelativeWriter
getRemaining, hasRemaining, order
-
Field Details
-
expander
The expander to use when the array underflows. -
flusher
The flusher to use when flushing componentByteArrays. -
autoFlush
private final boolean autoFlushWhether or not to automatically flush a component once the cursor moves past it.
-
-
Constructor Details
-
CompositeByteArrayRelativeWriter
public CompositeByteArrayRelativeWriter(CompositeByteArray cba, CompositeByteArrayRelativeWriter.Expander expander, CompositeByteArrayRelativeWriter.Flusher flusher, boolean autoFlush) Creates a new instance of CompositeByteArrayRelativeWriter.- Parameters:
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?
-
-
Method Details
-
prepareForAccess
private void prepareForAccess(int size) -
flush
public void flush()Flush to the current index. -
flushTo
public void flushTo(int index) Flush to the given index.- Parameters:
index- The end position
-
skip
public void skip(int length) Advances the writer by the given number of bytes.- Specified by:
skipin interfaceIoRelativeWriter- Parameters:
length- The number of bytes to skip
-
cursorPassedFirstComponent
protected void cursorPassedFirstComponent()Description copied from class:CompositeByteArrayRelativeBaseCalled whenever the cursor has passed from thecba'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).- Specified by:
cursorPassedFirstComponentin classCompositeByteArrayRelativeBase
-
put
public void put(byte b) Puts abyteand advances the reader.- Specified by:
putin interfaceIoRelativeWriter- Parameters:
b- The byte to put
-
put
Puts enough bytes to fill theIoBufferand advances the reader.- Specified by:
putin interfaceIoRelativeWriter- Parameters:
bb- The bytes to put
-
putShort
public void putShort(short s) Puts ashortand advances the reader.- Specified by:
putShortin interfaceIoRelativeWriter- Parameters:
s- The short to put
-
putInt
public void putInt(int i) Puts anintand advances the reader.- Specified by:
putIntin interfaceIoRelativeWriter- Parameters:
i- The int to put
-
putLong
public void putLong(long l) Puts alongand advances the reader.- Specified by:
putLongin interfaceIoRelativeWriter- Parameters:
l- The long to put
-
putFloat
public void putFloat(float f) Puts afloatand advances the reader.- Specified by:
putFloatin interfaceIoRelativeWriter- Parameters:
f- The float to put
-
putDouble
public void putDouble(double d) Puts adoubleand advances the reader.- Specified by:
putDoublein interfaceIoRelativeWriter- Parameters:
d- The double to put
-
putChar
public void putChar(char c) Puts acharand advances the reader.- Specified by:
putCharin interfaceIoRelativeWriter- Parameters:
c- The char to put
-