Class MessageBytes
java.lang.Object
org.apache.tomcat.util.buf.MessageBytes
- All Implemented Interfaces:
Serializable
,Cloneable
This 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:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final char[]
static final int
getType() is T_BYTES if the the object used to create the MessageBytes was a byte[].static final int
getType() is T_CHARS if the the object used to create the MessageBytes was a char[].static final int
static final int
getType() is T_STR if the the object used to create the MessageBytes was a String. -
Method Summary
Modifier and TypeMethodDescriptionclone()
void
duplicate
(MessageBytes src) Copy the src into this MessageBytes, allocating more space if needed.boolean
boolean
Compares the message bytes to the specified String object.boolean
equals
(MessageBytes mb) boolean
Compares the message bytes to the specified String object.Returns the byte chunk, representing the byte[] and offset/length.Returns the char chunk, representing the char[] and offset/length.int
Returns the length of the original buffer.long
getLong()
Convert the buffer to a long, cache the value.Returns the string value.int
getType()
Return the type of the original content.int
hashCode()
int
int
int
indexOfIgnoreCase
(String s, int starting) boolean
isNull()
static MessageBytes
Construct a new MessageBytes instance.void
recycle()
Resets the message bytes to an uninitialized (NULL) state.void
setBytes
(byte[] b, int off, int len) Sets the content to the specified subarray of bytes.void
setChars
(char[] c, int off, int len) Sets the content to be a char[]void
setCharset
(Charset charset) Set the Charset used for string<->byte conversions.void
setLong
(long l) Set the buffer to the representation of a long.void
Set the content to be a stringboolean
startsWithIgnoreCase
(String s, int pos) void
toBytes()
Convert to bytes and fill the ByteChunk with the converted value.void
toChars()
Convert to char[] and fill the CharChunk.toString()
Compute the string value.Convert to String (if not already of the String type) and then return the String value.
-
Field Details
-
T_NULL
public static final int T_NULL- See Also:
-
T_STR
public static final int T_STRgetType() is T_STR if the the object used to create the MessageBytes was a String.- See Also:
-
T_BYTES
public static final int T_BYTESgetType() is T_BYTES if the the object used to create the MessageBytes was a byte[].- See Also:
-
T_CHARS
public static final int T_CHARSgetType() is T_CHARS if the the object used to create the MessageBytes was a char[].- See Also:
-
EMPTY_CHAR_ARRAY
public static final char[] EMPTY_CHAR_ARRAY
-
-
Method Details
-
newInstance
Construct a new MessageBytes instance.- Returns:
- the instance
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-
isNull
public boolean isNull() -
recycle
public void recycle()Resets the message bytes to an uninitialized (NULL) state. -
setBytes
public void setBytes(byte[] b, int off, int len) Sets the content to the specified subarray of bytes.- Parameters:
b
- the bytesoff
- the start offset of the byteslen
- the length of the bytes
-
setChars
public void setChars(char[] c, int off, int len) Sets the content to be a char[]- Parameters:
c
- the charsoff
- the start offset of the charslen
- the length of the chars
-
setString
-
toString
-
toStringType
Convert to String (if not already of the String type) and then return the String value.- Returns:
- The current value as a String
-
getType
public int getType()Return the type of the original content. Can be T_STR, T_BYTES, T_CHARS or T_NULL- Returns:
- the type
-
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
-
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
-
getString
Returns the string value. Valid only if T_STR or after a conversion was made.- Returns:
- the string
-
getCharset
- Returns:
- the Charset used for string<->byte conversions.
-
setCharset
Set the Charset used for string<->byte conversions.- Parameters:
charset
- The charset
-
toBytes
public void toBytes()Convert to bytes and fill the ByteChunk with the converted value. -
toChars
public 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.
-
getLength
public int getLength()Returns the length of the original buffer.Note: The length in bytes may be different from the length in chars.
- Returns:
- the length
-
equals
Compares the message bytes to the specified String object.- Parameters:
s
- the String to compare- Returns:
true
if the comparison succeeded,false
otherwise
-
equalsIgnoreCase
Compares the message bytes to the specified String object.- Parameters:
s
- the String to compare- Returns:
true
if the comparison succeeded,false
otherwise
-
equals
-
equals
-
startsWithIgnoreCase
- Parameters:
s
- the stringpos
- The start position- Returns:
true
if the message bytes starts with the specified string.
-
hashCode
-
indexOf
-
indexOf
-
indexOfIgnoreCase
-
duplicate
Copy the src into this MessageBytes, allocating more space if needed.- Parameters:
src
- The source- Throws:
IOException
- Writing overflow data to the output channel failed
-
setLong
public void setLong(long l) Set the buffer to the representation of a long.- Parameters:
l
- The long
-
getLong
public long getLong()Convert the buffer to a long, cache the value. Used for headers conversion.- Returns:
- the long value
-