Package org.glassfish.grizzly.http.util
Class CharChunk
- java.lang.Object
-
- org.glassfish.grizzly.http.util.CharChunk
-
- All Implemented Interfaces:
Serializable,Cloneable,Chunk
public final class CharChunk extends Object implements Chunk, Cloneable, Serializable
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 Summary
Nested Classes Modifier and Type Class Description static interfaceCharChunk.CharInputChannelstatic 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 Modifier and Type Field Description static CharsetDEFAULT_HTTP_CHARSETDefault encoding used to convert to strings.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidallocate(int initial, int limit)voidappend(char b)voidappend(char[] src, int off, int len)Add data to the buffervoidappend(String s)Append a string to the buffervoidappend(StringBuffer sb)Add data to the buffervoidappend(String s, int off, int len)Append a string to the buffervoidappend(CharChunk src)voiddelete(int start, int end)booleanendsWith(String s)voidensureCapacity(int size)booleanequals(byte[] b)Compares the message bytes to the specified byte array representing ASCII characters.booleanequals(byte[] b2, int off2, int len2)booleanequals(char[] b2, int off2, int len2)booleanequals(CharSequence s)Compares the message bytes to the specified String object.booleanequals(Object o)booleanequals(CharChunk cc)booleanequalsIgnoreCase(byte[] b)Compares the message bytes to the specified byte array representing ASCII characters.booleanequalsIgnoreCase(byte[] b, int offset, int len)Compares the message bytes to the specified byte array representing ASCII characters.booleanequalsIgnoreCase(char[] b, int offset, int len)Compares the message bytes to the specified char array representing ASCII characters.booleanequalsIgnoreCase(CharSequence s)Compares the message bytes to the specified String object.booleanequalsIgnoreCaseLowerCase(byte[] b)Compares the char chunk to the specified byte array representing lower-case ASCII characters.voidflushBuffer()char[]getBuffer()char[]getChars()CharChunkgetClone()intgetEnd()intgetInt()intgetLength()Returns the length of the bytes.intgetLimit()intgetStart()Returns the start offset of the bytes.inthash()inthashCode()inthashIgnoreCase()intindexOf(char c)static intindexOf(char[] chars, int off, int cend, char qq)intindexOf(char c, int starting)Returns true if the message bytes starts with the specified string.intindexOf(String s, int fromIndex)intindexOf(String src, int srcOff, int srcLen, int myOff)booleanisNull()protected voidnotifyDirectUpdate()Notify the Chunk that its content is going to be changed directlyvoidrecycle()Resets the message bytes to an uninitialized state.voidreset()protected voidresetStringCache()voidset(BufferChunk bufferChunk, Charset encoding)SetBufferChunkcontent to CharChunk using givenCharset.voidset(ByteChunk byteChunk, Charset encoding)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.voidsetOptimizedWrite(boolean optimizedWrite)voidsetStart(int start)Returns the start offset of the bytes.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(char[] src, int off, int len)intsubstract(CharChunk src)StringtoString()StringtoString(int start, int end)StringtoStringInternal()voidtrimLeft()
-
-
-
Field Detail
-
DEFAULT_HTTP_CHARSET
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.
-
-
Method Detail
-
getClone
public CharChunk getClone()
-
isNull
public boolean isNull()
-
recycle
public void recycle()
Resets the message bytes to an uninitialized state.
-
reset
public void reset()
-
allocate
public void allocate(int initial, int limit)
-
ensureCapacity
public void ensureCapacity(int size)
-
setOptimizedWrite
public void setOptimizedWrite(boolean optimizedWrite)
-
setChars
public void setChars(char[] c, int off, int len)
-
setLimit
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.
-
getLimit
public int getLimit()
-
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.
-
getChars
public char[] getChars()
-
getBuffer
public char[] getBuffer()
-
getStart
public int getStart()
Returns the start offset of the bytes. For output this is the end of the buffer.
-
setStart
public void setStart(int start)
Returns the start offset of the bytes.
-
getLength
public int getLength()
Returns the length of the bytes.
-
append
public void append(char b) throws IOException- Throws:
IOException
-
append
public void append(CharChunk src) throws IOException
- Throws:
IOException
-
append
public void append(char[] src, int off, int len) throws IOExceptionAdd data to the buffer- Throws:
IOException
-
append
public void append(StringBuffer sb) throws IOException
Add data to the buffer- Throws:
IOException
-
append
public void append(String s) throws IOException
Append a string to the buffer- Throws:
IOException
-
append
public void append(String s, int off, int len) throws IOException
Append a string to the buffer- Throws:
IOException
-
substract
public int substract() throws IOException- Throws:
IOException
-
substract
public int substract(CharChunk src) throws IOException
- Throws:
IOException
-
substract
public int substract(char[] src, int off, int len) throws IOException- Throws:
IOException
-
flushBuffer
public void flushBuffer() throws IOException- Throws:
IOException
-
notifyDirectUpdate
protected void notifyDirectUpdate()
Notify the Chunk that its content is going to be changed directly
-
resetStringCache
protected void resetStringCache()
-
toStringInternal
public String toStringInternal()
-
getInt
public int getInt()
-
set
public void set(ByteChunk byteChunk, Charset encoding) throws CharConversionException
- Throws:
CharConversionException
-
set
public void set(BufferChunk bufferChunk, Charset encoding) throws CharConversionException
SetBufferChunkcontent to CharChunk using givenCharset.- Throws:
CharConversionException
-
equals
public boolean equals(CharSequence 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(byte[] b)
Compares the message bytes to the specified byte array representing ASCII characters.- Parameters:
b- thebyte[]to compare- Returns:
- true if the comparison succeeded, false otherwise
- Since:
- 2.3
-
equalsIgnoreCase
public boolean equalsIgnoreCase(CharSequence s)
Compares the message bytes to the specified String object.- Parameters:
s- the String to compare- Returns:
- true if the comparison succeeded, false otherwise
-
equalsIgnoreCase
public boolean equalsIgnoreCase(byte[] b)
Compares the message bytes to the specified byte array representing ASCII characters.- Parameters:
b- thebyte[]to compare- Returns:
- true if the comparison succeeded, false otherwise
- Since:
- 2.1.2
-
equalsIgnoreCase
public boolean equalsIgnoreCase(byte[] b, int offset, int len)Compares the message bytes to the specified byte array representing ASCII characters.- Parameters:
b- thebyte[]to compare- Returns:
- true if the comparison succeeded, false otherwise
- Since:
- 2.3
-
equalsIgnoreCase
public boolean equalsIgnoreCase(char[] b, int offset, int len)Compares the message bytes to the specified char array representing ASCII characters.- Parameters:
b- thechar[]to compare- Returns:
- true if the comparison succeeded, false otherwise
- Since:
- 2.3
-
equalsIgnoreCaseLowerCase
public boolean equalsIgnoreCaseLowerCase(byte[] b)
Compares the char chunk to the specified byte array representing lower-case ASCII characters.- Parameters:
b- thebyte[]to compare- Returns:
- true if the comparison succeeded, false otherwise
- Since:
- 2.1.2
-
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)
-
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
-
endsWith
public boolean endsWith(String s)
-
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.
-
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)
-
trimLeft
public void trimLeft()
-
-