Top Description Inners Fields Constructors Methods
org.apache.tomcat.util.buf

public final Class CharChunk

extends AbstractChunk
implements CharSequence
Class Inheritance
All Implemented Interfaces
java.lang.CharSequence
Imports
java.io.IOException

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.
Authors
[email protected], James Todd [[email protected]], Costin Manolache, Remy Maucherat

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
CharChunk.CharInputChannel

Input interface, used when the buffer is empty.

public 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.

Field Summary

Modifier and TypeField and Description
private char[]
private transient CharChunk.CharInputChannel
private transient CharChunk.CharOutputChannel
private static final long
Inherited from org.apache.tomcat.util.buf.AbstractChunk:
ARRAY_MAX_SIZEendhasHashCodeisSetsmstart

Constructor Summary

AccessConstructor and Description
public
CharChunk()

Creates a new, uninitialized CharChunk object.

public
CharChunk(int initial)

Method Summary

Modifier and TypeMethod and Description
public void
allocate(int initial, int limit)

public void
append(char c)

public void
public void
append(char[]
Char array
src
,
int
Offset
off
,
int
Length
len
)

Add data to the buffer.

public void
append(String
The string
s
)

Append a string to the buffer.

public void
append(String
The string
s
,
int
Offset
off
,
int
Length
len
)

Append a string to the buffer.

public char
charAt(int
the index of the char value to be returned
index
)

Implements java.lang.CharSequence.charAt.

Returns the char value at the specified index.

private boolean
public Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.

public boolean

Returns:

true if the message bytes end with the specified string.
endsWith
(String
The string
s
)

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public boolean

Returns:

true if the comparison succeeded, false otherwise
equals
(String
the String to compare
s
)

Compares the message bytes to the specified String object.

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

public boolean

Returns:

true if the comparison succeeded, false otherwise
equalsIgnoreCase
(String
the String to compare
s
)

Compares the message bytes to the specified String object.

public void
flushBuffer()

Send the buffer to the sink.

public char[]

Returns:

the buffer.
getBuffer
()

protected int
public char[]

Returns:

the buffer.
getChars
()

public int
indexOf(char c)

public int

Returns:

The position of the first instance of the character or -1 if the character is not found.
indexOf
(char
The character
c
,
int
The start position
starting
)

Returns the first instance of the given character in this CharChunk starting at the specified char.

public static int

Returns:

The position of the first instance of the character or -1 if the character is not found.
indexOf
(char[]
The array to search
chars
,
int
The point to start searching from in the array
start
,
int
The point to stop searching in the array
end
,
char
The character to search for
s
)

Returns the first instance of the given character in the given char array between the specified start and end.

public int
length()

Implements java.lang.CharSequence.length.

Returns the length of this character sequence.

public void
makeSpace(int
The size
count
)

Make space for len chars.

private int
min(int a, int b)

public void
setCharInputChannel(CharChunk.CharInputChannel
The input channel
in
)

When the buffer is empty, read the data from the input channel.

public void
setCharOutputChannel(CharChunk.CharOutputChannel
The output channel
out
)

When the buffer is full, write the data to the output channel.

public void
setChars(char[]
the characters
c
,
int
the start offset of the characters
off
,
int
the length of the characters
len
)

Sets the buffer to the specified subarray of characters.

public boolean

Returns:

true if the message bytes starts with the specified string.
startsWith
(String
The string
s
)

public boolean

Returns:

true if the start matches
startsWithIgnoreCase
(String
the string
s
,
int
The position
pos
)

Returns true if the buffer starts with the specified string.

public CharSequence
subSequence(int
the start index, inclusive
start
,
int
the end index, exclusive
end
)

Implements java.lang.CharSequence.subSequence.

Returns a CharSequence that is a subsequence of this sequence.

public int
public int
subtract(char[] dest, int off, int len)

public String
toString()

Overrides java.lang.Object.toString.

Implements java.lang.CharSequence.toString.

Returns a string containing the characters in this sequence in the same order as this sequence.

public String
Inherited from org.apache.tomcat.util.buf.AbstractChunk:
getEndgetLengthgetLimitgetLimitInternalgetOffsetgetStarthashhashCodeindexOfisNullrecyclesetEndsetLimitsetOffset

Field Detail

buffback to summary
private char[] buff
inback to summary
private transient CharChunk.CharInputChannel in
outback to summary
private transient CharChunk.CharOutputChannel out
serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.tomcat.util.buf.AbstractChunk.serialVersionUID.

Constructor Detail

CharChunkback to summary
public CharChunk()

Creates a new, uninitialized CharChunk object.

CharChunkback to summary
public CharChunk(int initial)

Method Detail

allocateback to summary
public void allocate(int initial, int limit)
appendback to summary
public void append(char c) throws IOException
appendback to summary
public void append(CharChunk src) throws IOException
appendback to summary
public void append(char[] src, int off, int len) throws IOException

Add data to the buffer.

Parameters
src:char[]

Char array

off:int

Offset

len:int

Length

Exceptions
IOException:
Writing overflow data to the output channel failed
appendback to summary
public void append(String s) throws IOException

Append a string to the buffer.

Parameters
s:String

The string

Exceptions
IOException:
Writing overflow data to the output channel failed
appendback to summary
public void append(String s, int off, int len) throws IOException

Append a string to the buffer.

Parameters
s:String

The string

off:int

Offset

len:int

Length

Exceptions
IOException:
Writing overflow data to the output channel failed
charAtback to summary
public char charAt(int index)

Implements java.lang.CharSequence.charAt.

Doc from java.lang.CharSequence.charAt.

Returns the char value at the specified index. An index ranges from zero to length() - 1. The first char value of the sequence is at index zero, the next at index one, and so on, as for array indexing.

If the char value specified by the index is a surrogate, the surrogate value is returned.

Parameters
index:int

the index of the char value to be returned

Returns:char

the specified char value

Annotations
@Override
checkEofback to summary
private boolean checkEof() throws IOException
cloneback to summary
public Object clone() throws CloneNotSupportedException

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Object

a clone of this instance.

Annotations
@Override
Exceptions
CloneNotSupportedException:
if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.
endsWithback to summary
public boolean endsWith(String s)
Parameters
s:String

The string

Returns:boolean

true if the message bytes end with the specified string.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
equalsback to summary
public boolean equals(String s)

Compares the message bytes to the specified String object.

Parameters
s:String

the String to compare

Returns:boolean

true if the comparison succeeded, false otherwise

equalsback to summary
public boolean equals(CharChunk cc)
equalsback to summary
public boolean equals(char[] b2, int off2, int len2)
equalsIgnoreCaseback to summary
public boolean equalsIgnoreCase(String s)

Compares the message bytes to the specified String object.

Parameters
s:String

the String to compare

Returns:boolean

true if the comparison succeeded, false otherwise

flushBufferback to summary
public void flushBuffer() throws IOException

Send 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.

Exceptions
IOException:
Writing overflow data to the output channel failed
getBufferback to summary
public char[] getBuffer()
Returns:char[]

the buffer.

getBufferElementback to summary
protected int getBufferElement(int index)

Implements abstract org.apache.tomcat.util.buf.AbstractChunk.getBufferElement.

Annotations
@Override
getCharsback to summary
public char[] getChars()
Returns:char[]

the buffer.

indexOfback to summary
public int indexOf(char c)
indexOfback to summary
public 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:char

The character

starting:int

The start position

Returns:int

The position of the first instance of the character or -1 if the character is not found.

indexOfback to summary
public 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:char[]

The array to search

start:int

The point to start searching from in the array

end:int

The point to stop searching in the array

s:char

The character to search for

Returns:int

The position of the first instance of the character or -1 if the character is not found.

lengthback to summary
public int length()

Implements java.lang.CharSequence.length.

Doc from java.lang.CharSequence.length.

Returns the length of this character sequence. The length is the number of 16-bit chars in the sequence.

Returns:int

the number of chars in this sequence

Annotations
@Override
makeSpaceback to summary
public void makeSpace(int count)

Make space for len chars. If len is small, allocate a reserve space too. Never grow bigger than the limit or AbstractChunk#ARRAY_MAX_SIZE.

Parameters
count:int

The size

minback to summary
private int min(int a, int b)
setCharInputChannelback to summary
public void setCharInputChannel(CharChunk.CharInputChannel in)

When the buffer is empty, read the data from the input channel.

Parameters
in:CharChunk.CharInputChannel

The input channel

setCharOutputChannelback to summary
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.

Parameters
out:CharChunk.CharOutputChannel

The output channel

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

Sets the buffer to the specified subarray of characters.

Parameters
c:char[]

the characters

off:int

the start offset of the characters

len:int

the length of the characters

startsWithback to summary
public boolean startsWith(String s)
Parameters
s:String

The string

Returns:boolean

true if the message bytes starts with the specified string.

startsWithIgnoreCaseback to summary
public boolean startsWithIgnoreCase(String s, int pos)

Returns true if the buffer starts with the specified string.

Parameters
s:String

the string

pos:int

The position

Returns:boolean

true if the start matches

subSequenceback to summary
public CharSequence subSequence(int start, int end)

Implements java.lang.CharSequence.subSequence.

Doc from java.lang.CharSequence.subSequence.

Returns a CharSequence that is a subsequence of this sequence. The subsequence starts with the char value at the specified index and ends with the char value at index end - 1. The length (in chars) of the returned sequence is end - start, so if start == end then an empty sequence is returned.

Parameters
start:int

the start index, inclusive

end:int

the end index, exclusive

Returns:CharSequence

the specified subsequence

Annotations
@Override
subtractback to summary
public int subtract() throws IOException
subtractback to summary
public int subtract(char[] dest, int off, int len) throws IOException
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements java.lang.CharSequence.toString.

Doc from java.lang.CharSequence.toString.

Returns a string containing the characters in this sequence in the same order as this sequence. The length of the string will be the length of this sequence.

Returns:String

a string consisting of exactly this sequence of characters

Annotations
@Override
toStringInternalback to summary
public String toStringInternal()
org.apache.tomcat.util.buf back to summary

public Interface CharChunk.CharInputChannel


Input interface, used when the buffer is empty.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

The number of characters read
realReadChars
()

Read new characters.

Method Detail

realReadCharsback to summary
public int realReadChars() throws IOException

Read new characters.

Returns:int

The number of characters read

Exceptions
IOException:
If an I/O error occurs during reading
org.apache.tomcat.util.buf back to summary

public Interface CharChunk.CharOutputChannel


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

Method Summary

Modifier and TypeMethod and Description
public void
realWriteChars(char[]
characters that will be written
buf
,
int
offset in the characters array
off
,
int
length that will be written
len
)

Send the bytes ( usually the internal conversion buffer ).

Method Detail

realWriteCharsback to summary
public void realWriteChars(char[] buf, int off, int len) throws IOException

Send the bytes ( usually the internal conversion buffer ). Expect 8k output if the buffer is full.

Parameters
buf:char[]

characters that will be written

off:int

offset in the characters array

len:int

length that will be written

Exceptions
IOException:
If an I/O occurs while writing the characters