public class NettyMessageBuffer extends Object implements MessageBuffer<io.netty.buffer.ByteBuf>
MessageBuffer interface. It is a thin
wrapper over the the Netty ByteBuf with some additional methods
for string and object read write. It does not expose all methods of the
ChannelBuffer, instead it has a method getNativeBuffer() which can
be used to retrieve the buffer and then call the appropriate method. For
writing to the buffer, this class uses ByteBuf
implementation.| Modifier and Type | Field and Description |
|---|---|
private io.netty.buffer.ByteBuf |
buffer |
| Constructor and Description |
|---|
NettyMessageBuffer() |
NettyMessageBuffer(io.netty.buffer.ByteBuf buffer)
This constructor can be used when trying to read information from a
ByteBuf. |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
array()
Returns the backing byte array of this buffer.
|
void |
clear()
Clears the contents of this buffer.
|
io.netty.buffer.ByteBuf |
getNativeBuffer()
Returns the actual buffer implementation that is wrapped in this
MessageBuffer instance.
|
boolean |
isReadable() |
int |
readableBytes()
Gets the number of readable bytes left in the buffer.
|
int |
readByte()
Read a single signed byte from the current
readerIndex position
of the buffer. |
void |
readBytes(byte[] dst)
Transfers this buffer's data to the specified destination starting at the
current
readerIndex and increases the readerIndex by the
number of the transferred bytes (= dst.length). |
void |
readBytes(byte[] dst,
int dstIndex,
int length)
Transfers this buffer's data to the specified destination starting at the
current
readerIndex and increases the readerIndex by the
number of the transferred bytes (= length). |
byte[] |
readBytes(int length) |
char |
readChar()
Gets a 2-byte UTF-16 character at the current
readerIndex and
increases the readerIndex by 2 in this buffer. |
double |
readDouble()
Gets a 64-bit floating point number at the current
readerIndex
and increases the readerIndex by 8 in this buffer. |
float |
readFloat()
Gets a 32-bit floating point number at the current
readerIndex
and increases the readerIndex by 4 in this buffer. |
int |
readInt()
Gets a 32-bit integer at the current
readerIndex and increases
the readerIndex by 4 in this buffer. |
long |
readLong()
Gets a 64-bit integer at the current
readerIndex and increases
the readerIndex by 8 in this buffer. |
int |
readMedium()
Gets a 24-bit medium integer at the current
readerIndex and
increases the readerIndex by 3 in this buffer. |
<V> V |
readObject(Transform<io.netty.buffer.ByteBuf,V> converter)
Reads an object from the underlying buffer and transform the bytes using
the supplied transformer to any desired object.
|
int |
readShort()
Gets a 16-bit short integer at the current
readerIndex and
increases the readerIndex by 2 in this buffer. |
String |
readString() |
String[] |
readStrings(int numOfStrings) |
int |
readUnsignedByte()
Gets an unsigned byte at the current
readerIndex and increases
the readerIndex by 1 in this buffer. |
long |
readUnsignedInt()
Gets an unsigned 32-bit integer at the current
readerIndex and
increases the readerIndex by 4 in this buffer. |
int |
readUnsignedMedium()
Gets an unsigned 24-bit medium integer at the current
readerIndex
and increases the readerIndex by 3 in this buffer. |
int |
readUnsignedShort()
Gets an unsigned 16-bit short integer at the current
readerIndex
and increases the readerIndex by 2 in this buffer. |
MessageBuffer<io.netty.buffer.ByteBuf> |
writeByte(byte b) |
MessageBuffer<io.netty.buffer.ByteBuf> |
writeBytes(byte[] src)
Transfers the specified source array's data to this buffer starting at
the current
writerIndex and increases the writerIndex by
the number of the transferred bytes (= src.length). |
MessageBuffer<io.netty.buffer.ByteBuf> |
writeChar(int value)
Sets the specified 2-byte UTF-16 character at the current
writerIndex and increases the writerIndex by 2 in
this buffer. |
MessageBuffer<io.netty.buffer.ByteBuf> |
writeDouble(double value)
Sets the specified 64-bit floating point number at the current
writerIndex and increases the writerIndex by 8 in
this buffer. |
MessageBuffer<io.netty.buffer.ByteBuf> |
writeFloat(float value)
Sets the specified 32-bit floating point number at the current
writerIndex and increases the writerIndex by 4 in
this buffer. |
MessageBuffer<io.netty.buffer.ByteBuf> |
writeInt(int value)
Sets the specified 32-bit integer at the current
writerIndex and
increases the writerIndex by 4 in this buffer. |
MessageBuffer<io.netty.buffer.ByteBuf> |
writeLong(long value)
Sets the specified 64-bit long integer at the current
writerIndex
and increases the writerIndex by 8 in this buffer. |
MessageBuffer<io.netty.buffer.ByteBuf> |
writeMedium(int value)
Sets the specified 24-bit medium integer at the current
writerIndex and increases the writerIndex by 3 in
this buffer. |
<V> MessageBuffer<io.netty.buffer.ByteBuf> |
writeObject(Transform<V,io.netty.buffer.ByteBuf> converter,
V object)
Most implementations will write an object to the underlying buffer after
converting the incoming object using the transformer into a byte array.
|
MessageBuffer<io.netty.buffer.ByteBuf> |
writeShort(int value)
Sets the specified 16-bit short integer at the current
writerIndex and increases the writerIndex by 2 in
this buffer. |
MessageBuffer<io.netty.buffer.ByteBuf> |
writeString(String message) |
MessageBuffer<io.netty.buffer.ByteBuf> |
writeStrings(String... messages) |
public NettyMessageBuffer()
public NettyMessageBuffer(io.netty.buffer.ByteBuf buffer)
ByteBuf.buffer - public boolean isReadable()
isReadable in interface MessageBuffer<io.netty.buffer.ByteBuf>public int readableBytes()
MessageBufferreadableBytes in interface MessageBuffer<io.netty.buffer.ByteBuf>public byte[] array()
MessageBufferarray in interface MessageBuffer<io.netty.buffer.ByteBuf>public void clear()
MessageBufferclear in interface MessageBuffer<io.netty.buffer.ByteBuf>public io.netty.buffer.ByteBuf getNativeBuffer()
MessageBuffergetNativeBuffer in interface MessageBuffer<io.netty.buffer.ByteBuf>ByteBuf, for a core java implementation
it could be ByteBufferpublic int readByte()
MessageBufferreaderIndex position
of the buffer. It will increment the readerIndex after doing this
operation.readByte in interface MessageBuffer<io.netty.buffer.ByteBuf>public int readUnsignedByte()
MessageBufferreaderIndex and increases
the readerIndex by 1 in this buffer.readUnsignedByte in interface MessageBuffer<io.netty.buffer.ByteBuf>public byte[] readBytes(int length)
readBytes in interface MessageBuffer<io.netty.buffer.ByteBuf>public void readBytes(byte[] dst)
MessageBufferreaderIndex and increases the readerIndex by the
number of the transferred bytes (= dst.length).readBytes in interface MessageBuffer<io.netty.buffer.ByteBuf>public void readBytes(byte[] dst,
int dstIndex,
int length)
MessageBufferreaderIndex and increases the readerIndex by the
number of the transferred bytes (= length).readBytes in interface MessageBuffer<io.netty.buffer.ByteBuf>dstIndex - the first index of the destinationlength - the number of bytes to transferpublic char readChar()
MessageBufferreaderIndex and
increases the readerIndex by 2 in this buffer.readChar in interface MessageBuffer<io.netty.buffer.ByteBuf>public int readUnsignedShort()
MessageBufferreaderIndex
and increases the readerIndex by 2 in this buffer.readUnsignedShort in interface MessageBuffer<io.netty.buffer.ByteBuf>public int readShort()
MessageBufferreaderIndex and
increases the readerIndex by 2 in this buffer.readShort in interface MessageBuffer<io.netty.buffer.ByteBuf>public int readUnsignedMedium()
MessageBufferreaderIndex
and increases the readerIndex by 3 in this buffer.readUnsignedMedium in interface MessageBuffer<io.netty.buffer.ByteBuf>public int readMedium()
MessageBufferreaderIndex and
increases the readerIndex by 3 in this buffer.readMedium in interface MessageBuffer<io.netty.buffer.ByteBuf>public long readUnsignedInt()
MessageBufferreaderIndex and
increases the readerIndex by 4 in this buffer.readUnsignedInt in interface MessageBuffer<io.netty.buffer.ByteBuf>public int readInt()
MessageBufferreaderIndex and increases
the readerIndex by 4 in this buffer.readInt in interface MessageBuffer<io.netty.buffer.ByteBuf>public long readLong()
MessageBufferreaderIndex and increases
the readerIndex by 8 in this buffer.readLong in interface MessageBuffer<io.netty.buffer.ByteBuf>public float readFloat()
MessageBufferreaderIndex
and increases the readerIndex by 4 in this buffer.readFloat in interface MessageBuffer<io.netty.buffer.ByteBuf>public double readDouble()
MessageBufferreaderIndex
and increases the readerIndex by 8 in this buffer.readDouble in interface MessageBuffer<io.netty.buffer.ByteBuf>public String readString()
readString in interface MessageBuffer<io.netty.buffer.ByteBuf>public String[] readStrings(int numOfStrings)
readStrings in interface MessageBuffer<io.netty.buffer.ByteBuf>public <V> V readObject(Transform<io.netty.buffer.ByteBuf,V> converter)
MessageBufferreadObject in interface MessageBuffer<io.netty.buffer.ByteBuf>converter - The converter which will transform the bytes to relevant
object.public MessageBuffer<io.netty.buffer.ByteBuf> writeByte(byte b)
writeByte in interface MessageBuffer<io.netty.buffer.ByteBuf>public MessageBuffer<io.netty.buffer.ByteBuf> writeBytes(byte[] src)
MessageBufferwriterIndex and increases the writerIndex by
the number of the transferred bytes (= src.length).writeBytes in interface MessageBuffer<io.netty.buffer.ByteBuf>public MessageBuffer<io.netty.buffer.ByteBuf> writeChar(int value)
MessageBufferwriterIndex and increases the writerIndex by 2 in
this buffer. The 16 high-order bits of the specified value are ignored.writeChar in interface MessageBuffer<io.netty.buffer.ByteBuf>public MessageBuffer<io.netty.buffer.ByteBuf> writeShort(int value)
MessageBufferwriterIndex and increases the writerIndex by 2 in
this buffer. The 16 high-order bits of the specified value are ignored.writeShort in interface MessageBuffer<io.netty.buffer.ByteBuf>public MessageBuffer<io.netty.buffer.ByteBuf> writeMedium(int value)
MessageBufferwriterIndex and increases the writerIndex by 3 in
this buffer.writeMedium in interface MessageBuffer<io.netty.buffer.ByteBuf>public MessageBuffer<io.netty.buffer.ByteBuf> writeInt(int value)
MessageBufferwriterIndex and
increases the writerIndex by 4 in this buffer.writeInt in interface MessageBuffer<io.netty.buffer.ByteBuf>public MessageBuffer<io.netty.buffer.ByteBuf> writeLong(long value)
MessageBufferwriterIndex
and increases the writerIndex by 8 in this buffer.writeLong in interface MessageBuffer<io.netty.buffer.ByteBuf>public MessageBuffer<io.netty.buffer.ByteBuf> writeFloat(float value)
MessageBufferwriterIndex and increases the writerIndex by 4 in
this buffer.writeFloat in interface MessageBuffer<io.netty.buffer.ByteBuf>public MessageBuffer<io.netty.buffer.ByteBuf> writeDouble(double value)
MessageBufferwriterIndex and increases the writerIndex by 8 in
this buffer.writeDouble in interface MessageBuffer<io.netty.buffer.ByteBuf>public MessageBuffer<io.netty.buffer.ByteBuf> writeString(String message)
writeString in interface MessageBuffer<io.netty.buffer.ByteBuf>public MessageBuffer<io.netty.buffer.ByteBuf> writeStrings(String... messages)
writeStrings in interface MessageBuffer<io.netty.buffer.ByteBuf>public <V> MessageBuffer<io.netty.buffer.ByteBuf> writeObject(Transform<V,io.netty.buffer.ByteBuf> converter, V object)
MessageBufferwriteObject in interface MessageBuffer<io.netty.buffer.ByteBuf>V - The object to be converted, mostly to a byte array or relevant
buffer implementation.converter - For most implementations, the converter which will transform
the object to byte array.Copyright © 2013. All Rights Reserved.