Top Description Fields Constructors Methods
io.undertow.util

public final Class HttpString

extends Object
implements Comparable<HttpString>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Comparable
Static Imports
java.lang.Integer.signum, .System.arraycopy, java.util.Arrays.copyOfRange

An HTTP case-insensitive Latin-1 string.
Author
David M. Lloyd

Field Summary

Modifier and TypeField and Description
private final byte[]
public static final HttpString
EMPTY

Empty HttpString instance.

private final transient int
private static final Field
private final int
orderInt

And integer that is only set for well known header to make comparison fast

private static final long
private transient String

Constructor Summary

AccessConstructor and Description
public
HttpString(final byte[]
the byte array to copy
bytes
)

Construct a new instance.

public
HttpString(final byte[]
the byte array to copy
bytes
,
int
the offset into the array to start copying
offset
,
int
the number of bytes to copy
length
)

Construct a new instance.

public
HttpString(final ByteBuffer
the buffer to read
buffer
)

Construct a new instance by reading the remaining bytes from a buffer.

public
HttpString(final String
the source string
string
)

Construct a new instance from a String.

pack-priv
HttpString(final String string, int orderInt)

private
HttpString(final byte[] bytes, final String string)

Method Summary

Modifier and TypeMethod and Description
public void
appendTo(ByteBuffer
the buffer to append to
buffer
)

Append to a byte buffer.

public byte

Returns:

the byte at an index
byteAt
(int idx)

Get the byte at an index.

private static boolean
bytesAreEqual(final byte[] a, final byte[] b)

private static boolean
bytesAreEquivalent(final byte[] a, final byte[] b)

private static int
calcHashCode(final byte[] bytes)

private void
public int

Returns:

-1, 0, or 1
compareTo
(final HttpString
the other string
other
)

Implements java.lang.Comparable.compareTo.

Compare this string to another in a case-insensitive manner.

public void
copyTo(int
the source offset
srcOffs
,
byte[]
the destination
dst
,
int
the destination offset
offs
,
int
the number of bytes to copy
len
)

Copy len bytes from this string at offset srcOffs to the given array at the given offset.

public void
copyTo(byte[]
the destination
dst
,
int
the destination offset
offs
,
int
the number of bytes
len
)

Copy len bytes from this string to the given array at the given offset.

public void
copyTo(byte[]
the destination
dst
,
int
the destination offset
offs
)

Copy all the bytes from this string to the given array at the given offset.

public boolean

Returns:

true if they are equal, false otherwise
equals
(final Object
the other object
other
)

Overrides java.lang.Object.equals.

Determine if this HttpString is equal to another.

public boolean

Returns:

true if they are equal, false otherwise
equals
(final HttpString
the other object
other
)

Determine if this HttpString is equal to another.

public boolean
equalToString(String headerName)

public int

Returns:

the hash code
hashCode
()

Overrides java.lang.Object.hashCode.

Get the hash code.

pack-priv static int
hashCodeOf(final String headerName)

private static int
higher(byte b)

public int

Returns:

the string length
length
()

Get the string length.

private void
private static byte[]
take(final ByteBuffer buffer)

private static byte[]
toByteArray(final String string)

public String

Returns:

the string
toString
()

Overrides java.lang.Object.toString.

Get the String representation of this HttpString.

public static HttpString

Returns:

the HTTP string, or null if the string is not in a compatible encoding
tryFromString
(String
the string to try
string
)

Attempt to convert a String to an HttpString.

public void
writeTo(OutputStream
the stream to write to
output
)

Append to an output stream.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

bytesback to summary
private final byte[] bytes
EMPTYback to summary
public static final HttpString EMPTY

Empty HttpString instance.

hashCodeback to summary
private final transient int hashCode
hashCodeFieldback to summary
private static final Field hashCodeField
orderIntback to summary
private final int orderInt

And integer that is only set for well known header to make comparison fast

serialVersionUIDback to summary
private static final long serialVersionUID
stringback to summary
private transient String string

Constructor Detail

HttpStringback to summary
public HttpString(final byte[] bytes)

Construct a new instance.

Parameters
bytes:byte[]

the byte array to copy

HttpStringback to summary
public HttpString(final byte[] bytes, int offset, int length)

Construct a new instance.

Parameters
bytes:byte[]

the byte array to copy

offset:int

the offset into the array to start copying

length:int

the number of bytes to copy

HttpStringback to summary
public HttpString(final ByteBuffer buffer)

Construct a new instance by reading the remaining bytes from a buffer.

Parameters
buffer:ByteBuffer

the buffer to read

HttpStringback to summary
public HttpString(final String string)

Construct a new instance from a String. The String will be used as the cached toString() value for this HttpString.

Parameters
string:String

the source string

HttpStringback to summary
pack-priv HttpString(final String string, int orderInt)
HttpStringback to summary
private HttpString(final byte[] bytes, final String string)

Method Detail

appendToback to summary
public void appendTo(ByteBuffer buffer)

Append to a byte buffer.

Parameters
buffer:ByteBuffer

the buffer to append to

byteAtback to summary
public byte byteAt(int idx)

Get the byte at an index.

Returns:byte

the byte at an index

bytesAreEqualback to summary
private static boolean bytesAreEqual(final byte[] a, final byte[] b)
bytesAreEquivalentback to summary
private static boolean bytesAreEquivalent(final byte[] a, final byte[] b)
calcHashCodeback to summary
private static int calcHashCode(final byte[] bytes)
checkForNewlinesback to summary
private void checkForNewlines()
compareToback to summary
public int compareTo(final HttpString other)

Implements java.lang.Comparable.compareTo.

Compare this string to another in a case-insensitive manner.

Parameters
other:HttpString

the other string

Returns:int

-1, 0, or 1

copyToback to summary
public void copyTo(int srcOffs, byte[] dst, int offs, int len)

Copy len bytes from this string at offset srcOffs to the given array at the given offset.

Parameters
srcOffs:int

the source offset

dst:byte[]

the destination

offs:int

the destination offset

len:int

the number of bytes to copy

copyToback to summary
public void copyTo(byte[] dst, int offs, int len)

Copy len bytes from this string to the given array at the given offset.

Parameters
dst:byte[]

the destination

offs:int

the destination offset

len:int

the number of bytes

copyToback to summary
public void copyTo(byte[] dst, int offs)

Copy all the bytes from this string to the given array at the given offset.

Parameters
dst:byte[]

the destination

offs:int

the destination offset

equalsback to summary
public boolean equals(final Object other)

Overrides java.lang.Object.equals.

Determine if this HttpString is equal to another.

Parameters
other:Object

the other object

Returns:boolean

true if they are equal, false otherwise

Annotations
@Override
equalsback to summary
public boolean equals(final HttpString other)

Determine if this HttpString is equal to another.

Parameters
other:HttpString

the other object

Returns:boolean

true if they are equal, false otherwise

equalToStringback to summary
public boolean equalToString(String headerName)
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Get the hash code.

Returns:int

the hash code

Annotations
@Override
hashCodeOfback to summary
pack-priv static int hashCodeOf(final String headerName)
higherback to summary
private static int higher(byte b)
lengthback to summary
public int length()

Get the string length.

Returns:int

the string length

readObjectback to summary
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException
takeback to summary
private static byte[] take(final ByteBuffer buffer)
toByteArrayback to summary
private static byte[] toByteArray(final String string)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Get the String representation of this HttpString.

Returns:String

the string

Annotations
@Override
tryFromStringback to summary
public static HttpString tryFromString(String string)

Attempt to convert a String to an HttpString. If the string cannot be converted, null is returned.

Parameters
string:String

the string to try

Returns:HttpString

the HTTP string, or null if the string is not in a compatible encoding

writeToback to summary
public void writeTo(OutputStream output) throws IOException

Append to an output stream.

Parameters
output:OutputStream

the stream to write to

Exceptions
IOException:
if an error occurs