public abstract class AbstractBuffer extends BaseBuffer
| Modifier and Type | Field and Description |
|---|---|
protected int |
lowerBoundary
We will pretend that any bytes below this boundary doesn't exist.
|
protected int |
markedReaderIndex
The position of the reader index that has been marked.
|
protected int |
readerIndex
From where we will continue reading
|
protected int |
upperBoundary
Any bytes above this boundary is not accessible to us
|
protected int |
writerIndex
This is where we will write the next byte.
|
CR, LF| Modifier | Constructor and Description |
|---|---|
protected |
AbstractBuffer(int readerIndex,
int lowerBoundary,
int upperBoundary,
int writerIndex) |
| Modifier and Type | Method and Description |
|---|---|
int |
capacity()
The capacity of this buffer.
|
protected void |
checkIndex(int index)
Convenience method for checking if we can read at the index
|
protected void |
checkWriterIndex(int index)
Convenience method for checking whether we can write at the specified
index.
|
abstract Buffer |
clone()
Performs a deep clone of this object.
|
abstract boolean |
equals(Object other)
Check whether to buffers are considered to be equal.
|
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
|
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.
|
abstract int |
hashCode() |
boolean |
hasWriteSupport()
The underlying subclass should override this if it has write support.
|
void |
markReaderIndex()
Mark the current position of the reader index.
|
short |
readUnsignedByte() |
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 |
setReaderIndex(int index) |
void |
setWriterIndex(int index) |
Buffer |
slice()
Slice off the rest of the buffer.
|
Buffer |
slice(int stop)
Same as
#slice(Buffer.getReaderIndex(), int) |
void |
write(byte b)
Write a byte to where the current writer index is pointing.
|
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.
|
checkReadableBytes, checkReadableBytesSafe, checkWritableBytesSafe, hasWritableBytes, indexOf, indexOf, isByteInArray, parseToInt, parseToInt, readLine, readUntil, readUntil, readUntilDoubleCRLF, readUntilSafe, readUntilSingleCRLFfinalize, getClass, notify, notifyAll, toString, wait, wait, waitdumpAsHex, equalsIgnoreCase, getArray, getBit, getBit0, getBit1, getBit2, getBit3, getBit4, getBit5, getBit6, getBit7, getByes, getByte, getBytes, getBytes, getBytes, getInt, getRawArray, getShort, getUnsignedByte, getUnsignedInt, getUnsignedShort, hasReadableBytes, isEmpty, peekByte, readByte, readBytes, readInt, readShort, readUnsignedInt, readUnsignedShort, setByte, setInt, setUnsignedByte, setUnsignedInt, setUnsignedShort, slice, toString, unsignedInt, write, write, write, writeAsString, writeAsStringprotected int readerIndex
protected int writerIndex
protected int markedReaderIndex
resetReaderIndex()protected int lowerBoundary
protected int upperBoundary
protected AbstractBuffer(int readerIndex,
int lowerBoundary,
int upperBoundary,
int writerIndex)
public abstract Buffer clone()
Bufferclone in interface Bufferclone in class BaseBufferpublic 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.public int getUpperBoundary()
BufferBuffer.getLowerBoundary() since this is the same, just
the upper limit of that raw array.public int getReaderIndex()
public int getWriterIndex()
Bufferpublic void setWriterIndex(int index)
public void setReaderIndex(int index)
public int capacity()
public int getWritableBytes()
Bufferpublic void markReaderIndex()
#reset()public Buffer slice(int stop)
#slice(Buffer.getReaderIndex(), int)public Buffer slice()
Buffer#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 getReadableBytes()
InputStream may be able to read more off the stream,
however, it may not be able to do so without blocking.public void resetReaderIndex()
protected void checkIndex(int index)
throws IndexOutOfBoundsException
index - IndexOutOfBoundsExceptionprotected void checkWriterIndex(int index)
throws IndexOutOfBoundsException
index - IndexOutOfBoundsExceptionpublic final short readUnsignedByte()
throws IndexOutOfBoundsException,
IOException
IndexOutOfBoundsExceptionIOExceptionpublic boolean hasWriteSupport()
Buffer 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.public void write(byte b)
throws IndexOutOfBoundsException
BufferWriteNotSupportedExceptionIndexOutOfBoundsException - 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(String s) throws IndexOutOfBoundsException, WriteNotSupportedException, UnsupportedEncodingException
BufferBuffer.write(String, String) where the charset is set to
"UTF-8"IndexOutOfBoundsException - in case we cannot write entire String to this Buffer.WriteNotSupportedException - in case the underlying implementation does not support
writes.UnsupportedEncodingException - in case the charset "UTF-8" is not supported by the platform.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.IndexOutOfBoundsException - in case we cannot write entire String to this
Buffer.WriteNotSupportedExceptionUnsupportedEncodingException - in case the specified charset is not supportedpublic abstract boolean equals(Object other)
BufferCopyright © 2021. All Rights Reserved.