| java.lang.Object com.nabhinc.util.md.ByteChunk
ByteChunk | final public class ByteChunk implements Cloneable,Serializable(Code) | | 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.
There are 2 modes: The chunk can be associated with a sink - ByteInputChannel or ByteOutputChannel,
which will be used when the buffer is empty ( on input ) or filled ( on output ).
For output, it can also grow. This operating mode is selected by calling setLimit() or
allocate(initial, limit) with limit != -1.
Various search and append method are defined - similar with String and StringBuffer, but
operating on bytes.
This is important because it allows processing the http headers directly on the received bytes,
without converting to chars and Strings until the strings are needed. In addition, the charset
is determined later, from headers or user code.
author: dac@sun.com author: James Todd [gonzo@sun.com] author: Costin Manolache author: Remy Maucherat |
Inner Class :public static interface ByteInputChannel | |
Inner Class :public static interface ByteOutputChannel | |
Constructor Summary | |
public | ByteChunk() Creates a new, uninitialized ByteChunk object. | public | ByteChunk(int initial) |
Method Summary | |
public void | allocate(int initial, int limit) | public void | append(char c) Append a char, by casting it to byte. | public void | append(byte b) | public void | append(ByteChunk src) | public void | append(byte src, int off, int len) | final public static byte[] | convertToBytes(String value) Convert specified String to a byte array. | public boolean | equals(String s) Compares the message bytes to the specified String object. | public 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 | equalsIgnoreCase(String s) Compares the message bytes to the specified String object. | public static int | findChar(byte buf, int start, int end, char c) Find a character, no side effects. | public static int | findChars(byte buf, int start, int end, byte c) Find a character, no side effects. | public static int | findNotChars(byte buf, int start, int end, byte c) | public void | flushBuffer() Send the buffer to the sink. | public byte[] | getBuffer() Returns the message bytes. | public byte[] | getBytes() Returns the message bytes. | public ByteChunk | getClone() | public String | getEncoding() | public int | getEnd() | public int | getInt() | public int | getLength() Returns the length of the bytes. | public int | getLimit() | public long | getLong() | public int | getOffset() | public int | getStart() Returns the start offset of the bytes. | public int | hash() | public int | hashIgnoreCase() | public int | indexOf(String src, int srcOff, int srcLen, int myOff) | public int | indexOf(char c, int starting) Returns true if the message bytes starts with the specified string. | public static int | indexOf(byte bytes, int off, int end, char qq) | public boolean | isNull() | public void | recycle() Resets the message buff to an uninitialized state. | public void | reset() | public void | setByteInputChannel(ByteInputChannel in) When the buffer is empty, read the data from the input channel. | public void | setByteOutputChannel(ByteOutputChannel out) When the buffer is full, write the data to the output channel. | public void | setBytes(byte[] b, int off, int len) Sets the message bytes to the specified subarray of bytes. | public void | setEncoding(String enc) | public void | setEnd(int i) | public void | setLimit(int limit) Maximum amount of data in this buffer. | public void | setOffset(int off) | public void | setOptimizedWrite(boolean optimizedWrite) | public boolean | startsWith(String s) Returns true if the message bytes starts with the specified string. | public boolean | startsWith(byte[] b2) | public boolean | startsWithIgnoreCase(String s, int pos) Returns true if the message bytes starts with the specified string. | public int | substract() | public int | substract(ByteChunk src) | public int | substract(byte src, int off, int len) | public String | toString() | public String | toStringInternal() |
DEFAULT_CHARACTER_ENCODING | final public static String DEFAULT_CHARACTER_ENCODING(Code) | | Default encoding used to convert to strings. It should be UTF8,
as most standards seem to converge, but the servlet API requires
8859_1, and this object is used mostly for servlets.
|
ByteChunk | public ByteChunk()(Code) | | Creates a new, uninitialized ByteChunk object.
|
ByteChunk | public ByteChunk(int initial)(Code) | | |
allocate | public void allocate(int initial, int limit)(Code) | | |
append | public void append(char c) throws IOException(Code) | | Append a char, by casting it to byte. This IS NOT intended for unicode.
Parameters: c - throws: IOException - |
append | public void append(byte src, int off, int len) throws IOException(Code) | | Add data to the buffer
|
convertToBytes | final public static byte[] convertToBytes(String value)(Code) | | Convert specified String to a byte array. This ONLY WORKS for ascii, UTF chars will be truncated.
Parameters: value - to convert to byte array the byte array value |
equals | public boolean equals(String s)(Code) | | Compares the message bytes to the specified String object.
Parameters: s - the String to compare true if the comparison succeeded, false otherwise |
equals | public boolean equals(byte b2, int off2, int len2)(Code) | | |
equals | public boolean equals(char c2, int off2, int len2)(Code) | | |
equalsIgnoreCase | public boolean equalsIgnoreCase(String s)(Code) | | Compares the message bytes to the specified String object.
Parameters: s - the String to compare true if the comparison succeeded, false otherwise |
findChar | public static int findChar(byte buf, int start, int end, char c)(Code) | | Find a character, no side effects.
index of char if found, -1 if not |
findChars | public static int findChars(byte buf, int start, int end, byte c)(Code) | | Find a character, no side effects.
index of char if found, -1 if not |
findNotChars | public static int findNotChars(byte buf, int start, int end, byte c)(Code) | | Find the first character != c
index of char if found, -1 if not |
flushBuffer | public void flushBuffer() throws IOException(Code) | | Send the buffer to the sink. Called by append() when the limit is reached.
You can also call it explicitely to force the data to be written.
throws: IOException - |
getBuffer | public byte[] getBuffer()(Code) | | Returns the message bytes.
|
getBytes | public byte[] getBytes()(Code) | | Returns the message bytes.
|
getEnd | public int getEnd()(Code) | | |
getInt | public int getInt()(Code) | | |
getLength | public int getLength()(Code) | | Returns the length of the bytes.
XXX need to clean this up
|
getLimit | public int getLimit()(Code) | | |
getLong | public long getLong()(Code) | | |
getOffset | public int getOffset()(Code) | | |
getStart | public int getStart()(Code) | | Returns the start offset of the bytes.
For output this is the end of the buffer.
|
hashIgnoreCase | public int hashIgnoreCase()(Code) | | |
indexOf | public int indexOf(String src, int srcOff, int srcLen, int myOff)(Code) | | |
indexOf | public int indexOf(char c, int starting)(Code) | | Returns true if the message bytes starts with the specified string.
Parameters: c - the character Parameters: starting - The start position |
indexOf | public static int indexOf(byte bytes, int off, int end, char qq)(Code) | | |
isNull | public boolean isNull()(Code) | | |
recycle | public void recycle()(Code) | | Resets the message buff to an uninitialized state.
|
reset | public void reset()(Code) | | |
setByteInputChannel | public void setByteInputChannel(ByteInputChannel in)(Code) | | When the buffer is empty, read the data from the input channel.
|
setByteOutputChannel | public void setByteOutputChannel(ByteOutputChannel out)(Code) | | 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)(Code) | | Sets the message bytes to the specified subarray of bytes.
Parameters: b - the ascii bytes Parameters: off - the start offset of the bytes Parameters: len - the length of the bytes |
setEnd | public void setEnd(int i)(Code) | | |
setLimit | public void setLimit(int limit)(Code) | | 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)(Code) | | |
setOptimizedWrite | public void setOptimizedWrite(boolean optimizedWrite)(Code) | | |
startsWith | public boolean startsWith(String s)(Code) | | Returns true if the message bytes starts with the specified string.
Parameters: s - the string |
startsWith | public boolean startsWith(byte[] b2)(Code) | | |
startsWithIgnoreCase | public boolean startsWithIgnoreCase(String s, int pos)(Code) | | Returns true if the message bytes starts with the specified string.
Parameters: s - the string Parameters: pos - The position |
|
|