Methods Summary |
---|
public void | duplicate(org.apache.tomcat.util.buf.MessageBytes src)Copy the src into this MessageBytes, allocating more space if
needed
switch( src.getType() ) {
case MessageBytes.T_BYTES:
type=T_BYTES;
ByteChunk bc=src.getByteChunk();
byteC.allocate( 2 * bc.getLength(), -1 );
byteC.append( bc );
break;
case MessageBytes.T_CHARS:
type=T_CHARS;
CharChunk cc=src.getCharChunk();
charC.allocate( 2 * cc.getLength(), -1 );
charC.append( cc );
break;
case MessageBytes.T_STR:
type=T_STR;
String sc=src.getString();
this.setString( sc );
break;
}
|
public boolean | equals(java.lang.String s)Compares the message bytes to the specified String object.
if( ! caseSensitive )
return equalsIgnoreCase( s );
switch (type) {
case T_STR:
if( strValue==null && s!=null) return false;
return strValue.equals( s );
case T_CHARS:
return charC.equals( s );
case T_BYTES:
return byteC.equals( s );
default:
return false;
}
|
public boolean | equals(org.apache.tomcat.util.buf.MessageBytes mb)
switch (type) {
case T_STR:
return mb.equals( strValue );
}
if( mb.type != T_CHARS &&
mb.type!= T_BYTES ) {
// it's a string or int/date string value
return equals( mb.toString() );
}
// mb is either CHARS or BYTES.
// this is either CHARS or BYTES
// Deal with the 4 cases ( in fact 3, one is simetric)
if( mb.type == T_CHARS && type==T_CHARS ) {
return charC.equals( mb.charC );
}
if( mb.type==T_BYTES && type== T_BYTES ) {
return byteC.equals( mb.byteC );
}
if( mb.type== T_CHARS && type== T_BYTES ) {
return byteC.equals( mb.charC );
}
if( mb.type== T_BYTES && type== T_CHARS ) {
return mb.byteC.equals( charC );
}
// can't happen
return true;
|
public boolean | equalsIgnoreCase(java.lang.String s)Compares the message bytes to the specified String object.
switch (type) {
case T_STR:
if( strValue==null && s!=null) return false;
return strValue.equalsIgnoreCase( s );
case T_CHARS:
return charC.equalsIgnoreCase( s );
case T_BYTES:
return byteC.equalsIgnoreCase( s );
default:
return false;
}
|
public ByteChunk | getByteChunk()Returns the byte chunk, representing the byte[] and offset/length.
Valid only if T_BYTES or after a conversion was made.
return byteC;
|
public CharChunk | getCharChunk()Returns the char chunk, representing the char[] and offset/length.
Valid only if T_CHARS or after a conversion was made.
return charC;
|
public org.apache.tomcat.util.buf.MessageBytes | getClone()
try {
return (MessageBytes)this.clone();
} catch( Exception ex) {
return null;
}
|
public int | getInt()Convert the buffer to an int, cache the value
if( hasIntValue )
return intValue;
switch (type) {
case T_BYTES:
intValue=byteC.getInt();
break;
default:
intValue=Integer.parseInt(toString());
}
hasIntValue=true;
return intValue;
|
public int | getLength()Returns the length of the original buffer.
Note that the length in bytes may be different from the length
in chars.
if(type==T_BYTES)
return byteC.getLength();
if(type==T_CHARS) {
return charC.getLength();
}
if(type==T_STR)
return strValue.length();
toString();
if( strValue==null ) return 0;
return strValue.length();
|
public long | getLong()Convert the buffer to an long, cache the value
if( hasLongValue )
return longValue;
switch (type) {
case T_BYTES:
longValue=byteC.getLong();
break;
default:
longValue=Long.parseLong(toString());
}
hasLongValue=true;
return longValue;
|
public java.lang.String | getString()Returns the string value.
Valid only if T_STR or after a conversion was made.
return strValue;
|
public long | getTime()
if( hasDateValue ) {
if( dateValue==null) return -1;
return dateValue.getTime();
}
long l=DateTool.parseDate( this );
if( dateValue==null)
dateValue=new Date(l);
else
dateValue.setTime(l);
hasDateValue=true;
return l;
|
public int | getType()Return the type of the original content. Can be
T_STR, T_BYTES, T_CHARS or T_NULL
return type;
|
private int | hash()
int code=0;
switch (type) {
case T_STR:
// We need to use the same hash function
for (int i = 0; i < strValue.length(); i++) {
code = code * 37 + strValue.charAt( i );
}
return code;
case T_CHARS:
return charC.hash();
case T_BYTES:
return byteC.hash();
default:
return 0;
}
|
public int | hashCode()
if( hasHashCode ) return hashCode;
int code = 0;
if( caseSensitive )
code=hash();
else
code=hashIgnoreCase();
hashCode=code;
hasHashCode=true;
return code;
|
private int | hashIgnoreCase()
int code=0;
switch (type) {
case T_STR:
for (int i = 0; i < strValue.length(); i++) {
code = code * 37 + Ascii.toLower(strValue.charAt( i ));
}
return code;
case T_CHARS:
return charC.hashIgnoreCase();
case T_BYTES:
return byteC.hashIgnoreCase();
default:
return 0;
}
|
public int | indexOf(char c)
return indexOf( c, 0);
|
public int | indexOf(java.lang.String s, int starting)
toString();
return strValue.indexOf( s, starting );
|
public int | indexOf(java.lang.String s)
return indexOf( s, 0 );
|
public int | indexOf(char c, int starting)Returns true if the message bytes starts with the specified string.
switch (type) {
case T_STR:
return strValue.indexOf( c, starting );
case T_CHARS:
return charC.indexOf( c, starting);
case T_BYTES:
return byteC.indexOf( c, starting );
default:
return -1;
}
|
public int | indexOfIgnoreCase(java.lang.String s, int starting)
toString();
String upper=strValue.toUpperCase();
String sU=s.toUpperCase();
return upper.indexOf( sU, starting );
|
public boolean | isNull()
// should we check also hasStrValue ???
return byteC.isNull() && charC.isNull() && ! hasStrValue;
// bytes==null && strValue==null;
|
public static org.apache.tomcat.util.buf.MessageBytes | newInstance()Construct a new MessageBytes instance
return factory.newInstance();
|
public void | recycle()Resets the message bytes to an uninitialized (NULL) state.
type=T_NULL;
byteC.recycle();
charC.recycle();
strValue=null;
caseSensitive=true;
hasStrValue=false;
hasHashCode=false;
hasIntValue=false;
hasLongValue=false;
hasDateValue=false;
|
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 ?
if( type != T_STR ) {
// If this was cread as a byte[] or char[], we remove
// the old string value
hasStrValue=false;
strValue=null;
}
|
public void | setBytes(byte[] b, int off, int len)Sets the content to the specified subarray of bytes.
byteC.setBytes( b, off, len );
type=T_BYTES;
hasStrValue=false;
hasHashCode=false;
hasIntValue=false;
hasLongValue=false;
hasDateValue=false;
|
public void | setCaseSenitive(boolean b)Configure the case sensitivity
caseSensitive=b;
|
public void | setChars(char[] c, int off, int len)Sets the content to be a char[]
charC.setChars( c, off, len );
type=T_CHARS;
hasStrValue=false;
hasHashCode=false;
hasIntValue=false;
hasLongValue=false;
hasDateValue=false;
|
public void | setEncoding(java.lang.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.
if( !byteC.isNull() ) {
// if the encoding changes we need to reset the converion results
charC.recycle();
hasStrValue=false;
}
byteC.setEncoding(enc);
|
public static void | setFactory(org.apache.tomcat.util.buf.MessageBytes$MessageBytesFactory mbf)
factory=mbf;
|
public void | setInt(int i)Set the buffer to the representation of an int
byteC.allocate(16, 32);
int current = i;
byte[] buf = byteC.getBuffer();
int start = 0;
int end = 0;
if (i == 0) {
buf[end++] = (byte) '0";
}
if (i < 0) {
current = -i;
buf[end++] = (byte) '-";
}
while (current > 0) {
int digit = current % 10;
current = current / 10;
buf[end++] = HexUtils.HEX[digit];
}
byteC.setOffset(0);
byteC.setEnd(end);
// Inverting buffer
end--;
if (i < 0) {
start++;
}
while (end > start) {
byte temp = buf[start];
buf[start] = buf[end];
buf[end] = temp;
start++;
end--;
}
intValue=i;
hasStrValue=false;
hasHashCode=false;
hasIntValue=true;
hasLongValue=false;
hasDateValue=false;
type=T_BYTES;
|
public void | setLong(long l)Set the buffer to the representation of an long
byteC.allocate(32, 64);
long current = l;
byte[] buf = byteC.getBuffer();
int start = 0;
int end = 0;
if (l == 0) {
buf[end++] = (byte) '0";
}
if (l < 0) {
current = -l;
buf[end++] = (byte) '-";
}
while (current > 0) {
int digit = (int) (current % 10);
current = current / 10;
buf[end++] = HexUtils.HEX[digit];
}
byteC.setOffset(0);
byteC.setEnd(end);
// Inverting buffer
end--;
if (l < 0) {
start++;
}
while (end > start) {
byte temp = buf[start];
buf[start] = buf[end];
buf[end] = temp;
start++;
end--;
}
longValue=l;
hasStrValue=false;
hasHashCode=false;
hasIntValue=false;
hasLongValue=true;
hasDateValue=false;
type=T_BYTES;
|
public void | setString(java.lang.String s)Set the content to be a string
strValue=s;
hasHashCode=false;
hasIntValue=false;
hasLongValue=false;
hasDateValue=false;
if (s == null) {
hasStrValue=false;
type=T_NULL;
} else {
hasStrValue=true;
type=T_STR;
}
|
public void | setTime(long t, java.text.DateFormat df)
// XXX replace it with a byte[] tool
recycle();
if( dateValue==null)
dateValue=new Date(t);
else
dateValue.setTime(t);
if( df==null )
strValue=DateTool.format1123(dateValue);
else
strValue=DateTool.format1123(dateValue,df);
hasStrValue=true;
hasDateValue=true;
type=T_STR;
|
public void | setTime(long t)
setTime( t, null );
|
public boolean | startsWith(java.lang.String s)Returns true if the message bytes starts with the specified string.
switch (type) {
case T_STR:
return strValue.startsWith( s );
case T_CHARS:
return charC.startsWith( s );
case T_BYTES:
return byteC.startsWith( s );
default:
return false;
}
|
public boolean | startsWithIgnoreCase(java.lang.String s, int pos)Returns true if the message bytes starts with the specified string.
switch (type) {
case T_STR:
if( strValue==null ) return false;
if( strValue.length() < pos + s.length() ) return false;
for( int i=0; i<s.length(); i++ ) {
if( Ascii.toLower( s.charAt( i ) ) !=
Ascii.toLower( strValue.charAt( pos + i ))) {
return false;
}
}
return true;
case T_CHARS:
return charC.startsWithIgnoreCase( s, pos );
case T_BYTES:
return byteC.startsWithIgnoreCase( s, pos );
default:
return false;
}
|
public void | toBytes()Unimplemented yet. Do a char->byte conversion.
if( ! byteC.isNull() ) {
type=T_BYTES;
return;
}
toString();
type=T_BYTES;
byte bb[] = strValue.getBytes();
byteC.setBytes(bb, 0, bb.length);
|
public void | toChars()Convert to char[] and fill the CharChunk.
XXX Not optimized - it converts to String first.
if( ! charC.isNull() ) {
type=T_CHARS;
return;
}
// inefficient
toString();
type=T_CHARS;
char cc[]=strValue.toCharArray();
charC.setChars(cc, 0, cc.length);
|
public java.lang.String | toString()Compute the string value
if( hasStrValue ) return strValue;
switch (type) {
case T_CHARS:
strValue=charC.toString();
hasStrValue=true;
return strValue;
case T_BYTES:
strValue=byteC.toString();
hasStrValue=true;
return strValue;
}
return null;
|