Package org.apache.mina.util.byteaccess
Class CompositeByteArrayRelativeWriter
- java.lang.Object
-
- org.apache.mina.util.byteaccess.CompositeByteArrayRelativeWriter
-
- All Implemented Interfaces:
IoRelativeWriter
public class CompositeByteArrayRelativeWriter extends Object implements IoRelativeWriter
Provides restricted, relative, write-only access to the bytes in aCompositeByteArray
. Using this interface has the advantage that it can be automatically determined when a componentByteArray
can no longer be written to, and thus components can be automatically flushed. This makes it easier to use pooling for underlyingByteArray
s. By providing an appropriateExpander
it is also possible to automatically add more backing storage as more data is written.
TODO: Get flushing working.- Author:
- Apache MINA Project
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CompositeByteArrayRelativeWriter.ChunkedExpander
Expands the suppliedCompositeByteArray
by the number of bytes provided in the constructorstatic interface
CompositeByteArrayRelativeWriter.Expander
An object that knows how to expand aCompositeByteArray
.static interface
CompositeByteArrayRelativeWriter.Flusher
An object that knows how to flush aByteArray
.static class
CompositeByteArrayRelativeWriter.NopExpander
No-op expander.
-
Field Summary
Fields Modifier and Type Field Description protected CompositeByteArray
cba
The underlyingCompositeByteArray
.protected ByteArray.Cursor
cursor
A cursor of the underlyingCompositeByteArray
.
-
Constructor Summary
Constructors Constructor Description CompositeByteArrayRelativeWriter(CompositeByteArray cba, CompositeByteArrayRelativeWriter.Expander expander, CompositeByteArrayRelativeWriter.Flusher flusher, boolean autoFlush)
Creates a new instance of CompositeByteArrayRelativeWriter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
append(ByteArray ba)
Make aByteArray
available for access at the end of this object.protected void
cursorPassedFirstComponent()
Called whenever the cursor has passed from thecba
's first component.void
flush()
Flush to the current index.void
flushTo(int index)
Flush to the given index.void
free()
Free all resources associated with this object.int
getIndex()
int
getRemaining()
boolean
hasRemaining()
int
last()
ByteOrder
order()
void
put(byte b)
Puts abyte
and advances the reader.void
put(IoBuffer bb)
Puts enough bytes to fill theIoBuffer
and advances the reader.void
putChar(char c)
Puts achar
and advances the reader.void
putDouble(double d)
Puts adouble
and advances the reader.void
putFloat(float f)
Puts afloat
and advances the reader.void
putInt(int i)
Puts anint
and advances the reader.void
putLong(long l)
Puts along
and advances the reader.void
putShort(short s)
Puts ashort
and advances the reader.void
skip(int length)
Advances the writer by the given number of bytes.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.mina.util.byteaccess.IoRelativeWriter
getRemaining, hasRemaining, order
-
-
-
-
Field Detail
-
cba
protected final CompositeByteArray cba
The underlyingCompositeByteArray
.
-
cursor
protected final ByteArray.Cursor cursor
A cursor of the underlyingCompositeByteArray
. This cursor is never moved directly; its position only changes through calls to relative read or write methods.
-
-
Constructor Detail
-
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 Detail
-
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:
skip
in interfaceIoRelativeWriter
- Parameters:
length
- The number of bytes to skip
-
cursorPassedFirstComponent
protected void cursorPassedFirstComponent()
Called 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).
-
put
public void put(byte b)
Puts abyte
and advances the reader.- Specified by:
put
in interfaceIoRelativeWriter
- Parameters:
b
- The byte to put
-
put
public void put(IoBuffer bb)
Puts enough bytes to fill theIoBuffer
and advances the reader.- Specified by:
put
in interfaceIoRelativeWriter
- Parameters:
bb
- The bytes to put
-
putShort
public void putShort(short s)
Puts ashort
and advances the reader.- Specified by:
putShort
in interfaceIoRelativeWriter
- Parameters:
s
- The short to put
-
putInt
public void putInt(int i)
Puts anint
and advances the reader.- Specified by:
putInt
in interfaceIoRelativeWriter
- Parameters:
i
- The int to put
-
putLong
public void putLong(long l)
Puts along
and advances the reader.- Specified by:
putLong
in interfaceIoRelativeWriter
- Parameters:
l
- The long to put
-
putFloat
public void putFloat(float f)
Puts afloat
and advances the reader.- Specified by:
putFloat
in interfaceIoRelativeWriter
- Parameters:
f
- The float to put
-
putDouble
public void putDouble(double d)
Puts adouble
and advances the reader.- Specified by:
putDouble
in interfaceIoRelativeWriter
- Parameters:
d
- The double to put
-
putChar
public void putChar(char c)
Puts achar
and advances the reader.- Specified by:
putChar
in interfaceIoRelativeWriter
- Parameters:
c
- The char to put
-
getRemaining
public final int getRemaining()
- Returns:
- The number of remaining bytes
-
hasRemaining
public final boolean hasRemaining()
- Returns:
TRUE
if there are some more bytes
-
order
public ByteOrder order()
- Returns:
- The used byte order (little of big endian)
-
append
public final void append(ByteArray ba)
Make aByteArray
available for access at the end of this object.- Parameters:
ba
- The ByteArray to append
-
free
public final void free()
Free all resources associated with this object.
-
getIndex
public final int getIndex()
- Returns:
- the index that will be used for the next access.
-
last
public final int last()
- Returns:
- the index after the last byte that can be accessed.
-
-