public final class ByteBuffer extends AbstractBuffer
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
buffer
The actual buffer
|
lowerBoundary, markedReaderIndex, readerIndex, upperBoundary, writerIndex| Modifier | Constructor and Description |
|---|---|
protected |
ByteBuffer(byte[] buffer) |
protected |
ByteBuffer(int readerIndex,
int lowerBoundary,
int upperBoundary,
byte[] buffer) |
protected |
ByteBuffer(int readerIndex,
int lowerBoundary,
int upperBoundary,
int writerIndex,
byte[] buffer) |
| Modifier and Type | Method and Description |
|---|---|
Buffer |
clone()
Performs a deep clone of this object.
|
java.lang.String |
dumpAsHex()
Dump the content of this buffer as a hex dump ala Wireshark.
|
boolean |
equals(java.lang.Object other)
Check whether to buffers are considered to be equal.
|
boolean |
equalsIgnoreCase(java.lang.Object other) |
byte[] |
getArray()
Get the backing array.
|
byte |
getByte(int index)
Get the byte at the index.
|
void |
getBytes(Buffer dst)
Same as calling
Buffer.getBytes(int, Buffer) where the index is
Buffer.getReaderIndex(). |
void |
getBytes(int index,
Buffer dst)
Transfer this buffer's data to the destination buffer.
|
void |
getBytes(int index,
java.nio.ByteBuffer dst) |
int |
getInt(int index)
Get a 32-bit integer at the specified absolute index.
|
short |
getShort(int index) |
short |
getUnsignedByte(int index) |
int |
getUnsignedShort(int index) |
int |
getWriterIndex()
The writer index.
|
int |
hashCode() |
boolean |
hasReadableBytes()
Checks whether this buffer has any bytes available for reading without
blocking.
|
boolean |
hasWriteSupport()
The underlying subclass should override this if it has write support.
|
boolean |
isEmpty()
Check whether this buffer is empty or not.
|
byte |
peekByte()
Peak a head to see what the next byte is.
|
byte |
readByte()
Read the next byte, which will also increase the readerIndex by one.
|
Buffer |
readBytes(int length)
Read the requested number of bytes and increase the readerIndex with the
corresponding number of bytes.
|
void |
readExternal(java.io.ObjectInput in) |
int |
readInt()
Read an int and will increase the reader index of this buffer by 4
|
short |
readShort() |
long |
readUnsignedInt()
Read an unsigned int and will increase the reader index of this buffer by
4
|
int |
readUnsignedShort() |
void |
setByte(int index,
byte value)
Set the byte at given index to a new value
|
void |
setInt(int index,
int value) |
void |
setUnsignedByte(int index,
short value) |
void |
setUnsignedInt(int index,
long value) |
void |
setUnsignedShort(int index,
int value) |
Buffer |
slice(int start,
int stop)
Get a slice of the buffer starting at
start (inclusive)
ending at stop (exclusive). |
java.lang.String |
toString() |
long |
unsignedInt(byte a,
byte b,
byte c,
byte d) |
void |
write(byte b)
Write a byte to where the current writer index is pointing.
|
void |
write(int value) |
void |
write(long value) |
void |
write(java.lang.String s)
Same as
Buffer.write(String, String) where the charset is set to
"UTF-8" |
void |
write(java.lang.String s,
java.lang.String charset)
Write a string to this buffer using the specified charset to convert the String into bytes.
|
void |
writeAsString(int value)
Write the integer value to this
Buffer as a String. |
void |
writeAsString(long value)
Write the long value to this
Buffer as a String. |
void |
writeExternal(java.io.ObjectOutput out) |
capacity, checkIndex, checkReadableBytes, checkReadableBytesSafe, checkWritableBytesSafe, checkWriterIndex, getReadableBytes, getReaderIndex, getWritableBytes, hasWritableBytes, indexOf, indexOf, markReaderIndex, parseToInt, parseToInt, readLine, readUnsignedByte, readUntil, readUntil, readUntilDoubleCRLF, resetReaderIndex, setReaderIndex, slice, sliceprotected ByteBuffer(byte[] buffer)
protected ByteBuffer(int readerIndex,
int lowerBoundary,
int upperBoundary,
byte[] buffer)
protected ByteBuffer(int readerIndex,
int lowerBoundary,
int upperBoundary,
int writerIndex,
byte[] buffer)
public Buffer slice(int start, int stop)
start (inclusive)
ending at stop (exclusive). Hence, the new capacity of the
buffer is stop - startpublic Buffer readBytes(int length) throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic boolean hasReadableBytes()
#readableBytes > 0public boolean isEmpty()
!Buffer.hasReadableBytes()public byte getByte(int index)
throws java.lang.IndexOutOfBoundsException
InputStreamBuffer gets its bytes off of a InputStream so
let's say you have read 10 bytes off of the stream already but ask to
access the byte at index 20, we will try and ready an additional 10 bytes
from the InputStream so we can return the byte at index 20.java.lang.IndexOutOfBoundsException - in case the index is greater than the capacity of this bufferpublic void write(byte b)
throws java.lang.IndexOutOfBoundsException
BufferWriteNotSupportedExceptionwrite in interface Bufferwrite in class AbstractBufferjava.lang.IndexOutOfBoundsException - in case there is no more space to write to (which includes
those cases where the underlying implementation does not
support writing)public byte[] getArray()
public byte readByte()
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException - in case there is nothing left to readpublic byte peekByte()
throws java.lang.IndexOutOfBoundsException,
java.io.IOException
java.lang.IndexOutOfBoundsException - in case there is nothing left to readjava.io.IOExceptionpublic long unsignedInt(byte a,
byte b,
byte c,
byte d)
public long readUnsignedInt()
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException - in case there is not 4 bytes left to readpublic int readInt()
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException - in case there is not 4 bytes left to readpublic short readShort()
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic int readUnsignedShort()
public int getInt(int index)
public short getShort(int index)
public void setUnsignedShort(int index,
int value)
public int getUnsignedShort(int index)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic short getUnsignedByte(int index)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic java.lang.String dumpAsHex()
public Buffer clone()
clone in interface Bufferclone in class AbstractBufferpublic int hashCode()
hashCode in interface BufferhashCode in class AbstractBufferpublic boolean equals(java.lang.Object other)
equals in interface Bufferequals in class AbstractBufferpublic boolean equalsIgnoreCase(java.lang.Object other)
public void setByte(int index,
byte value)
throws java.lang.IndexOutOfBoundsException
index - the indexvalue - the valuejava.lang.IndexOutOfBoundsExceptionpublic void setUnsignedByte(int index,
short value)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic java.lang.String toString()
public int getWriterIndex()
BuffergetWriterIndex in interface BuffergetWriterIndex in class AbstractBufferpublic void getBytes(Buffer dst)
BufferBuffer.getBytes(int, Buffer) where the index is
Buffer.getReaderIndex().public void getBytes(int index,
Buffer dst)
BufferreaderIndex or the writerIndex
of the src buffer (i.e. this) but will increase the
writerIndex of the destination buffer.public void getBytes(int index,
java.nio.ByteBuffer dst)
public void writeExternal(java.io.ObjectOutput out)
throws java.io.IOException
java.io.IOExceptionpublic void readExternal(java.io.ObjectInput in)
throws java.io.IOException,
java.lang.ClassNotFoundException
java.io.IOExceptionjava.lang.ClassNotFoundExceptionpublic boolean hasWriteSupport()
AbstractBufferBuffer has write support or not. There are
buffers that do not allow you to write to them (such as the
EmptyBuffer) so if you try and write to such a buffer it will
throw a WriteNotSupportedException.hasWriteSupport in interface BufferhasWriteSupport in class AbstractBufferpublic void write(java.lang.String s)
throws java.lang.IndexOutOfBoundsException,
WriteNotSupportedException,
java.io.UnsupportedEncodingException
BufferBuffer.write(String, String) where the charset is set to
"UTF-8"write in interface Bufferwrite in class AbstractBufferjava.lang.IndexOutOfBoundsException - in case we cannot write entire String to this Buffer.WriteNotSupportedException - in case the underlying implementation does not support
writes.java.io.UnsupportedEncodingException - in case the charset "UTF-8" is not supported by the platform.public void write(java.lang.String s,
java.lang.String charset)
throws java.lang.IndexOutOfBoundsException,
WriteNotSupportedException,
java.io.UnsupportedEncodingException
BufferwriterInxex of this buffer will be increased with the corresponding number
of bytes.
Note, either the entire string is written to this buffer or if it doesn't fit then nothing is
written to this buffer.write in interface Bufferwrite in class AbstractBufferjava.lang.IndexOutOfBoundsException - in case we cannot write entire String to this
Buffer.WriteNotSupportedExceptionjava.io.UnsupportedEncodingException - in case the specified charset is not supportedpublic void setInt(int index,
int value)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic void setUnsignedInt(int index,
long value)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic void write(int value)
throws java.lang.IndexOutOfBoundsException,
WriteNotSupportedException
java.lang.IndexOutOfBoundsExceptionWriteNotSupportedExceptionpublic void write(long value)
throws java.lang.IndexOutOfBoundsException,
WriteNotSupportedException
java.lang.IndexOutOfBoundsExceptionWriteNotSupportedExceptionpublic void writeAsString(int value)
throws java.lang.IndexOutOfBoundsException,
WriteNotSupportedException
BufferBuffer as a String.value - the value that will be converted to a String before being
written to this Buffer.java.lang.IndexOutOfBoundsExceptionWriteNotSupportedExceptionpublic void writeAsString(long value)
throws java.lang.IndexOutOfBoundsException,
WriteNotSupportedException
BufferBuffer as a String.value - the value that will be converted to a String before being written to this
Buffer.java.lang.IndexOutOfBoundsExceptionWriteNotSupportedExceptionCopyright © 2014. All Rights Reserved.