java.lang.Object
org.glassfish.grizzly.http.util.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:
- [email protected], James Todd [[email protected]], Costin Manolache
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
getType() is T_STR if the the object used to create the MessageBytes was a byte[]static final int
getType() is T_STR 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 -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.Use static newInstance() in order to allow future hooks. -
Method Summary
Modifier and TypeMethodDescriptionvoid
duplicate
(MessageBytes src) Copy the src into this MessageBytes, allocating more space if neededboolean
boolean
Compares the message bytes to the specified String object.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.getClone()
int
getInt()
Convert the buffer to an int, cache the valueint
Returns the length of the original buffer.long
getLong()
Convert the buffer to an long, cache the valueReturns the string value.int
getType()
Return the type of the original content.int
hashCode()
int
indexOf
(char c) int
indexOf
(char c, int starting) Returns true if the message bytes starts with the specified string.int
int
int
indexOfIgnoreCase
(String s, int starting) boolean
isNull()
static MessageBytes
Construct a new MessageBytes instancevoid
recycle()
Resets the message bytes to an uninitialized (NULL) state.void
Remove the cached string value.void
setBytes
(byte[] b, int off, int len) Sets the content to the specified subarray of bytes.void
setCaseSenitive
(boolean b) Configure the case sensitivityvoid
setChars
(char[] c, int off, int len) Sets the content to be a char[]void
setCharset
(Charset enc) Set the encoding.static void
void
setInt
(int i) Set the buffer to the representation of an intvoid
setLong
(long l) Set the buffer to the representation of an longvoid
Set the content to be a stringboolean
startsWith
(String s) Returns true if the message bytes starts with the specified string.boolean
startsWithIgnoreCase
(String s, int pos) Returns true if the message bytes starts with the specified string.void
toBytes()
Unimplemented yet.void
toChars()
Convert to char[] and fill the CharChunk.toString()
Compute 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_STR if the the object used to create the MessageBytes was a byte[]- See Also:
-
T_CHARS
public static final int T_CHARSgetType() is T_STR if the the object used to create the MessageBytes was a char[]- See Also:
-
-
Constructor Details
-
MessageBytes
Deprecated.Use static newInstance() in order to allow future hooks.Creates a new, uninitialized MessageBytes object.
-
-
Method Details
-
newInstance
Construct a new MessageBytes instance -
setCaseSenitive
public void setCaseSenitive(boolean b) Configure the case sensitivity -
getClone
-
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
-
setCharset
Set the encoding. If the object was constructed from bytes[]. any previous conversion is reset. If no encoding is set, we'll use 8859-1. -
setChars
public void setChars(char[] c, int off, int len) Sets the content to be a char[]- Parameters:
c
- the bytesoff
- the start offset of the byteslen
- the length of the bytes
-
resetStringValue
public void resetStringValue()Remove the cached string value. Use it after a conversion on the byte[] or after the encoding is changed XXX Is this needed ? -
setString
Set the content to be a string -
toString
Compute the string value -
getType
public int getType()Return the type of the original content. Can be T_STR, T_BYTES, T_CHARS or T_NULL -
getByteChunk
Returns the byte chunk, representing the byte[] and offset/length. Valid only if T_BYTES or after a conversion was made. -
getCharChunk
Returns the char chunk, representing the char[] and offset/length. Valid only if T_CHARS or after a conversion was made. -
getString
Returns the string value. Valid only if T_STR or after a conversion was made. -
toBytes
public void toBytes()Unimplemented yet. Do a char->byte conversion. -
toChars
public void toChars()Convert to char[] and fill the CharChunk. XXX Not optimized - it converts to String first. -
getLength
public int getLength()Returns the length of the original buffer. Note that the length in bytes may be different from the length in chars. -
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
-
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 stringpos
- The start position
-
hashCode
public int hashCode() -
indexOf
public int indexOf(char c) -
indexOf
-
indexOf
-
indexOfIgnoreCase
-
indexOf
public int indexOf(char c, int starting) Returns true if the message bytes starts with the specified string.- Parameters:
c
- the characterstarting
- The start position
-
duplicate
Copy the src into this MessageBytes, allocating more space if needed- Throws:
IOException
-
setInt
public void setInt(int i) Set the buffer to the representation of an int -
setLong
public void setLong(long l) Set the buffer to the representation of an long -
getInt
public int getInt()Convert the buffer to an int, cache the value -
getLong
public long getLong()Convert the buffer to an long, cache the value -
setFactory
-