Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.http.util

public final Class MessageBytes

extends Object
implements Cloneable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Cloneable
Imports
java.io.IOException, .Serializable, java.nio.charset.Charset

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.
Authors
[email protected], James Todd [[email protected]], Costin Manolache

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private final ByteChunk
private boolean
private final CharChunk
private static MessageBytes.MessageBytesFactory
private boolean
private int
private boolean
private boolean
private boolean
private int
private long
private String
public static final int
T_BYTES

getType() is T_STR if the the object used to create the MessageBytes was a byte[]

public static final int
T_CHARS

getType() is T_STR if the the object used to create the MessageBytes was a char[]

public static final int
public static final int
T_STR

getType() is T_STR if the the object used to create the MessageBytes was a String

private int

Constructor Summary

AccessConstructor and Description
public
MessageBytes()
Deprecated Use static newInstance() in order to allow future hooks.

Creates a new, uninitialized MessageBytes object.

Method Summary

Modifier and TypeMethod and Description
public void
duplicate(MessageBytes src)

Copy the src into this MessageBytes, allocating more space if needed

public boolean

Returns:

true if the comparison succeeded, false otherwise
equals
(String
the String to compare
s
)

Compares the message bytes to the specified String object.

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public boolean

Returns:

true if the comparison succeeded, false otherwise
equalsIgnoreCase
(String
the String to compare
s
)

Compares the message bytes to the specified String object.

public ByteChunk
getByteChunk()

Returns the byte chunk, representing the byte[] and offset/length.

public CharChunk
getCharChunk()

Returns the char chunk, representing the char[] and offset/length.

public MessageBytes
public int
getInt()

Convert the buffer to an int, cache the value

public int
getLength()

Returns the length of the original buffer.

public long
getLong()

Convert the buffer to an long, cache the value

public String
getString()

Returns the string value.

public int
getType()

Return the type of the original content.

private int
hash()

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

private int
public int
indexOf(char c)

public int
indexOf(String s, int starting)

public int
public int
indexOf(char
the character
c
,
int
The start position
starting
)

Returns true if the message bytes starts with the specified string.

public int
indexOfIgnoreCase(String s, int starting)

public boolean
public static MessageBytes
newInstance()

Construct a new MessageBytes instance

public void
recycle()

Resets the message bytes to an uninitialized (NULL) state.

public void
resetStringValue()

Remove the cached string value.

public void
setBytes(byte[]
the bytes
b
,
int
the start offset of the bytes
off
,
int
the length of the bytes
len
)

Sets the content to the specified subarray of bytes.

public void
setCaseSenitive(boolean b)

Configure the case sensitivity

public void
setChars(char[]
the bytes
c
,
int
the start offset of the bytes
off
,
int
the length of the bytes
len
)

Sets the content to be a char[]

public void
setCharset(Charset enc)

Set the encoding.

public static void
public void
setInt(int i)

Set the buffer to the representation of an int

public void
setLong(long l)

Set the buffer to the representation of an long

public void
setString(String s)

Set the content to be a string

public boolean
startsWith(String
the string
s
)

Returns true if the message bytes starts with the specified string.

public boolean
startsWithIgnoreCase(String
the string
s
,
int
The start position
pos
)

Returns true if the message bytes starts with the specified string.

public void
toBytes()

Unimplemented yet.

public void
toChars()

Convert to char[] and fill the CharChunk.

public String
toString()

Overrides java.lang.Object.toString.

Compute the string value

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

byteCback to summary
private final ByteChunk byteC
caseSensitiveback to summary
private boolean caseSensitive
charCback to summary
private final CharChunk charC
factoryback to summary
private static MessageBytes.MessageBytesFactory factory
hasHashCodeback to summary
private boolean hasHashCode
hashCodeback to summary
private int hashCode
hasIntValueback to summary
private boolean hasIntValue
hasLongValueback to summary
private boolean hasLongValue
hasStrValueback to summary
private boolean hasStrValue
intValueback to summary
private int intValue
longValueback to summary
private long longValue
strValueback to summary
private String strValue
T_BYTESback to summary
public static final int T_BYTES

getType() is T_STR if the the object used to create the MessageBytes was a byte[]

T_CHARSback to summary
public static final int T_CHARS

getType() is T_STR if the the object used to create the MessageBytes was a char[]

T_NULLback to summary
public static final int T_NULL
T_STRback to summary
public static final int T_STR

getType() is T_STR if the the object used to create the MessageBytes was a String

typeback to summary
private int type

Constructor Detail

MessageBytesback to summary
public MessageBytes()

Deprecated

Use static newInstance() in order to allow future hooks.

Creates a new, uninitialized MessageBytes object.

Annotations
@Deprecated

Method Detail

duplicateback to summary
public void duplicate(MessageBytes src) throws IOException

Copy the src into this MessageBytes, allocating more space if needed

equalsback to summary
public boolean equals(String s)

Compares the message bytes to the specified String object.

Parameters
s:String

the String to compare

Returns:boolean

true if the comparison succeeded, false otherwise

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
equalsIgnoreCaseback to summary
public boolean equalsIgnoreCase(String s)

Compares the message bytes to the specified String object.

Parameters
s:String

the String to compare

Returns:boolean

true if the comparison succeeded, false otherwise

getByteChunkback to summary
public ByteChunk getByteChunk()

Returns the byte chunk, representing the byte[] and offset/length. Valid only if T_BYTES or after a conversion was made.

getCharChunkback to summary
public CharChunk getCharChunk()

Returns the char chunk, representing the char[] and offset/length. Valid only if T_CHARS or after a conversion was made.

getCloneback to summary
public MessageBytes getClone()
getIntback to summary
public int getInt()

Convert the buffer to an int, cache the value

getLengthback to summary
public int getLength()

Returns the length of the original buffer. Note that the length in bytes may be different from the length in chars.

getLongback to summary
public long getLong()

Convert the buffer to an long, cache the value

getStringback to summary
public String getString()

Returns the string value. Valid only if T_STR or after a conversion was made.

getTypeback to summary
public int getType()

Return the type of the original content. Can be T_STR, T_BYTES, T_CHARS or T_NULL

hashback to summary
private int hash()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
hashIgnoreCaseback to summary
private int hashIgnoreCase()
indexOfback to summary
public int indexOf(char c)
indexOfback to summary
public int indexOf(String s, int starting)
indexOfback to summary
public int indexOf(String s)
indexOfback to summary
public int indexOf(char c, int starting)

Returns true if the message bytes starts with the specified string.

Parameters
c:char

the character

starting:int

The start position

indexOfIgnoreCaseback to summary
public int indexOfIgnoreCase(String s, int starting)
isNullback to summary
public boolean isNull()
newInstanceback to summary
public static MessageBytes newInstance()

Construct a new MessageBytes instance

recycleback to summary
public void recycle()

Resets the message bytes to an uninitialized (NULL) state.

resetStringValueback to summary
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 ?

setBytesback to summary
public void setBytes(byte[] b, int off, int len)

Sets the content to the specified subarray of bytes.

Parameters
b:byte[]

the bytes

off:int

the start offset of the bytes

len:int

the length of the bytes

setCaseSenitiveback to summary
public void setCaseSenitive(boolean b)

Configure the case sensitivity

setCharsback to summary
public void setChars(char[] c, int off, int len)

Sets the content to be a char[]

Parameters
c:char[]

the bytes

off:int

the start offset of the bytes

len:int

the length of the bytes

setCharsetback to summary
public void setCharset(Charset enc)

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.

setFactoryback to summary
public static void setFactory(MessageBytes.MessageBytesFactory mbf)
setIntback to summary
public void setInt(int i)

Set the buffer to the representation of an int

setLongback to summary
public void setLong(long l)

Set the buffer to the representation of an long

setStringback to summary
public void setString(String s)

Set the content to be a string

startsWithback to summary
public boolean startsWith(String s)

Returns true if the message bytes starts with the specified string.

Parameters
s:String

the string

startsWithIgnoreCaseback to summary
public boolean startsWithIgnoreCase(String s, int pos)

Returns true if the message bytes starts with the specified string.

Parameters
s:String

the string

pos:int

The start position

toBytesback to summary
public void toBytes()

Unimplemented yet. Do a char->byte conversion.

toCharsback to summary
public void toChars()

Convert to char[] and fill the CharChunk. XXX Not optimized - it converts to String first.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Compute the string value

Annotations
@Override
org.glassfish.grizzly.http.util back to summary

public Class MessageBytes.MessageBytesFactory

extends Object
Class Inheritance
  • java.lang.Object
  • org.glassfish.grizzly.http.util.MessageBytes.MessageBytesFactory

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public MessageBytes
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

MessageBytesFactoryback to summary
protected MessageBytesFactory()

Method Detail

newInstanceback to summary
public MessageBytes newInstance()
Annotations
@SuppressWarnings:deprecation