Home » apache-tomcat-6.0.26-src » org.apache » tomcat » util » buf » [javadoc | source]
org.apache.tomcat.util.buf
public final class: ByteChunk [javadoc | source]
java.lang.Object
   org.apache.tomcat.util.buf.ByteChunk

All Implemented Interfaces:
    Cloneable, Serializable

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.
Nested Class Summary:
public static interface  ByteChunk.ByteInputChannel  Input interface, used when the buffer is emptiy Same as java.nio.channel.ReadableByteChannel 
public static interface  ByteChunk.ByteOutputChannel  Same as java.nio.channel.WrittableByteChannel. 
Field Summary
public static final  String DEFAULT_CHARACTER_ENCODING    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. 
Constructor:
 public ByteChunk() 
 public ByteChunk(int initial) 
Method from org.apache.tomcat.util.buf.ByteChunk Summary:
allocate,   append,   append,   append,   append,   convertToBytes,   equals,   equals,   equals,   equals,   equals,   equalsIgnoreCase,   findChar,   findChars,   findNotChars,   flushBuffer,   getBuffer,   getBytes,   getClone,   getEncoding,   getEnd,   getInt,   getLength,   getLimit,   getLong,   getOffset,   getStart,   hash,   hashIgnoreCase,   indexOf,   indexOf,   indexOf,   isNull,   recycle,   reset,   setByteInputChannel,   setByteOutputChannel,   setBytes,   setEncoding,   setEnd,   setLimit,   setOffset,   setOptimizedWrite,   startsWith,   startsWith,   startsWithIgnoreCase,   substract,   substract,   substract,   toString,   toStringInternal
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.tomcat.util.buf.ByteChunk Detail:
 public  void allocate(int initial,
    int limit) 
 public  void append(char c) throws IOException 
    Append a char, by casting it to byte. This IS NOT intended for unicode.
 public  void append(byte b) throws IOException 
 public  void append(ByteChunk src) throws IOException 
 public  void append(byte[] src,
    int off,
    int len) throws IOException 
    Add data to the buffer
 public static final byte[] convertToBytes(String value) 
    Convert specified String to a byte array. This ONLY WORKS for ascii, UTF chars will be truncated.
 public boolean equals(String s) 
    Compares the message bytes to the specified String object.
 public boolean equals(ByteChunk bb) 
 public boolean equals(CharChunk cc) 
 public boolean equals(byte[] b2,
    int off2,
    int len2) 
 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) 
    Find the first character != c
 public  void flushBuffer() throws IOException 
    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.
 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. XXX need to clean this up
 public int getLimit() 
 public long getLong() 
 public int getOffset() 
 public int getStart() 
    Returns the start offset of the bytes. For output this is the end of the buffer.
 public int hash() 
 public int hashIgnoreCase() 
 public int indexOf(char c,
    int starting) 
    Returns true if the message bytes starts with the specified string.
 public int indexOf(String src,
    int srcOff,
    int srcLen,
    int myOff) 
 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. Also used when large amount of data is appended. If not set, the buffer will grow to the limit.
 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. 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.
 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() throws IOException 
 public int substract(ByteChunk src) throws IOException 
 public int substract(byte[] src,
    int off,
    int len) throws IOException 
 public String toString() 
 public String toStringInternal()