org.apache.tomcat.util.buf

Class CharChunk

Implemented Interfaces:
Cloneable, Serializable

public final class CharChunk
extends java.lang.Object
implements Cloneable, Serializable

Utilities to manipluate char chunks. While String is the easiest way to manipulate chars ( search, substrings, etc), it is known to not be the most efficient solution - Strings are designed as imutable and secure objects.

Authors:
dac@sun.com
James Todd [gonzo@sun.com]
Costin Manolache
Remy Maucherat

Nested Class Summary

static interface
CharChunk.CharInputChannel
static interface
CharChunk.CharOutputChannel
When we need more space we'll either grow the buffer ( up to the limit ) or send it to a channel.

Constructor Summary

CharChunk()
Creates a new, uninitialized CharChunk object.
CharChunk(int size)

Method Summary

void
allocate(int initial, int limit)
void
append(String s, int off, int len)
Append a string to the buffer
void
append(StringBuffer sb)
Add data to the buffer
void
append(char b)
void
append(CharChunk src)
void
append(src[] , int off, int len)
Add data to the buffer
boolean
equals(String s)
Compares the message bytes to the specified String object.
boolean
equals(b2[] , int off2, int len2)
boolean
equals(b2[] , int off2, int len2)
boolean
equals(CharChunk cc)
boolean
equalsIgnoreCase(String s)
Compares the message bytes to the specified String object.
void
flushBuffer()
char[]
getBuffer()
char[]
getChars()
CharChunk
getClone()
int
getEnd()
int
getInt()
int
getLength()
Returns the length of the bytes.
int
getLimit()
int
getOffset()
int
getStart()
Returns the start offset of the bytes.
int
hash()
int
hashIgnoreCase()
int
indexOf(String src, int srcOff, int srcLen, int myOff)
int
indexOf(char c)
int
indexOf(char c, int starting)
Returns true if the message bytes starts with the specified string.
static int
indexOf(chars[] , int off, int cend, char qq)
boolean
isNull()
void
recycle()
Resets the message bytes to an uninitialized state.
void
reset()
void
setCharInputChannel(CharChunk.CharInputChannel in)
When the buffer is empty, read the data from the input channel.
void
setCharOutputChannel(CharChunk.CharOutputChannel out)
When the buffer is full, write the data to the output channel.
void
setChars(char[] c, int off, int len)
void
setEnd(int i)
void
setLimit(int limit)
Maximum amount of data in this buffer.
void
setOffset(int off)
Returns the start offset of the bytes.
void
setOptimizedWrite(boolean optimizedWrite)
boolean
startsWith(String s)
Returns true if the message bytes starts with the specified string.
boolean
startsWithIgnoreCase(String s, int pos)
Returns true if the message bytes starts with the specified string.
int
substract()
int
substract(CharChunk src)
int
substract(src[] , int off, int len)
String
toString()

Constructor Details

CharChunk

public CharChunk()
Creates a new, uninitialized CharChunk object.


CharChunk

public CharChunk(int size)

Method Details

allocate

public void allocate(int initial,
                     int limit)


append

public void append(String s,
                   int off,
                   int len)
            throws IOException
Append a string to the buffer


append

public void append(StringBuffer sb)
            throws IOException
Add data to the buffer


append

public void append(char b)
            throws IOException


append

public void append(CharChunk 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.

Parameters:
s - the String to compare

Returns:
true if the comparison succeeded, false otherwise


equals

public boolean equals(b2[] ,
                      int off2,
                      int len2)


equals

public boolean equals(b2[] ,
                      int off2,
                      int len2)


equals

public boolean equals(CharChunk cc)


equalsIgnoreCase

public boolean equalsIgnoreCase(String s)
Compares the message bytes to the specified String object.

Parameters:
s - the String to compare

Returns:
true if the comparison succeeded, false otherwise


flushBuffer

public void flushBuffer()
            throws IOException


getBuffer

public char[] getBuffer()


getChars

public char[] getChars()


getClone

public CharChunk getClone()


getEnd

public int getEnd()


getInt

public int getInt()


getLength

public int getLength()
Returns the length of the bytes.


getLimit

public int getLimit()


getOffset

public int getOffset()


getStart

public int getStart()
Returns the start offset of the bytes. For output this is the end of the buffer.


hash

public int hash()


hashIgnoreCase

public int hashIgnoreCase()


indexOf

public int indexOf(String src,
                   int srcOff,
                   int srcLen,
                   int myOff)


indexOf

public int indexOf(char c)


indexOf

public int indexOf(char c,
                   int starting)
Returns true if the message bytes starts with the specified string.

Parameters:


indexOf

public static int indexOf(chars[] ,
                          int off,
                          int cend,
                          char qq)


isNull

public boolean isNull()


recycle

public void recycle()
Resets the message bytes to an uninitialized state.


reset

public void reset()


setCharInputChannel

public void setCharInputChannel(CharChunk.CharInputChannel in)
When the buffer is empty, read the data from the input channel.


setCharOutputChannel

public void setCharOutputChannel(CharChunk.CharOutputChannel 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.


setChars

public void setChars(char[] c,
                     int off,
                     int len)


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)
Returns the start offset of the bytes.


setOptimizedWrite

public void setOptimizedWrite(boolean optimizedWrite)


startsWith

public boolean startsWith(String s)
Returns true if the message bytes starts with the specified string.

Parameters:
s - the string


startsWithIgnoreCase

public boolean startsWithIgnoreCase(String s,
                                    int pos)
Returns true if the message bytes starts with the specified string.

Parameters:
s - the string


substract

public int substract()
            throws IOException


substract

public int substract(CharChunk src)
            throws IOException


substract

public int substract(src[] ,
                     int off,
                     int len)
            throws IOException


toString

public String toString()


Copyright B) 2000-2003 Apache Software Foundation. All Rights Reserved.