public class BoundedInputStreamBuffer extends BaseBuffer
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_CAPACITY
The default capacity for each individual byte array, default to tcpdumps default snaplength.
|
CR, LF| Constructor and Description |
|---|
BoundedInputStreamBuffer(InputStream is) |
BoundedInputStreamBuffer(int bufferCapacity,
InputStream is) |
| Modifier and Type | Method and Description |
|---|---|
int |
capacity()
The capacity of this buffer.
|
Buffer |
clone()
Performs a deep clone of this object.
|
String |
dumpAsHex()
Dump the content of this buffer as a hex dump ala Wireshark.
|
boolean |
equals(Object other)
Check whether to buffers are considered to be equal.
|
boolean |
equalsIgnoreCase(Object other) |
byte[] |
getArray()
Get the backing array.
|
byte |
getByte(int index)
Get the byte at the index.
|
byte |
getByte(long 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.
|
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 |
hasWriteSupport()
Check whether this
Buffer has write support or not. |
boolean |
isEmpty()
Check whether this buffer is empty or not.
|
void |
markReaderIndex()
Mark the current position of the reader index.
|
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() |
short |
readUnsignedByte() |
long |
readUnsignedInt()
Read an unsigned int and will increase the reader index of this buffer by
4
|
int |
readUnsignedShort() |
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. |
checkReadableBytes, checkReadableBytesSafe, checkWritableBytesSafe, indexOf, indexOf, isByteInArray, parseToInt, parseToInt, readLine, readUntil, readUntil, readUntilDoubleCRLF, readUntilSafe, readUntilSingleCRLFpublic static final int DEFAULT_CAPACITY
public BoundedInputStreamBuffer(InputStream is)
public BoundedInputStreamBuffer(int bufferCapacity,
InputStream is)
bufferCapacity - To be sure that the PCAP framer works, this needs to be same or larger than SNAPLENGTH used to get PCAP.
Default SNAPLENGTH of tcpdump is 262144. If using '-s NNN' parameter of tcpdump, you should also be able
to reduce this to a lower value for less memory usage.is - 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 IndexOutOfBoundsException,
IOException
IOExceptionIndexOutOfBoundsException - in case there is nothing left to readpublic byte peekByte()
throws IndexOutOfBoundsException,
IOException
IndexOutOfBoundsException - in case there is nothing left to readIOExceptionpublic Buffer readBytes(int length) throws IndexOutOfBoundsException, IOException
IOExceptionIndexOutOfBoundsExceptionpublic int getReadableBytes()
InputStream may be able to read more off the stream,
however, it may not be able to do so without blocking.public boolean hasReadableBytes()
Buffer.getReadableBytes() > 0IOExceptionIndexOutOfBoundsExceptionpublic boolean isEmpty()
!Buffer.hasReadableBytes()public byte[] getArray()
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.IndexOutOfBoundsException - in case the index is greater than the capacity of this bufferIOExceptionpublic byte getByte(long index)
throws IndexOutOfBoundsException,
IOException
IndexOutOfBoundsExceptionIOExceptionpublic long readUnsignedInt()
throws IndexOutOfBoundsException
IndexOutOfBoundsException - in case there is not 4 bytes left to readpublic int readInt()
throws IndexOutOfBoundsException
IndexOutOfBoundsException - in case there is not 4 bytes left to readpublic int getInt(int index)
throws IndexOutOfBoundsException
IndexOutOfBoundsException - in case there is not 4 bytes left to readpublic short getShort(int index)
throws IndexOutOfBoundsException
IndexOutOfBoundsExceptionpublic int readUnsignedShort()
throws IndexOutOfBoundsException
IndexOutOfBoundsExceptionpublic int getUnsignedShort(int index)
throws IndexOutOfBoundsException
IndexOutOfBoundsExceptionpublic short readShort()
throws IndexOutOfBoundsException
IndexOutOfBoundsExceptionpublic long getUnsignedInt(int index)
throws IndexOutOfBoundsException
IndexOutOfBoundsExceptionpublic short getUnsignedByte(int index)
throws IndexOutOfBoundsException
IndexOutOfBoundsExceptionpublic String dumpAsHex()
public void setByte(int index,
byte value)
throws IndexOutOfBoundsException
index - the indexvalue - the valueIndexOutOfBoundsExceptionpublic void setUnsignedByte(int index,
short value)
throws IndexOutOfBoundsException
IndexOutOfBoundsExceptionpublic void setUnsignedShort(int index,
int value)
throws IndexOutOfBoundsException
IndexOutOfBoundsExceptionpublic Buffer clone()
Bufferclone in interface Bufferclone in class BaseBufferpublic boolean equals(Object other)
public boolean equalsIgnoreCase(Object other)
public int hashCode()
public String toString()
public int getWritableBytes()
Bufferpublic boolean hasWritableBytes()
BufferBuffer has any space left for writing. Same
as Buffer.getWritableBytes() > 0hasWritableBytes in interface BufferhasWritableBytes in class BaseBufferpublic void write(byte[] bytes)
throws IndexOutOfBoundsException,
WriteNotSupportedException
public void getBytes(Buffer dst)
BufferBuffer.getBytes(int, Buffer) where the index is
Buffer.getReaderIndex().public void getBytes(byte[] dst)
throws IndexOutOfBoundsException
IndexOutOfBoundsExceptionpublic 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.IndexOutOfBoundsException - in case index < 0public void setInt(int index,
int value)
throws IndexOutOfBoundsException
IndexOutOfBoundsExceptionpublic void write(int value)
throws IndexOutOfBoundsException,
WriteNotSupportedException
public void write(long value)
throws IndexOutOfBoundsException,
WriteNotSupportedException
public void writeAsString(int value)
throws IndexOutOfBoundsException,
WriteNotSupportedException
BufferBuffer as a String.value - 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.value - the value that will be converted to a String before being written to this
Buffer.IndexOutOfBoundsExceptionWriteNotSupportedExceptionpublic void setUnsignedInt(int index,
long value)
throws IndexOutOfBoundsException
IndexOutOfBoundsExceptionpublic 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 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.public void setWriterIndex(int index)
public void setReaderIndex(int index)
public int getReaderIndex()
Bufferpublic int getWriterIndex()
Bufferpublic final short readUnsignedByte()
throws IndexOutOfBoundsException,
IOException
IndexOutOfBoundsExceptionIOExceptionpublic int capacity()
Bufferpublic void resetReaderIndex()
Bufferpublic void markReaderIndex()
Buffer#reset()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.public int getUpperBoundary()
BufferBuffer.getLowerBoundary() since this is the same, just
the upper limit of that raw array.public Buffer slice(int stop)
Buffer#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.Copyright © 2021. All Rights Reserved.