Package org.apache.tomcat.util.buf
Class MessageBytes
- java.lang.Object
- 
- org.apache.tomcat.util.buf.MessageBytes
 
- 
- All Implemented Interfaces:
- java.io.Serializable,- java.lang.Cloneable
 
 public final class MessageBytes extends java.lang.Object implements java.lang.Cloneable, java.io.SerializableThis class is used to represent a subarray of bytes in an HTTP message. It represents all request/response elements. The byte/char conversions are delayed and cached. Everything is recyclable. The object can represent a byte[], a char[], or a (sub) String. All operations can be made in case sensitive mode or not.- Author:
- dac@eng.sun.com, James Todd [gonzo@eng.sun.com], Costin Manolache
- See Also:
- Serialized Form
 
- 
- 
Field SummaryFields Modifier and Type Field Description static char[]EMPTY_CHAR_ARRAYstatic intT_BYTESgetType() is T_BYTES if the the object used to create the MessageBytes was a byte[]static intT_CHARSgetType() is T_CHARS if the the object used to create the MessageBytes was a char[]static intT_NULLstatic intT_STRgetType() is T_STR if the the object used to create the MessageBytes was a String
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()voidduplicate(MessageBytes src)Copy the src into this MessageBytes, allocating more space if needed.booleanequals(java.lang.Object obj)booleanequals(java.lang.String s)Compares the message bytes to the specified String object.booleanequals(MessageBytes mb)booleanequalsIgnoreCase(java.lang.String s)Compares the message bytes to the specified String object.ByteChunkgetByteChunk()Returns the byte chunk, representing the byte[] and offset/length.CharChunkgetCharChunk()Returns the char chunk, representing the char[] and offset/length.java.nio.charset.CharsetgetCharset()intgetLength()Returns the length of the original buffer.longgetLong()Convert the buffer to an long, cache the value.java.lang.StringgetString()Returns the string value.intgetType()Return the type of the original content.inthashCode()intindexOf(java.lang.String s)intindexOf(java.lang.String s, int starting)intindexOfIgnoreCase(java.lang.String s, int starting)booleanisNull()static MessageBytesnewInstance()Construct a new MessageBytes instance.voidrecycle()Resets the message bytes to an uninitialized (NULL) state.voidsetBytes(byte[] b, int off, int len)Sets the content to the specified subarray of bytes.voidsetChars(char[] c, int off, int len)Sets the content to be a char[]voidsetCharset(java.nio.charset.Charset charset)Set the Charset used for string<->byte conversions.voidsetLong(long l)Set the buffer to the representation of a long.voidsetString(java.lang.String s)Set the content to be a stringbooleanstartsWithIgnoreCase(java.lang.String s, int pos)voidtoBytes()Convert to bytes and fill the ByteChunk with the converted value.voidtoChars()Convert to char[] and fill the CharChunk.java.lang.StringtoString()Compute the string value.
 
- 
- 
- 
Field Detail- 
T_NULLpublic static final int T_NULL - See Also:
- Constant Field Values
 
 - 
T_STRpublic static final int T_STR getType() is T_STR if the the object used to create the MessageBytes was a String- See Also:
- Constant Field Values
 
 - 
T_BYTESpublic static final int T_BYTES getType() is T_BYTES if the the object used to create the MessageBytes was a byte[]- See Also:
- Constant Field Values
 
 - 
T_CHARSpublic static final int T_CHARS getType() is T_CHARS if the the object used to create the MessageBytes was a char[]- See Also:
- Constant Field Values
 
 - 
EMPTY_CHAR_ARRAYpublic static final char[] EMPTY_CHAR_ARRAY 
 
- 
 - 
Method Detail- 
newInstancepublic static MessageBytes newInstance() Construct a new MessageBytes instance.- Returns:
- the instance
 
 - 
clonepublic java.lang.Object clone() throws java.lang.CloneNotSupportedException- Overrides:
- clonein class- java.lang.Object
- Throws:
- java.lang.CloneNotSupportedException
 
 - 
isNullpublic boolean isNull() 
 - 
recyclepublic void recycle() Resets the message bytes to an uninitialized (NULL) state.
 - 
setBytespublic void setBytes(byte[] b, int off, int len)Sets the content to the specified subarray of bytes.- Parameters:
- b- the bytes
- off- the start offset of the bytes
- len- the length of the bytes
 
 - 
setCharspublic void setChars(char[] c, int off, int len)Sets the content to be a char[]- Parameters:
- c- the chars
- off- the start offset of the chars
- len- the length of the chars
 
 - 
setStringpublic void setString(java.lang.String s) Set the content to be a string- Parameters:
- s- The string
 
 - 
toStringpublic java.lang.String toString() Compute the string value.- Overrides:
- toStringin class- java.lang.Object
- Returns:
- the string
 
 - 
getTypepublic int getType() Return the type of the original content. Can be T_STR, T_BYTES, T_CHARS or T_NULL- Returns:
- the type
 
 - 
getByteChunkpublic ByteChunk getByteChunk() Returns the byte chunk, representing the byte[] and offset/length. Valid only if T_BYTES or after a conversion was made.- Returns:
- the byte chunk
 
 - 
getCharChunkpublic CharChunk getCharChunk() Returns the char chunk, representing the char[] and offset/length. Valid only if T_CHARS or after a conversion was made.- Returns:
- the char chunk
 
 - 
getStringpublic java.lang.String getString() Returns the string value. Valid only if T_STR or after a conversion was made.- Returns:
- the string
 
 - 
getCharsetpublic java.nio.charset.Charset getCharset() - Returns:
- the Charset used for string<->byte conversions.
 
 - 
setCharsetpublic void setCharset(java.nio.charset.Charset charset) Set the Charset used for string<->byte conversions.- Parameters:
- charset- The charset
 
 - 
toBytespublic void toBytes() Convert to bytes and fill the ByteChunk with the converted value.
 - 
toCharspublic void toChars() Convert to char[] and fill the CharChunk. Note: The conversion from bytes is not optimised - it converts to String first. However, Tomcat doesn't call this method to convert from bytes so there is no benefit from optimising that path.
 - 
getLengthpublic int getLength() Returns the length of the original buffer. Note that the length in bytes may be different from the length in chars.- Returns:
- the length
 
 - 
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(java.lang.Object obj) - Overrides:
- equalsin class- java.lang.Object
 
 - 
equalspublic boolean equals(MessageBytes mb) 
 - 
startsWithIgnoreCasepublic boolean startsWithIgnoreCase(java.lang.String s, int pos)- Parameters:
- s- the string
- pos- The start position
- Returns:
- trueif the message bytes starts with the specified string.
 
 - 
hashCodepublic int hashCode() - Overrides:
- hashCodein class- java.lang.Object
 
 - 
indexOfpublic int indexOf(java.lang.String s, int starting)
 - 
indexOfpublic int indexOf(java.lang.String s) 
 - 
indexOfIgnoreCasepublic int indexOfIgnoreCase(java.lang.String s, int starting)
 - 
duplicatepublic void duplicate(MessageBytes src) throws java.io.IOException Copy the src into this MessageBytes, allocating more space if needed.- Parameters:
- src- The source
- Throws:
- java.io.IOException- Writing overflow data to the output channel failed
 
 - 
setLongpublic void setLong(long l) Set the buffer to the representation of a long.- Parameters:
- l- The long
 
 - 
getLongpublic long getLong() Convert the buffer to an long, cache the value.- Returns:
- the long value
 
 
- 
 
-