public final class InputStreamBuffer extends AbstractBuffer
lowerBoundary, markedReaderIndex, readerIndex, upperBoundary, writerIndex| Constructor and Description |
|---|
InputStreamBuffer(java.io.InputStream is) |
InputStreamBuffer(int initialCapacity,
java.io.InputStream is) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkIndex(int index)
Convenience method for checking if we can get the byte at the specified
index.
|
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() |
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.
|
int |
getInt(int index)
Get a 32-bit integer at the specified absolute index.
|
int |
getReadableBytes()
Returns the number of available bytes for reading without blocking.
|
short |
getShort(int index) |
short |
getUnsignedByte(int index) |
int |
getUnsignedShort(int index) |
int |
getWritableBytes()
Get the number of writable bytes.
|
int |
hashCode() |
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 |
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.
|
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() |
void |
write(int value) |
void |
write(long value) |
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. |
capacity, checkReadableBytes, checkReadableBytesSafe, checkWritableBytesSafe, checkWriterIndex, getReaderIndex, getWriterIndex, hasWriteSupport, indexOf, indexOf, markReaderIndex, parseToInt, parseToInt, readLine, readUnsignedByte, readUntil, readUntil, readUntilDoubleCRLF, resetReaderIndex, setReaderIndex, slice, slice, write, write, writepublic InputStreamBuffer(java.io.InputStream is)
public InputStreamBuffer(int initialCapacity,
java.io.InputStream is)
initialCapacity - the initial size of the internal byte arrayis - public Buffer slice(int start, int stop)
start (inclusive)
ending at stop (exclusive). Hence, the new capacity of the
buffer is stop - startpublic byte readByte()
throws java.lang.IndexOutOfBoundsException,
java.io.IOException
java.io.IOExceptionjava.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 Buffer readBytes(int length) throws java.lang.IndexOutOfBoundsException, java.io.IOException
java.io.IOExceptionjava.lang.IndexOutOfBoundsExceptionpublic 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 BuffergetReadableBytes in class AbstractBufferpublic boolean hasReadableBytes()
#readableBytes > 0java.io.IOExceptionjava.lang.IndexOutOfBoundsExceptionpublic boolean isEmpty()
!Buffer.hasReadableBytes()public byte[] getArray()
public byte getByte(int index)
throws java.lang.IndexOutOfBoundsException,
java.io.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.java.lang.IndexOutOfBoundsException - in case the index is greater than the capacity of this bufferjava.io.IOExceptionprotected void checkIndex(int index)
throws java.lang.IndexOutOfBoundsException
InputStream. If that fails, e.g. we don't ready
enough bytes off of the stream, then we will eventually throw an
IndexOutOfBoundsExceptioncheckIndex in class AbstractBufferindex - the actual index to check. I.e., this is the actual index in
our byte array, irrespective of what the lowerBoundary is set
to.java.lang.IndexOutOfBoundsExceptionjava.io.IOExceptionpublic 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 int getInt(int index)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException - in case there is not 4 bytes left to readpublic short getShort(int index)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic int readUnsignedShort()
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic int getUnsignedShort(int index)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic short readShort()
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic short getUnsignedByte(int index)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic java.lang.String dumpAsHex()
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 void setUnsignedShort(int index,
int value)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic Buffer clone()
Bufferclone in interface Bufferclone in class AbstractBufferpublic boolean equals(java.lang.Object other)
equals in interface Bufferequals in class AbstractBufferpublic boolean equalsIgnoreCase(java.lang.Object other)
public int hashCode()
hashCode in interface BufferhashCode in class AbstractBufferpublic java.lang.String toString()
public int getWritableBytes()
BuffergetWritableBytes in interface BuffergetWritableBytes in class AbstractBufferpublic boolean hasWritableBytes()
BufferBuffer has any space left for writing. Same
as Buffer.getWritableBytes() > 0hasWritableBytes in interface BufferhasWritableBytes in class AbstractBufferpublic void getBytes()
public void getBytes(Buffer dst)
BufferBuffer.getBytes(int, Buffer) where the index is
Buffer.getReaderIndex().public void getBytes(int index,
Buffer dst)
throws java.lang.IndexOutOfBoundsException
BufferreaderIndex or the writerIndex
of the src buffer (i.e. this) but will increase the
writerIndex of the destination buffer.java.lang.IndexOutOfBoundsException - in case index < 0public void setInt(int index,
int 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.IndexOutOfBoundsExceptionWriteNotSupportedExceptionpublic void setUnsignedInt(int index,
long value)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionCopyright © 2014. All Rights Reserved.