java.lang.Object
org.glassfish.grizzly.http.util.CharChunk
- All Implemented Interfaces:
Serializable,Cloneable,Chunk
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interfaceWhen we need more space we'll either grow the buffer ( up to the limit ) or send it to a channel. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CharsetDefault encoding used to convert to strings. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidallocate(int initial, int limit) voidappend(char b) voidappend(char[] src, int off, int len) Add data to the buffervoidAppend a string to the buffervoidappend(StringBuffer sb) Add data to the buffervoidAppend a string to the buffervoidvoiddelete(int start, int end) booleanvoidensureCapacity(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) booleanCompares the message bytes to the specified String object.booleanbooleanbooleanequalsIgnoreCase(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.booleanCompares 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.voidchar[]char[]getChars()getClone()intgetEnd()intgetInt()intReturns the length of the bytes.intgetLimit()intgetStart()Returns the start offset of the bytes.inthash()inthashCode()intintindexOf(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.intintbooleanisNull()protected voidNotify the Chunk that its content is going to be changed directlyvoidrecycle()Resets the message bytes to an uninitialized state.voidreset()protected voidvoidset(BufferChunk bufferChunk, Charset encoding) SetBufferChunkcontent to CharChunk using givenCharset.voidvoidWhen the buffer is empty, read the data from the input channel.voidWhen 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.intintsubstract(char[] src, int off, int len) inttoString()toString(int start, int end) voidtrimLeft()
-
Field Details
-
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.
-
-
Constructor Details
-
CharChunk
public CharChunk()Creates a new, uninitialized CharChunk object. -
CharChunk
public CharChunk(int size)
-
-
Method Details
-
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
When the buffer is empty, read the data from the input channel. -
setCharOutputChannel
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. -
getEnd
public int getEnd() -
setEnd
public void setEnd(int i) -
append
- Throws:
IOException
-
append
- Throws:
IOException
-
append
Add data to the buffer- Throws:
IOException
-
append
Add data to the buffer- Throws:
IOException
-
append
Append a string to the buffer- Throws:
IOException
-
append
Append a string to the buffer- Throws:
IOException
-
delete
public void delete(int start, int end) -
substract
- Throws:
IOException
-
substract
- Throws:
IOException
-
substract
- Throws:
IOException
-
flushBuffer
- Throws:
IOException
-
notifyDirectUpdate
protected void notifyDirectUpdate()Notify the Chunk that its content is going to be changed directly -
resetStringCache
protected void resetStringCache() -
toString
-
toString
-
toStringInternal
-
getInt
public int getInt() -
set
- Throws:
CharConversionException
-
set
SetBufferChunkcontent to CharChunk using givenCharset.- Throws:
CharConversionException
-
hashCode
public int hashCode() -
equals
-
equals
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
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
-
equals
public boolean equals(char[] b2, int off2, int len2) -
equals
public boolean equals(byte[] b2, int off2, int len2) -
startsWith
Returns true if the message bytes starts with the specified string.- Parameters:
s- the string
-
startsWithIgnoreCase
Returns true if the message bytes starts with the specified string.- Parameters:
s- the string
-
endsWith
-
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
-
indexOf
-
trimLeft
public void trimLeft()
-