public class FlexBuffer extends Object
Modifier and Type | Class and Description |
---|---|
class |
FlexBuffer.Tokenizer
A tokenizer for the FlexBuffer.
|
Modifier and Type | Field and Description |
---|---|
static byte |
CR
Carriage return.
|
static byte |
LF
Line feed.
|
static byte |
WS
White space.
|
Constructor and Description |
---|
FlexBuffer(byte[] backingArray)
Constructs a FlexBuffer with an initial backing array.
|
FlexBuffer(byte[] origin,
int start,
int length)
Constructs a FlexBuffer with initial content.
|
FlexBuffer(int initial)
FlexBuffer constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
append(byte b)
Appends one byte to the buffer.
|
void |
append(byte[] b)
Appends the content from the whole byte array to the buffer.
|
void |
append(byte[] b,
int offset,
int length)
Appends content from byte array to the buffer.
|
void |
append(ByteBuffer b,
int length)
Appends content of the nio ByteBuffer of a certain length.
|
void |
appendDirect(ByteBuffer b,
int length)
Appends content of the nio direct ByteBuffer of a certain length
to the FlexBuffer.
|
void |
clear()
Clears the FlexBuffer.
|
boolean |
endsWith(String s)
Checks if the string ends with provided string.
|
int |
getByte(int pos)
Obtains the byte a a certain position in the buffer.
|
byte[] |
getBytes()
Gets a byte array resembling the whole buffer.
|
int |
getBytes(int pos,
byte[] b,
int off,
int length)
Copies buffer content into byte array.
|
byte[] |
getBytes(int pos,
int length)
Gets a byte array resembling part of the buffer.
|
String |
getString(int pos,
int length)
Obtains a String representation of all or part of the buffer.
|
FlexBuffer.Tokenizer |
getTokenizer()
Returns Tokenizer instance.
|
String |
getTrimmedString(int pos,
int length)
Trims the string based on the position and the length.
|
int |
indexOf(String s)
Searches the byte buffer for the first occurrence of
the input string, converted to bytes.
|
int |
indexOf(String s,
int start)
Searches the byte buffer for the first occurrence of
the input string from a starting index, converted to bytes.
|
int |
indexOfBOL(int eol)
Obtains the index of the next line begin, given the EOL marker.
|
int |
indexOfEOL(int start)
Searches the buffer for an end-of-line.
|
protected void |
nextBuffer()
Switches the buffer to the next one.
|
int |
size()
Obtains the size of this buffer.
|
String |
toString()
Provides a String representation of the buffer content.
|
int |
writeBytes(int pos,
int length,
OutputStream stream)
Writes buffer content into an OutputStream.
|
int |
writeBytes(OutputStream stream)
Writes buffer content into an OutputStream.
|
public static final byte CR
public static final byte LF
public static final byte WS
public FlexBuffer(int initial)
initial
- The initial size and expansion blockpublic FlexBuffer(byte[] origin, int start, int length)
origin
- the byte array to take content fromstart
- the starting offset in the byte arraylength
- the content length to copypublic FlexBuffer(byte[] backingArray)
backingArray
- The byte array to be used as a backing array.public void clear()
protected void nextBuffer()
public void append(byte b)
b
- byte to appendpublic void append(byte[] b, int offset, int length)
b
- byte array to appendoffset
- the offset to start appendinglength
- the length to start appendingpublic void append(byte[] b)
b
- byte array to appendpublic void append(ByteBuffer b, int length)
b
- The bufferlength
- appendpublic void appendDirect(ByteBuffer b, int length)
b
- The bufferlength
- The length to appendpublic int size()
public byte[] getBytes()
public byte[] getBytes(int pos, int length)
pos
- starting position in the bufferlength
- content lengthpublic int getBytes(int pos, byte[] b, int off, int length)
pos
- position to start copy in the bufferb
- byte array to copy intooff
- offset in the byte array to start copylength
- content length to copypublic int writeBytes(int pos, int length, OutputStream stream) throws IOException
pos
- position to start copy in the bufferlength
- content length to copystream
- the output stream to write toIOException
- write errorpublic int writeBytes(OutputStream stream) throws IOException
stream
- the output stream to write toIOException
- write errorpublic String getString(int pos, int length)
pos
- The starting positionlength
- The lengthpublic String getTrimmedString(int pos, int length)
pos
- The starting positionlength
- The lengthpublic int getByte(int pos)
pos
- the position of the bytepublic int indexOf(String s)
s
- the string to matchpublic boolean endsWith(String s)
s
- The string to check the buffer againstpublic int indexOf(String s, int start)
s
- the string to matchstart
- the search starting pointpublic int indexOfEOL(int start)
start
- The offset to start searchingpublic int indexOfBOL(int eol)
Note: the method does not actually check that
eol
- The EOL indexpublic String toString()
public FlexBuffer.Tokenizer getTokenizer()