org.apache.tomcat.util.buf

Class CharChunk

public final class CharChunk extends Object implements Cloneable, Serializable, CharSequence

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.

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

Nested Class Summary
static interfaceCharChunk.CharInputChannel
static interfaceCharChunk.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
voidallocate(int initial, int limit)
voidappend(char b)
voidappend(CharChunk src)
voidappend(char[] src, int off, int len)
Add data to the buffer
voidappend(StringBuffer sb)
Add data to the buffer
voidappend(String s)
Append a string to the buffer
voidappend(String s, int off, int len)
Append a string to the buffer
charcharAt(int index)
booleanequals(String s)
Compares the message bytes to the specified String object.
booleanequals(CharChunk cc)
booleanequals(char[] b2, int off2, int len2)
booleanequals(byte[] b2, int off2, int len2)
booleanequalsIgnoreCase(String s)
Compares the message bytes to the specified String object.
voidflushBuffer()
char[]getBuffer()
char[]getChars()
CharChunkgetClone()
intgetEnd()
intgetInt()
intgetLength()
Returns the length of the bytes.
intgetLimit()
intgetOffset()
intgetStart()
Returns the start offset of the bytes.
inthash()
inthashIgnoreCase()
intindexOf(char c)
intindexOf(char c, int starting)
Returns true if the message bytes starts with the specified string.
static intindexOf(char[] chars, int off, int cend, char qq)
intindexOf(String src, int srcOff, int srcLen, int myOff)
booleanisNull()
intlength()
voidrecycle()
Resets the message bytes to an uninitialized state.
voidreset()
voidsetCharInputChannel(CharChunk.CharInputChannel in)
When the buffer is empty, read the data from the input channel.
voidsetCharOutputChannel(CharChunk.CharOutputChannel out)
When the buffer is full, write the data to the output channel.
voidsetChars(char[] c, int off, int len)
voidsetEnd(int i)
voidsetLimit(int limit)
Maximum amount of data in this buffer.
voidsetOffset(int off)
Returns the start offset of the bytes.
voidsetOptimizedWrite(boolean optimizedWrite)
booleanstartsWith(String s)
Returns true if the message bytes starts with the specified string.
booleanstartsWithIgnoreCase(String s, int pos)
Returns true if the message bytes starts with the specified string.
intsubstract()
intsubstract(CharChunk src)
intsubstract(char[] src, int off, int len)
CharSequencesubSequence(int start, int end)
StringtoString()
StringtoStringInternal()

Constructor Detail

CharChunk

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

CharChunk

public CharChunk(int size)

Method Detail

allocate

public void allocate(int initial, int limit)

append

public void append(char b)

append

public void append(CharChunk src)

append

public void append(char[] src, int off, int len)
Add data to the buffer

append

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

append

public void append(String s)
Append a string to the buffer

append

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

charAt

public char charAt(int index)

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(CharChunk cc)

equals

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

equals

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

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()

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(char c)

indexOf

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

Parameters: c the character

indexOf

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

indexOf

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

isNull

public boolean isNull()

length

public int length()

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()

substract

public int substract(CharChunk src)

substract

public int substract(char[] src, int off, int len)

subSequence

public CharSequence subSequence(int start, int end)

toString

public String toString()

toStringInternal

public String toStringInternal()
Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.