Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.http.util

public final Class CharChunk

extends Object
implements Chunk, Cloneable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Cloneable, org.glassfish.grizzly.http.util.Chunk
Imports
java.io.CharConversionException, .IOException, .Serializable, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.Charset, .CharsetDecoder, .CoderResult, java.util.Arrays, org.glassfish.grizzly.Buffer, org.glassfish.grizzly.utils.Charsets

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
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 String
public static final Charset
DEFAULT_HTTP_CHARSET

Default encoding used to convert to strings.

private int
private transient CharChunk.CharInputChannel
private boolean
private int
private boolean
private transient CharChunk.CharOutputChannel
private static final long
private int

Constructor Summary

AccessConstructor and Description
public
CharChunk()

Creates a new, uninitialized CharChunk object.

public
CharChunk(int size)

Method Summary

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

public void
append(char b)

public void
public void
append(char[] src, int off, int len)

Add data to the buffer

public void
append(StringBuffer sb)

Add data to the buffer

public void
append(String s)

Append a string to the buffer

public void
append(String s, int off, int len)

Append a string to the buffer

public void
delete(final int start, final int end)

Implements org.glassfish.grizzly.http.util.Chunk.delete.

public boolean
public void
ensureCapacity(final int size)

public boolean
equals(Object o)

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
(CharSequence
the String to compare
s
)

Compares the message bytes to the specified String object.

public boolean

Returns:

true if the comparison succeeded, false otherwise
equals
(byte[]
the byte[] to compare
b
)

Compares the message bytes to the specified byte array representing ASCII characters.

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

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

public boolean

Returns:

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

Compares the message bytes to the specified String object.

public boolean

Returns:

true if the comparison succeeded, false otherwise
equalsIgnoreCase
(final byte[]
the byte[] to compare
b
)

Compares the message bytes to the specified byte array representing ASCII characters.

public boolean

Returns:

true if the comparison succeeded, false otherwise
equalsIgnoreCase
(final byte[]
the byte[] to compare
b
,
final int offset, final int len)

Compares the message bytes to the specified byte array representing ASCII characters.

public boolean

Returns:

true if the comparison succeeded, false otherwise
equalsIgnoreCase
(final char[]
the char[] to compare
b
,
final int offset, final int len)

Compares the message bytes to the specified char array representing ASCII characters.

public boolean

Returns:

true if the comparison succeeded, false otherwise
equalsIgnoreCaseLowerCase
(final byte[]
the byte[] to compare
b
)

Compares the char chunk to the specified byte array representing lower-case ASCII characters.

public void
public char[]
public char[]
public CharChunk
public int
public int
public int
getLength()

Implements org.glassfish.grizzly.http.util.Chunk.getLength.

Returns the length of the bytes.

public int
public int
getStart()

Implements org.glassfish.grizzly.http.util.Chunk.getStart.

Returns the start offset of the bytes.

public int
hash()

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public int
public int
indexOf(char c)

public int
indexOf(char
the character
c
,
int starting)

Implements org.glassfish.grizzly.http.util.Chunk.indexOf.

Returns true if the message bytes starts with the specified string.

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

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

public boolean
pack-priv void
makeSpace(int count)

Make space for len chars.

private int
min(int a, int b)

protected void
notifyDirectUpdate()

Notify the Chunk that its content is going to be changed directly

public void
recycle()

Resets the message bytes to an uninitialized state.

public void
protected void
public void
set(final ByteChunk byteChunk, final Charset encoding)

Set ByteChunk content to CharChunk using given Charset.

public void
set(final BufferChunk bufferChunk, final Charset encoding)

Set BufferChunk content to CharChunk using given Charset.

public void
setCharInputChannel(CharChunk.CharInputChannel in)

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

public void
setCharOutputChannel(CharChunk.CharOutputChannel out)

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

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

public void
public void
setLimit(int limit)

Maximum amount of data in this buffer.

public void
setOptimizedWrite(boolean optimizedWrite)

public void
setStart(int start)

Implements org.glassfish.grizzly.http.util.Chunk.setStart.

Returns the start offset of the bytes.

public boolean
startsWith(String
the string
s
)

Returns true if the message bytes starts with the specified string.

pack-priv boolean
startsWith(final String s, final int pos)

public boolean
startsWithIgnoreCase(final String
the string
s
,
final int pos)

Returns true if the message bytes starts with the specified string.

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

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public String
public String
public void
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

buffback to summary
private char[] buff
cachedStringback to summary
private String cachedString
DEFAULT_HTTP_CHARSETback to summary
public static final Charset DEFAULT_HTTP_CHARSET

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.

endback to summary
private int end
inback to summary
private transient CharChunk.CharInputChannel in
isSetback to summary
private boolean isSet
limitback to summary
private int limit
optimizedWriteback to summary
private boolean optimizedWrite
outback to summary
private transient CharChunk.CharOutputChannel out
serialVersionUIDback to summary
private static final long serialVersionUID
startback to summary
private int start

Constructor Detail

CharChunkback to summary
public CharChunk()

Creates a new, uninitialized CharChunk object.

CharChunkback to summary
public CharChunk(int size)

Method Detail

allocateback to summary
public void allocate(int initial, int limit)
appendback to summary
public void append(char b) 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

appendback to summary
public void append(StringBuffer sb) throws IOException

Add data to the buffer

appendback to summary
public void append(String s) throws IOException

Append a string to the buffer

appendback to summary
public void append(String s, int off, int len) throws IOException

Append a string to the buffer

deleteback to summary
public void delete(final int start, final int end)

Implements org.glassfish.grizzly.http.util.Chunk.delete.

Annotations
@Override
endsWithback to summary
public boolean endsWith(String s)
ensureCapacityback to summary
public void ensureCapacity(final int size)
equalsback to summary
public boolean equals(Object o)

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.

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

Compares the message bytes to the specified String object.

Parameters
s:CharSequence

the String to compare

Returns:boolean

true if the comparison succeeded, false otherwise

equalsback to summary
public boolean equals(byte[] b)

Compares the message bytes to the specified byte array representing ASCII characters.

Parameters
b:byte[]

the byte[] to compare

Returns:boolean

true if the comparison succeeded, false otherwise

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

Compares the message bytes to the specified String object.

Parameters
s:CharSequence

the String to compare

Returns:boolean

true if the comparison succeeded, false otherwise

equalsIgnoreCaseback to summary
public boolean equalsIgnoreCase(final byte[] b)

Compares the message bytes to the specified byte array representing ASCII characters.

Parameters
b:byte[]

the byte[] to compare

Returns:boolean

true if the comparison succeeded, false otherwise

Since
2.1.2
equalsIgnoreCaseback to summary
public boolean equalsIgnoreCase(final byte[] b, final int offset, final int len)

Compares the message bytes to the specified byte array representing ASCII characters.

Parameters
b:byte[]

the byte[] to compare

Returns:boolean

true if the comparison succeeded, false otherwise

Since
2.3
equalsIgnoreCaseback to summary
public boolean equalsIgnoreCase(final char[] b, final int offset, final int len)

Compares the message bytes to the specified char array representing ASCII characters.

Parameters
b:char[]

the char[] to compare

Returns:boolean

true if the comparison succeeded, false otherwise

Since
2.3
equalsIgnoreCaseLowerCaseback to summary
public boolean equalsIgnoreCaseLowerCase(final byte[] b)

Compares the char chunk to the specified byte array representing lower-case ASCII characters.

Parameters
b:byte[]

the byte[] to compare

Returns:boolean

true if the comparison succeeded, false otherwise

Since
2.1.2
flushBufferback to summary
public void flushBuffer() throws IOException
getBufferback to summary
public char[] getBuffer()
getCharsback to summary
public char[] getChars()
getCloneback to summary
public CharChunk getClone()
getEndback to summary
public int getEnd()

Implements org.glassfish.grizzly.http.util.Chunk.getEnd.

Annotations
@Override
getIntback to summary
public int getInt()
getLengthback to summary
public int getLength()

Implements org.glassfish.grizzly.http.util.Chunk.getLength.

Returns the length of the bytes.

Annotations
@Override
getLimitback to summary
public int getLimit()
getStartback to summary
public int getStart()

Implements org.glassfish.grizzly.http.util.Chunk.getStart.

Returns the start offset of the bytes. For output this is the end of the buffer.

Annotations
@Override
hashback to summary
public int hash()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
hashIgnoreCaseback to summary
public int hashIgnoreCase()
indexOfback to summary
public int indexOf(char c)
indexOfback to summary
public int indexOf(char c, int starting)

Implements org.glassfish.grizzly.http.util.Chunk.indexOf.

Returns true if the message bytes starts with the specified string.

Parameters
c:char

the character

Annotations
@Override
indexOfback to summary
public static int indexOf(char[] chars, int off, int cend, char qq)
indexOfback to summary
public int indexOf(String s, int fromIndex)

Implements org.glassfish.grizzly.http.util.Chunk.indexOf.

Annotations
@Override
indexOfback to summary
public int indexOf(String src, int srcOff, int srcLen, int myOff)
isNullback to summary
public boolean isNull()
makeSpaceback to summary
pack-priv void makeSpace(int count)

Make space for len chars. If len is small, allocate a reserve space too. Never grow bigger than limit.

minback to summary
private int min(int a, int b)
notifyDirectUpdateback to summary
protected void notifyDirectUpdate()

Notify the Chunk that its content is going to be changed directly

recycleback to summary
public void recycle()

Resets the message bytes to an uninitialized state.

resetback to summary
public void reset()
resetStringCacheback to summary
protected void resetStringCache()
setback to summary
public void set(final ByteChunk byteChunk, final Charset encoding) throws CharConversionException

Set ByteChunk content to CharChunk using given Charset.

setback to summary
public void set(final BufferChunk bufferChunk, final Charset encoding) throws CharConversionException

Set BufferChunk content to CharChunk using given Charset.

setCharInputChannelback to summary
public void setCharInputChannel(CharChunk.CharInputChannel in)

When the buffer is empty, read the data from 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.

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

Implements org.glassfish.grizzly.http.util.Chunk.setEnd.

Annotations
@Override
setLimitback to summary
public void setLimit(int limit)

Maximum amount of data in this buffer. If -1 or not set, the buffer will grow indefinitely. 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.

setOptimizedWriteback to summary
public void setOptimizedWrite(boolean optimizedWrite)
setStartback to summary
public void setStart(int start)

Implements org.glassfish.grizzly.http.util.Chunk.setStart.

Returns the start offset of the bytes.

Annotations
@Override
startsWithback to summary
public boolean startsWith(String s)

Returns true if the message bytes starts with the specified string.

Parameters
s:String

the string

startsWithback to summary
pack-priv boolean startsWith(final String s, final int pos)
startsWithIgnoreCaseback to summary
public boolean startsWithIgnoreCase(final String s, final int pos)

Returns true if the message bytes starts with the specified string.

Parameters
s:String

the string

substractback to summary
public int substract() throws IOException
substractback to summary
public int substract(CharChunk src) throws IOException
substractback to summary
public int substract(char[] src, int off, int len) throws IOException
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
toStringback to summary
public String toString(int start, int end)

Implements org.glassfish.grizzly.http.util.Chunk.toString.

Annotations
@Override
toStringInternalback to summary
public String toStringInternal()
trimLeftback to summary
public void trimLeft()
org.glassfish.grizzly.http.util back to summary

public Interface CharChunk.CharInputChannel


Method Summary

Modifier and TypeMethod and Description
public int
realReadChars(char[] cbuf, int off, int len)

Read new bytes ( usually the internal conversion buffer ).

Method Detail

realReadCharsback to summary
public int realReadChars(char[] cbuf, int off, int len) throws IOException

Read new bytes ( usually the internal conversion buffer ). The implementation is allowed to ignore the parameters, and mutate the chunk if it wishes to implement its own buffering.

org.glassfish.grizzly.http.util 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[] cbuf, int off, int len)

Send the bytes ( usually the internal conversion buffer ).

Method Detail

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

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