public final class ByteChunk extends AbstractChunk
| Modifier and Type | Class and Description |
|---|---|
static interface |
ByteChunk.ByteInputChannel
Input interface, used when the buffer is empty.
|
static interface |
ByteChunk.ByteOutputChannel
When we need more space we'll either grow the buffer ( up to the limit )
or send it to a channel.
|
| Modifier and Type | Field and Description |
|---|---|
static Charset |
DEFAULT_CHARSET
Default encoding used to convert to strings.
|
ARRAY_MAX_SIZE, end, hasHashCode, isSet, start| Constructor and Description |
|---|
ByteChunk()
Creates a new, uninitialized ByteChunk object.
|
ByteChunk(int initial) |
| Modifier and Type | Method and Description |
|---|---|
void |
allocate(int initial,
int limit) |
void |
append(byte b) |
void |
append(byte[] src,
int off,
int len)
Add data to the buffer.
|
void |
append(ByteBuffer from)
Add data to the buffer.
|
void |
append(ByteChunk src) |
Object |
clone() |
static byte[] |
convertToBytes(String value)
Convert specified String to a byte array.
|
boolean |
equals(byte[] b2,
int off2,
int len2) |
boolean |
equals(ByteChunk bb) |
boolean |
equals(char[] c2,
int off2,
int len2) |
boolean |
equals(CharChunk cc) |
boolean |
equals(Object obj) |
boolean |
equals(String s)
Compares the message bytes to the specified String object.
|
boolean |
equalsIgnoreCase(String s)
Compares the message bytes to the specified String object.
|
static int |
findByte(byte[] bytes,
int start,
int end,
byte b)
Returns the first instance of the given byte in the byte array between
the specified start and end.
|
static int |
findBytes(byte[] bytes,
int start,
int end,
byte[] b)
Returns the first instance of any of the given bytes in the byte array
between the specified start and end.
|
void |
flushBuffer()
Send the buffer to the sink.
|
byte[] |
getBuffer() |
protected int |
getBufferElement(int index) |
byte[] |
getBytes() |
Charset |
getCharset() |
long |
getLong() |
static int |
indexOf(byte[] bytes,
int start,
int end,
char s)
Returns the first instance of the given character in the given byte array
between the specified start and end.
|
int |
indexOf(char c,
int starting)
Returns the first instance of the given character in this ByteChunk
starting at the specified byte.
|
void |
makeSpace(int count)
Make space for len bytes.
|
void |
recycle()
Resets the chunk to an uninitialized state.
|
void |
setByteInputChannel(ByteChunk.ByteInputChannel in)
When the buffer is empty, read the data from the input channel.
|
void |
setByteOutputChannel(ByteChunk.ByteOutputChannel out)
When the buffer is full, write the data to the output channel.
|
void |
setBytes(byte[] b,
int off,
int len)
Sets the buffer to the specified subarray of bytes.
|
void |
setCharset(Charset charset) |
boolean |
startsWith(String s,
int pos)
Returns true if the buffer starts with the specified string when tested
in a case sensitive manner.
|
boolean |
startsWithIgnoreCase(String s,
int pos)
Returns true if the buffer starts with the specified string when tested
in a case insensitive manner.
|
int |
substract() |
int |
substract(byte[] dest,
int off,
int len) |
int |
substract(ByteBuffer to)
Transfers bytes from the buffer to the specified ByteBuffer.
|
byte |
substractB() |
String |
toString() |
String |
toStringInternal() |
public static final Charset DEFAULT_CHARSET
public ByteChunk()
public ByteChunk(int initial)
public Object clone() throws CloneNotSupportedException
clone in class ObjectCloneNotSupportedExceptionpublic void recycle()
AbstractChunkrecycle in class AbstractChunkpublic void allocate(int initial,
int limit)
public void setBytes(byte[] b,
int off,
int len)
b - the ascii bytesoff - the start offset of the byteslen - the length of the bytespublic void setCharset(Charset charset)
public Charset getCharset()
public byte[] getBytes()
public byte[] getBuffer()
public void setByteInputChannel(ByteChunk.ByteInputChannel in)
in - The input channelpublic void setByteOutputChannel(ByteChunk.ByteOutputChannel out)
out - The output channelpublic void append(byte b)
throws IOException
IOExceptionpublic void append(ByteChunk src) throws IOException
IOExceptionpublic void append(byte[] src,
int off,
int len)
throws IOException
src - Bytes arrayoff - Offsetlen - LengthIOException - Writing overflow data to the output channel failedpublic void append(ByteBuffer from) throws IOException
from - the ByteBuffer with the dataIOException - Writing overflow data to the output channel failedpublic int substract()
throws IOException
IOExceptionpublic byte substractB()
throws IOException
IOExceptionpublic int substract(byte[] dest,
int off,
int len)
throws IOException
IOExceptionpublic int substract(ByteBuffer to) throws IOException
to - the ByteBuffer into which bytes are to be written.IOException - if an input or output exception has occurredpublic void flushBuffer()
throws IOException
IOException - Writing overflow data to the output channel failedpublic void makeSpace(int count)
AbstractChunk.ARRAY_MAX_SIZE.count - The sizepublic String toStringInternal()
public long getLong()
public boolean equals(String s)
s - the String to comparetrue if the comparison succeeded, false
otherwisepublic boolean equalsIgnoreCase(String s)
s - the String to comparetrue if the comparison succeeded, false
otherwisepublic boolean equals(ByteChunk bb)
public boolean equals(byte[] b2,
int off2,
int len2)
public boolean equals(CharChunk cc)
public boolean equals(char[] c2,
int off2,
int len2)
public boolean startsWith(String s, int pos)
s - the stringpos - The positiontrue if the start matchespublic boolean startsWithIgnoreCase(String s, int pos)
s - the stringpos - The positiontrue if the start matchesprotected int getBufferElement(int index)
getBufferElement in class AbstractChunkpublic int indexOf(char c,
int starting)
c - The characterstarting - The start positionpublic static int indexOf(byte[] bytes,
int start,
int end,
char s)
bytes - The array to searchstart - The point to start searching from in the arrayend - The point to stop searching in the arrays - The character to search forpublic static int findByte(byte[] bytes,
int start,
int end,
byte b)
bytes - The byte array to searchstart - The point to start searching from in the byte arrayend - The point to stop searching in the byte arrayb - The byte to search forpublic static int findBytes(byte[] bytes,
int start,
int end,
byte[] b)
bytes - The byte array to searchstart - The point to start searching from in the byte arrayend - The point to stop searching in the byte arrayb - The array of bytes to search forpublic static final byte[] convertToBytes(String value)
value - to convert to byte arrayCopyright © 2000-2021 Apache Software Foundation. All Rights Reserved.