org.apache.tomcat.util.buf

Class MessageBytes

Implemented Interfaces:
Cloneable, Serializable

public final class MessageBytes
extends java.lang.Object
implements Cloneable, Serializable

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:
dac@eng.sun.com
James Todd [gonzo@eng.sun.com]
Costin Manolache

Nested Class Summary

static class
MessageBytes.MessageBytesFactory

Field Summary

static int
T_BYTES
getType() is T_STR if the the object used to create the MessageBytes was a byte[]
static int
T_CHARS
getType() is T_STR if the the object used to create the MessageBytes was a char[]
static int
T_NULL
static int
T_STR
getType() is T_STR if the the object used to create the MessageBytes was a String

Constructor Summary

MessageBytes()
Creates a new, uninitialized MessageBytes object.

Method Summary

void
duplicate(MessageBytes src)
Copy the src into this MessageBytes, allocating more space if needed
boolean
equals(String s)
Compares the message bytes to the specified String object.
boolean
equals(MessageBytes mb)
boolean
equalsIgnoreCase(String s)
Compares the message bytes to the specified String object.
ByteChunk
getByteChunk()
Returns the byte chunk, representing the byte[] and offset/length.
CharChunk
getCharChunk()
Returns the char chunk, representing the char[] and offset/length.
MessageBytes
getClone()
int
getInt()
Convert the buffer to an int, cache the value
int
getLength()
Returns the length of the original buffer.
long
getLong()
Convert the buffer to an long, cache the value
String
getString()
Returns the string value.
long
getTime()
Deprecated. The buffer are general purpose, caching for headers should be done in headers
int
getType()
Return the type of the original content.
int
hashCode()
int
indexOf(String s)
int
indexOf(String s, int starting)
int
indexOf(char c)
int
indexOf(char c, int starting)
Returns true if the message bytes starts with the specified string.
int
indexOfIgnoreCase(String s, int starting)
boolean
isNull()
static MessageBytes
newInstance()
Construct a new MessageBytes instance
void
recycle()
Resets the message bytes to an uninitialized (NULL) state.
void
resetStringValue()
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 sensitivity
void
setChars(char[] c, int off, int len)
Sets the content to be a char[]
void
setEncoding(String enc)
Set the encoding.
static void
setFactory(MessageBytes.MessageBytesFactory mbf)
void
setInt(int i)
Set the buffer to the representation of an int
void
setString(String s)
Set the content to be a string
void
setTime(long t)
void
setTime(long t, DateFormat df)
Deprecated. The buffer are general purpose, caching for headers should be done in headers.
boolean
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.
String
toString()
Compute the string value

Field Details

T_BYTES

public static final int T_BYTES
getType() is T_STR if the the object used to create the MessageBytes was a byte[]

Field Value:
2


T_CHARS

public static final int T_CHARS
getType() is T_STR if the the object used to create the MessageBytes was a char[]

Field Value:
3


T_NULL

public static final int T_NULL

Field Value:
0


T_STR

public static final int T_STR
getType() is T_STR if the the object used to create the MessageBytes was a String

Field Value:
1

Constructor Details

MessageBytes

public MessageBytes()
Creates a new, uninitialized MessageBytes object.

Method Details

duplicate

public void duplicate(MessageBytes src)
            throws IOException
Copy the src into this MessageBytes, allocating more space if needed


equals

public boolean equals(String s)
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(MessageBytes mb)


equalsIgnoreCase

public boolean equalsIgnoreCase(String s)
Compares the message bytes to the specified String object.

Parameters:
s - the String to compare

Returns:
true if the comparison succeeded, false otherwise


getByteChunk

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


getCharChunk

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


getClone

public MessageBytes getClone()


getInt

public int getInt()
Convert the buffer to an int, cache the value


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.


getLong

public long getLong()
Convert the buffer to an long, cache the value


getString

public String getString()
Returns the string value. Valid only if T_STR or after a conversion was made.


getTime

public long getTime()

Deprecated. The buffer are general purpose, caching for headers should be done in headers


getType

public int getType()
Return the type of the original content. Can be T_STR, T_BYTES, T_CHARS or T_NULL


hashCode

public int hashCode()


indexOf

public int indexOf(String s)


indexOf

public int indexOf(String s,
                   int starting)


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.

Parameters:


indexOfIgnoreCase

public int indexOfIgnoreCase(String s,
                             int starting)


isNull

public boolean isNull()


newInstance

public static MessageBytes newInstance()
Construct a new MessageBytes instance


recycle

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


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 ?


setBytes

public void setBytes(byte[] b,
                     int off,
                     int len)
Sets the content to the specified subarray of bytes.

Parameters:
b - the ascii bytes
off - the start offset of the bytes
len - the length of the bytes


setCaseSenitive

public void setCaseSenitive(boolean b)
Configure the case sensitivity


setChars

public void setChars(char[] c,
                     int off,
                     int len)
Sets the content to be a char[]


setEncoding

public void setEncoding(String 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.


setFactory

public static void setFactory(MessageBytes.MessageBytesFactory mbf)


setInt

public void setInt(int i)
Set the buffer to the representation of an int


setString

public void setString(String s)
Set the content to be a string


setTime

public void setTime(long t)


setTime

public void setTime(long t,
                    DateFormat df)

Deprecated. The buffer are general purpose, caching for headers should be done in headers. The second parameter allows us to pass a date format instance to avoid synchronization problems.


startsWith

public boolean startsWith(String s)
Returns true if the message bytes starts with the specified string.

Parameters:
s - the string


startsWithIgnoreCase

public boolean startsWithIgnoreCase(String s,
                                    int pos)
Returns true if the message bytes starts with the specified string.

Parameters:
s - the string


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.


toString

public String toString()
Compute the string value


Copyright B) 2000-2003 Apache Software Foundation. All Rights Reserved.