Package org.apache.tomcat.util.buf
Class CharChunk
- java.lang.Object
- 
- org.apache.tomcat.util.buf.AbstractChunk
- 
- org.apache.tomcat.util.buf.CharChunk
 
 
- 
- All Implemented Interfaces:
- java.io.Serializable,- java.lang.CharSequence,- java.lang.Cloneable
 
 public final class CharChunk extends AbstractChunk implements java.lang.CharSequence Utilities to manipulate 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 immutable and secure objects.- Author:
- dac@sun.com, James Todd [gonzo@sun.com], Costin Manolache, Remy Maucherat
- See Also:
- Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static interfaceCharChunk.CharInputChannelInput interface, used when the buffer is empty.static interfaceCharChunk.CharOutputChannelWhen we need more space we'll either grow the buffer ( up to the limit ) or send it to a channel.
 - 
Field Summary- 
Fields inherited from class org.apache.tomcat.util.buf.AbstractChunkARRAY_MAX_SIZE, end, hasHashCode, isSet, sm, start
 
- 
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidallocate(int initial, int limit)voidappend(char c)voidappend(char[] src, int off, int len)Add data to the buffer.voidappend(java.lang.String s)Append a string to the buffer.voidappend(java.lang.String s, int off, int len)Append a string to the buffer.voidappend(CharChunk src)charcharAt(int index)java.lang.Objectclone()booleanendsWith(java.lang.String s)booleanequals(char[] b2, int off2, int len2)booleanequals(java.lang.Object obj)booleanequals(java.lang.String s)Compares the message bytes to the specified String object.booleanequals(CharChunk cc)booleanequalsIgnoreCase(java.lang.String s)Compares the message bytes to the specified String object.voidflushBuffer()Send the buffer to the sink.char[]getBuffer()protected intgetBufferElement(int index)char[]getChars()intindexOf(char c)static intindexOf(char[] chars, int start, int end, char s)Returns the first instance of the given character in the given char array between the specified start and end.intindexOf(char c, int starting)Returns the first instance of the given character in this CharChunk starting at the specified char.intlength()voidmakeSpace(int count)Make space for len chars.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)Sets the buffer to the specified subarray of characters.voidsetOptimizedWrite(boolean optimizedWrite)Deprecated.Unused code.booleanstartsWith(java.lang.String s)booleanstartsWithIgnoreCase(java.lang.String s, int pos)Returns true if the buffer starts with the specified string.java.lang.CharSequencesubSequence(int start, int end)intsubstract()Deprecated.intsubstract(char[] dest, int off, int len)Deprecated.intsubtract()intsubtract(char[] dest, int off, int len)java.lang.StringtoString()java.lang.StringtoStringInternal()- 
Methods inherited from class org.apache.tomcat.util.buf.AbstractChunkgetEnd, getLength, getLimit, getLimitInternal, getOffset, getStart, hash, hashCode, indexOf, isNull, recycle, setEnd, setLimit, setOffset
 
- 
 
- 
- 
- 
Method Detail- 
clonepublic java.lang.Object clone() throws java.lang.CloneNotSupportedException- Overrides:
- clonein class- java.lang.Object
- Throws:
- java.lang.CloneNotSupportedException
 
 - 
allocatepublic void allocate(int initial, int limit)
 - 
setCharspublic void setChars(char[] c, int off, int len)Sets the buffer to the specified subarray of characters.- Parameters:
- c- the characters
- off- the start offset of the characters
- len- the length of the characters
 
 - 
getCharspublic char[] getChars() - Returns:
- the buffer.
 
 - 
getBufferpublic char[] getBuffer() - Returns:
- the buffer.
 
 - 
setCharInputChannelpublic void setCharInputChannel(CharChunk.CharInputChannel in) When the buffer is empty, read the data from the input channel.- Parameters:
- in- The input channel
 
 - 
setCharOutputChannelpublic 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.- Parameters:
- out- The output channel
 
 - 
appendpublic void append(char c) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
appendpublic void append(CharChunk src) throws java.io.IOException - Throws:
- java.io.IOException
 
 - 
appendpublic void append(char[] src, int off, int len) throws java.io.IOExceptionAdd data to the buffer.- Parameters:
- src- Char array
- off- Offset
- len- Length
- Throws:
- java.io.IOException- Writing overflow data to the output channel failed
 
 - 
appendpublic void append(java.lang.String s) throws java.io.IOExceptionAppend a string to the buffer.- Parameters:
- s- The string
- Throws:
- java.io.IOException- Writing overflow data to the output channel failed
 
 - 
appendpublic void append(java.lang.String s, int off, int len) throws java.io.IOExceptionAppend a string to the buffer.- Parameters:
- s- The string
- off- Offset
- len- Length
- Throws:
- java.io.IOException- Writing overflow data to the output channel failed
 
 - 
substract@Deprecated public int substract() throws java.io.IOExceptionDeprecated.- Throws:
- java.io.IOException
 
 - 
subtractpublic int subtract() throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
substract@Deprecated public int substract(char[] dest, int off, int len) throws java.io.IOExceptionDeprecated.- Throws:
- java.io.IOException
 
 - 
subtractpublic int subtract(char[] dest, int off, int len) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
flushBufferpublic void flushBuffer() throws java.io.IOExceptionSend the buffer to the sink. Called by append() when the limit is reached. You can also call it explicitly to force the data to be written.- Throws:
- java.io.IOException- Writing overflow data to the output channel failed
 
 - 
makeSpacepublic void makeSpace(int count) Make space for len chars. If len is small, allocate a reserve space too. Never grow bigger than the limit orAbstractChunk.ARRAY_MAX_SIZE.- Parameters:
- count- The size
 
 - 
toStringpublic java.lang.String toString() - Specified by:
- toStringin interface- java.lang.CharSequence
- Overrides:
- toStringin class- java.lang.Object
 
 - 
toStringInternalpublic java.lang.String toStringInternal() 
 - 
equalspublic boolean equals(java.lang.Object obj) - Overrides:
- equalsin class- java.lang.Object
 
 - 
equalspublic boolean equals(java.lang.String s) Compares the message bytes to the specified String object.- Parameters:
- s- the String to compare
- Returns:
- trueif the comparison succeeded,- falseotherwise
 
 - 
equalsIgnoreCasepublic boolean equalsIgnoreCase(java.lang.String s) Compares the message bytes to the specified String object.- Parameters:
- s- the String to compare
- Returns:
- trueif the comparison succeeded,- falseotherwise
 
 - 
equalspublic boolean equals(CharChunk cc) 
 - 
equalspublic boolean equals(char[] b2, int off2, int len2)
 - 
startsWithpublic boolean startsWith(java.lang.String s) - Parameters:
- s- The string
- Returns:
- trueif the message bytes starts with the specified string.
 
 - 
startsWithIgnoreCasepublic boolean startsWithIgnoreCase(java.lang.String s, int pos)Returns true if the buffer starts with the specified string.- Parameters:
- s- the string
- pos- The position
- Returns:
- trueif the start matches
 
 - 
endsWithpublic boolean endsWith(java.lang.String s) - Parameters:
- s- The string
- Returns:
- trueif the message bytes end with the specified string.
 
 - 
getBufferElementprotected int getBufferElement(int index) - Specified by:
- getBufferElementin class- AbstractChunk
 
 - 
indexOfpublic int indexOf(char c) 
 - 
indexOfpublic int indexOf(char c, int starting)Returns the first instance of the given character in this CharChunk starting at the specified char. If the character is not found, -1 is returned.- Parameters:
- c- The character
- starting- The start position
- Returns:
- The position of the first instance of the character or -1 if the character is not found.
 
 - 
indexOfpublic static int indexOf(char[] chars, int start, int end, char s)Returns the first instance of the given character in the given char array between the specified start and end.- Parameters:
- chars- The array to search
- start- The point to start searching from in the array
- end- The point to stop searching in the array
- s- The character to search for
- Returns:
- The position of the first instance of the character or -1 if the character is not found.
 
 - 
charAtpublic char charAt(int index) - Specified by:
- charAtin interface- java.lang.CharSequence
 
 - 
subSequencepublic java.lang.CharSequence subSequence(int start, int end)- Specified by:
- subSequencein interface- java.lang.CharSequence
 
 - 
lengthpublic int length() - Specified by:
- lengthin interface- java.lang.CharSequence
 
 - 
setOptimizedWrite@Deprecated public void setOptimizedWrite(boolean optimizedWrite) Deprecated.Unused code. This is now a NO-OP and will be removed without replacement in Tomcat 10.NO-OP.- Parameters:
- optimizedWrite- Ignored
 
 
- 
 
-