| Modifier | Constructor and Description |
|---|---|
protected |
EmptyBuffer() |
| Modifier and Type | Method and Description |
|---|---|
int |
capacity()
The capacity of this buffer.
|
Buffer |
clone()
Really nothing to clone so just return this since this
EmptyBuffer is by definition immutable. |
String |
dumpAsHex()
Dump the content of this buffer as a hex dump ala Wireshark.
|
boolean |
equalsIgnoreCase(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(byte[] dst) |
void |
getBytes(int index,
Buffer dst)
Transfer this buffer's data to the destination buffer.
|
int |
getInt(int index)
Get a 32-bit integer at the specified absolute index.
|
int |
getLowerBoundary()
If you access the
Buffer.getRawArray() you will get just that. |
int |
getReadableBytes()
Returns the number of available bytes for reading without blocking.
|
int |
getReaderIndex()
The reader index
|
short |
getShort(int index) |
short |
getUnsignedByte(int index) |
long |
getUnsignedInt(int index) |
int |
getUnsignedShort(int index) |
int |
getUpperBoundary()
See explanation in
Buffer.getLowerBoundary() since this is the same, just
the upper limit of that raw array. |
int |
getWritableBytes()
Get the number of writable bytes.
|
int |
getWriterIndex()
The writer index.
|
boolean |
hasReadableBytes()
Checks whether this buffer has any bytes available for reading without
blocking.
|
boolean |
hasWritableBytes()
Checks whether this
Buffer has any space left for writing. |
boolean |
hasWriteSupport()
Check whether this
Buffer has write support or not. |
int |
indexOf(byte b) |
int |
indexOf(int maxBytes,
byte... bytes)
Same as
Buffer.readUntil(int, byte...) but instead of returning the
buffer with everything up until the specified byte it returns the index
instead. |
boolean |
isEmpty()
Check whether this buffer is empty or not.
|
void |
markReaderIndex()
Mark the current position of the reader index.
|
int |
parseToInt()
Parse all the readable bytes in this buffer as a unsigned integer value.
|
int |
parseToInt(int radix)
Convert the entire buffer to a signed integer value
|
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.
|
int |
readInt()
Read an int and will increase the reader index of this buffer by 4
|
Buffer |
readLine()
Reads a line, i.e., it reads until we hit a line feed ('\n') or a
carriage return ('\r'), or a carriage return followed immediately by a
line feed.
|
short |
readShort() |
short |
readUnsignedByte() |
long |
readUnsignedInt()
Read an unsigned int and will increase the reader index of this buffer by
4
|
int |
readUnsignedShort() |
Buffer |
readUntil(byte b)
Same as
#readUntil(4096, 'b')
Read until the specified byte is encountered and return a buffer
representing that section of the buffer. |
Buffer |
readUntil(int maxBytes,
byte... bytes)
Read until any of the specified bytes have been encountered or until we
have read a maximum amount of bytes.
|
Buffer |
readUntilDoubleCRLF()
Read until we find a double CRLF.
|
Buffer |
readUntilSafe(int maxBytes,
byte... bytes)
Same as
Buffer.readUntil(int, byte...) but will return null instead of
throwing a ByteNotFoundException |
Buffer |
readUntilSingleCRLF()
Read until we find a single CRLF.
|
void |
resetReaderIndex()
Reset the reader index to the marked position or to the beginning of the
buffer if mark hasn't explicitly been called.
|
void |
setByte(int index,
byte value)
Set the byte at given index to a new value
|
void |
setInt(int index,
int value) |
void |
setReaderIndex(int index) |
void |
setUnsignedByte(int index,
short value) |
void |
setUnsignedInt(int index,
long value) |
void |
setUnsignedShort(int index,
int value) |
void |
setWriterIndex(int index) |
Buffer |
slice()
Slice off the rest of the buffer.
|
Buffer |
slice(int stop)
Same as
#slice(Buffer.getReaderIndex(), int) |
Buffer |
slice(int start,
int stop)
Get a slice of the buffer starting at
start (inclusive)
ending at stop (exclusive). |
String |
toString() |
void |
write(byte b)
Write a byte to where the current writer index is pointing.
|
void |
write(byte[] bytes) |
void |
write(int value) |
void |
write(long value) |
void |
write(String s)
Same as
Buffer.write(String, String) where the charset is set to
"UTF-8" |
void |
write(String s,
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. |
public Buffer readBytes(int length) throws IndexOutOfBoundsException, IOException
readBytes in interface BufferIndexOutOfBoundsExceptionIOExceptionpublic Buffer readLine() throws IOException
readLine in interface BufferIOExceptionpublic Buffer readUntilSingleCRLF() throws IOException
BufferBuffer.readLine() but the
readLine doesn't enforce the CRLF being present, which is typical for
e.g. SIP and is important when reading bytes being streamed over e.g.
a network connectionreadUntilSingleCRLF in interface BufferIOExceptionpublic Buffer readUntilDoubleCRLF() throws IOException
BufferreadUntilDoubleCRLF in interface BufferIOExceptionpublic int getReadableBytes()
InputStream may be able to read more off the stream,
however, it may not be able to do so without blocking.getReadableBytes in interface Bufferpublic boolean hasReadableBytes()
Buffer.getReadableBytes() > 0hasReadableBytes in interface Bufferpublic boolean isEmpty()
!Buffer.hasReadableBytes()public byte[] getArray()
public Buffer readUntil(byte b) throws IOException, ByteNotFoundException
#readUntil(4096, 'b')
Read until the specified byte is encountered and return a buffer
representing that section of the buffer.
If the byte isn't found, then a ByteNotFoundException is thrown
and the Buffer.getReaderIndex() is left where we bailed out.
Note, the byte we are looking for will have been consumed so whatever
that is left in the Buffer will not contain that byte.
Example:
Buffer buffer = Buffers.wrap("hello world");
Buffer hello = buffer.readUntil((byte)' ');
System.out.println(hello); // will contain "hello"
System.out.println(buffer); // will contain "world"
As the example above illustrates, we are looking for a space, which is
found between "hello" and "world". Since the space will be consumed, the
original buffer will now only contain "world" and not " world".readUntil in interface Bufferb - the byte to look forByteNotFoundException - in case the byte we were looking for is not found.IOExceptionpublic Buffer slice(int start, int stop)
start (inclusive)
ending at stop (exclusive). Hence, the new capacity of the
buffer is stop - startpublic Buffer slice(int stop)
#slice(Buffer.getReaderIndex(), int)public Buffer slice()
#slice(Buffer.getReaderIndex(), buffer.getCapacity())
Note, if you slice an empty buffer you will get back another empty
buffer. Same goes for when you slice a buffer whose bytes already have
been consumed.public int getLowerBoundary()
BufferBuffer.getRawArray() you will get just that. The raw
un-guarded array, which may be useful but should be used with care since you
now can do whatever you want with the data. However, if you do so and also
want to know which 'slice' of that array this buffer is seeing, then you
need to know the lower boundary as well since the array can e.g be 1k long
but the data seen by this buffer starts at index 200.getLowerBoundary in interface Bufferpublic int getUpperBoundary()
BufferBuffer.getLowerBoundary() since this is the same, just
the upper limit of that raw array.getUpperBoundary in interface Bufferpublic int getReaderIndex()
getReaderIndex in interface Bufferpublic void markReaderIndex()
markReaderIndex in interface Buffer#reset()public void resetReaderIndex()
resetReaderIndex in interface Bufferpublic int capacity()
public byte getByte(int index)
throws IndexOutOfBoundsException,
IOException
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.getByte in interface BufferIndexOutOfBoundsException - in case the index is greater than the capacity of this bufferIOExceptionpublic byte readByte()
throws IndexOutOfBoundsException,
IOException
readByte in interface BufferIndexOutOfBoundsException - in case there is nothing left to readIOExceptionpublic long readUnsignedInt()
throws IndexOutOfBoundsException
readUnsignedInt in interface BufferIndexOutOfBoundsException - in case there is not 4 bytes left to readpublic int readInt()
throws IndexOutOfBoundsException
readInt in interface BufferIndexOutOfBoundsException - in case there is not 4 bytes left to readpublic int getInt(int index)
throws IndexOutOfBoundsException
getInt in interface BufferIndexOutOfBoundsException - in case there is not 4 bytes left to readpublic short getShort(int index)
throws IndexOutOfBoundsException
getShort in interface BufferIndexOutOfBoundsExceptionpublic int readUnsignedShort()
throws IndexOutOfBoundsException
readUnsignedShort in interface BufferIndexOutOfBoundsExceptionpublic int getUnsignedShort(int index)
throws IndexOutOfBoundsException
getUnsignedShort in interface BufferIndexOutOfBoundsExceptionpublic short readShort()
throws IndexOutOfBoundsException
readShort in interface BufferIndexOutOfBoundsExceptionpublic short readUnsignedByte()
throws IndexOutOfBoundsException,
IOException
readUnsignedByte in interface BufferIndexOutOfBoundsExceptionIOExceptionpublic long getUnsignedInt(int index)
throws IndexOutOfBoundsException
getUnsignedInt in interface BufferIndexOutOfBoundsExceptionpublic short getUnsignedByte(int index)
throws IndexOutOfBoundsException
getUnsignedByte in interface BufferIndexOutOfBoundsExceptionpublic String dumpAsHex()
public void setByte(int index,
byte value)
throws IndexOutOfBoundsException
setByte in interface Bufferindex - the indexvalue - the valueIndexOutOfBoundsExceptionpublic void setUnsignedByte(int index,
short value)
throws IndexOutOfBoundsException
setUnsignedByte in interface BufferIndexOutOfBoundsExceptionpublic void setUnsignedShort(int index,
int value)
throws IndexOutOfBoundsException
setUnsignedShort in interface BufferIndexOutOfBoundsExceptionpublic Buffer clone()
EmptyBuffer is by definition immutable.
Performs a deep clone of this object. I.e., the array that is backed by
this buffer will be copied and a new buffer will be returned. Hence, any
changes to the backing of this buffer will not affect the cloned buffer.public String toString()
public byte peekByte()
throws IndexOutOfBoundsException,
IOException
BufferpeekByte in interface BufferIndexOutOfBoundsException - in case there is nothing left to readIOExceptionpublic Buffer readUntil(int maxBytes, byte... bytes) throws IOException, ByteNotFoundException
BufferBuffer.readUntil(byte) except it allows you to look for multiple bytes
and to specify for how many bytes we should be looking before we give up.
Example, we want to read until we either findreadUntil in interface BuffermaxBytes - the maximum number of bytes we would like to read before
giving up.bytes - the bytes we are looking for (either one of them)IOExceptionByteNotFoundException - in case none of the bytes we were looking for are found
within the specified maximum number of bytes.public Buffer readUntilSafe(int maxBytes, byte... bytes) throws IOException, IllegalArgumentException
BufferBuffer.readUntil(int, byte...) but will return null instead of
throwing a ByteNotFoundExceptionreadUntilSafe in interface BufferIOExceptionIllegalArgumentExceptionpublic int indexOf(int maxBytes,
byte... bytes)
throws IOException,
ByteNotFoundException,
IllegalArgumentException
BufferBuffer.readUntil(int, byte...) but instead of returning the
buffer with everything up until the specified byte it returns the index
instead.
NOTE. The index is representing where in the Buffer you can find
the byte and the index is in relation to the entire Buffer and
its capacity so even if you have already read x bytes, it would not
change the index of what you search for.
Example:indexOf in interface BuffermaxBytes - the maximum number of bytes we would like to read before
giving up.bytes - the bytes we are looking for (either one of them)IOExceptionByteNotFoundException - will ONLY be thrown if we haven't found the byte within the
maxBytes limit. If the buffer we are searching in is less
than maxBytes and we can't find what we are looking for then
negative one will be returned instead.IllegalArgumentExceptionpublic int indexOf(byte b)
throws IOException,
ByteNotFoundException,
IllegalArgumentException
indexOf in interface BufferIOExceptionByteNotFoundExceptionIllegalArgumentExceptionpublic void setReaderIndex(int index)
setReaderIndex in interface Bufferpublic void write(byte b)
throws IndexOutOfBoundsException
BufferWriteNotSupportedExceptionwrite in interface BufferIndexOutOfBoundsException - in case there is no more space to write to (which includes
those cases where the underlying implementation does not
support writing)public void write(byte[] bytes)
throws IndexOutOfBoundsException,
WriteNotSupportedException
write in interface BufferIndexOutOfBoundsExceptionWriteNotSupportedExceptionpublic void write(String s) throws IndexOutOfBoundsException, WriteNotSupportedException
BufferBuffer.write(String, String) where the charset is set to
"UTF-8"write in interface BufferIndexOutOfBoundsException - in case we cannot write entire String to this Buffer.WriteNotSupportedException - in case the underlying implementation does not support
writes.public void write(String s, String charset) throws IndexOutOfBoundsException, WriteNotSupportedException, 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 BufferIndexOutOfBoundsException - in case we cannot write entire String to this
Buffer.WriteNotSupportedExceptionUnsupportedEncodingException - in case the specified charset is not supportedpublic void write(int value)
throws IndexOutOfBoundsException,
WriteNotSupportedException
write in interface BufferIndexOutOfBoundsExceptionWriteNotSupportedExceptionpublic void write(long value)
throws IndexOutOfBoundsException,
WriteNotSupportedException
write in interface BufferIndexOutOfBoundsExceptionWriteNotSupportedExceptionpublic void writeAsString(int value)
throws IndexOutOfBoundsException,
WriteNotSupportedException
BufferBuffer as a String.writeAsString in interface Buffervalue - the value that will be converted to a String before being
written to this Buffer.IndexOutOfBoundsExceptionWriteNotSupportedExceptionpublic void writeAsString(long value)
throws IndexOutOfBoundsException,
WriteNotSupportedException
BufferBuffer as a String.writeAsString in interface Buffervalue - the value that will be converted to a String before being written to this
Buffer.IndexOutOfBoundsExceptionWriteNotSupportedExceptionpublic int getWriterIndex()
BuffergetWriterIndex in interface Bufferpublic void setWriterIndex(int index)
setWriterIndex in interface Bufferpublic int getWritableBytes()
BuffergetWritableBytes in interface Bufferpublic boolean hasWritableBytes()
BufferBuffer has any space left for writing. Same
as Buffer.getWritableBytes() > 0hasWritableBytes in interface Bufferpublic void getBytes(Buffer dst)
BufferBuffer.getBytes(int, Buffer) where the index is
Buffer.getReaderIndex().public void getBytes(byte[] dst)
throws IndexOutOfBoundsException
getBytes in interface BufferIndexOutOfBoundsExceptionpublic void getBytes(int index,
Buffer dst)
throws IndexOutOfBoundsException
BufferreaderIndex or the writerIndex
of the src buffer (i.e. this) but will increase the
writerIndex of the destination buffer.getBytes in interface BufferIndexOutOfBoundsException - in case index < 0public boolean hasWriteSupport()
BufferBuffer 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 Bufferpublic void setInt(int index,
int value)
throws IndexOutOfBoundsException
setInt in interface BufferIndexOutOfBoundsExceptionpublic int parseToInt()
throws NumberFormatException
BufferparseToInt in interface BufferNumberFormatException - in case the bytes in the buffer cannot be converted into an
integer value.public int parseToInt(int radix)
BufferparseToInt in interface Bufferpublic void setUnsignedInt(int index,
long value)
throws IndexOutOfBoundsException
setUnsignedInt in interface BufferIndexOutOfBoundsExceptionpublic boolean equalsIgnoreCase(Object other)
equalsIgnoreCase in interface BufferCopyright © 2021. All Rights Reserved.