This class is used to represent a chunk of bytes, and
utilities to manipulate byte[].
The buffer can be modified and used for both input and output.
allocate
public void allocate(int initial,
int limit)
append
public void append(byte b)
throws IOException
append
public void append(char c)
throws IOException
append
public void append(ByteChunk src)
throws IOException
append
public void append(src[] ,
int off,
int len)
throws IOException
Add data to the buffer
equals
public boolean equals(String s)
Compares the message bytes to the specified String object.
s
- the String to compare
- true if the comparison succeeded, false otherwise
equals
public boolean equals(b2[] ,
int off2,
int len2)
equals
public boolean equals(c2[] ,
int off2,
int len2)
equalsIgnoreCase
public boolean equalsIgnoreCase(String s)
Compares the message bytes to the specified String object.
s
- the String to compare
- true if the comparison succeeded, false otherwise
findChar
public static int findChar(buf[] ,
int start,
int end,
char c)
Find a character, no side effects.
findChars
public static int findChars(buf[] ,
int start,
int end,
c[] )
Find a character, no side effects.
findNotChars
public static int findNotChars(buf[] ,
int start,
int end,
c[] )
Find the first character != c
flushBuffer
public void flushBuffer()
throws IOException
getBuffer
public byte[] getBuffer()
Returns the message bytes.
getBytes
public byte[] getBytes()
Returns the message bytes.
getEnd
public int getEnd()
getInt
public int getInt()
getLength
public int getLength()
Returns the length of the bytes.
XXX need to clean this up
getLimit
public int getLimit()
getLong
public long getLong()
getOffset
public int getOffset()
getStart
public int getStart()
Returns the start offset of the bytes.
For output this is the end of the buffer.
hashIgnoreCase
public int hashIgnoreCase()
indexOf
public int indexOf(String src,
int srcOff,
int srcLen,
int myOff)
indexOf
public static int indexOf(bytes[] ,
int off,
int end,
char qq)
indexOf
public int indexOf(char c,
int starting)
Returns true if the message bytes starts with the specified string.
isNull
public boolean isNull()
recycle
public void recycle()
Resets the message buff to an uninitialized state.
setByteInputChannel
public void setByteInputChannel(ByteChunk.ByteInputChannel in)
When the buffer is empty, read the data from the input channel.
setByteOutputChannel
public void setByteOutputChannel(ByteChunk.ByteOutputChannel out)
When the buffer is full, write the data to the output channel.
Also used when large amount of data is appended.
If not set, the buffer will grow to the limit.
setBytes
public void setBytes(byte[] b,
int off,
int len)
Sets the message bytes to the specified subarray of bytes.
b
- the ascii bytesoff
- the start offset of the byteslen
- the length of the bytes
setEncoding
public void setEncoding(String enc)
setEnd
public void setEnd(int i)
setLimit
public void setLimit(int limit)
Maximum amount of data in this buffer.
If -1 or not set, the buffer will grow undefinitely.
Can be smaller than the current buffer size ( which will not shrink ).
When the limit is reached, the buffer will be flushed ( if out is set )
or throw exception.
setOffset
public void setOffset(int off)
setOptimizedWrite
public void setOptimizedWrite(boolean optimizedWrite)
startsWith
public boolean startsWith(String s)
Returns true if the message bytes starts with the specified string.
s
- the string
startsWith
public boolean startsWith(byte[] b2)
startsWithIgnoreCase
public boolean startsWithIgnoreCase(String s,
int pos)
Returns true if the message bytes starts with the specified string.
s
- the string
substract
public int substract()
throws IOException
substract
public int substract(ByteChunk src)
throws IOException
substract
public int substract(src[] ,
int off,
int len)
throws IOException
toString
public String toString()