Package io.undertow.util
Class HttpString
- java.lang.Object
-
- io.undertow.util.HttpString
-
- All Implemented Interfaces:
Serializable
,Comparable<HttpString>
public final class HttpString extends Object implements Comparable<HttpString>, Serializable
An HTTP case-insensitive Latin-1 string.- Author:
- David M. Lloyd
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static HttpString
EMPTY
Empty HttpString instance.
-
Constructor Summary
Constructors Constructor Description HttpString(byte[] bytes)
Construct a new instance.HttpString(byte[] bytes, int offset, int length)
Construct a new instance.HttpString(String string)
Construct a new instance from aString
.HttpString(ByteBuffer buffer)
Construct a new instance by reading the remaining bytes from a buffer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendTo(ByteBuffer buffer)
Append to a byte buffer.byte
byteAt(int idx)
Get the byte at an index.int
compareTo(HttpString other)
Compare this string to another in a case-insensitive manner.void
copyTo(byte[] dst, int offs)
Copy all the bytes from this string to the given array at the given offset.void
copyTo(byte[] dst, int offs, int len)
Copylen
bytes from this string to the given array at the given offset.void
copyTo(int srcOffs, byte[] dst, int offs, int len)
Copylen
bytes from this string at offsetsrcOffs
to the given array at the given offset.boolean
equals(HttpString other)
Determine if thisHttpString
is equal to another.boolean
equals(Object other)
Determine if thisHttpString
is equal to another.boolean
equalToString(String headerName)
int
hashCode()
Get the hash code.int
length()
Get the string length.String
toString()
Get theString
representation of thisHttpString
.static HttpString
tryFromString(String string)
Attempt to convert aString
to anHttpString
.void
writeTo(OutputStream output)
Append to an output stream.
-
-
-
Field Detail
-
EMPTY
public static final HttpString EMPTY
Empty HttpString instance.
-
-
Constructor Detail
-
HttpString
public HttpString(byte[] bytes)
Construct a new instance.- Parameters:
bytes
- the byte array to copy
-
HttpString
public HttpString(byte[] bytes, int offset, int length)
Construct a new instance.- Parameters:
bytes
- the byte array to copyoffset
- the offset into the array to start copyinglength
- the number of bytes to copy
-
HttpString
public HttpString(ByteBuffer buffer)
Construct a new instance by reading the remaining bytes from a buffer.- Parameters:
buffer
- the buffer to read
-
HttpString
public HttpString(String string)
Construct a new instance from aString
. TheString
will be used as the cachedtoString()
value for thisHttpString
.- Parameters:
string
- the source string
-
-
Method Detail
-
tryFromString
public static HttpString tryFromString(String string)
Attempt to convert aString
to anHttpString
. If the string cannot be converted,null
is returned.- Parameters:
string
- the string to try- Returns:
- the HTTP string, or
null
if the string is not in a compatible encoding
-
length
public int length()
Get the string length.- Returns:
- the string length
-
byteAt
public byte byteAt(int idx)
Get the byte at an index.- Returns:
- the byte at an index
-
copyTo
public void copyTo(int srcOffs, byte[] dst, int offs, int len)
Copylen
bytes from this string at offsetsrcOffs
to the given array at the given offset.- Parameters:
srcOffs
- the source offsetdst
- the destinationoffs
- the destination offsetlen
- the number of bytes to copy
-
copyTo
public void copyTo(byte[] dst, int offs, int len)
Copylen
bytes from this string to the given array at the given offset.- Parameters:
dst
- the destinationoffs
- the destination offsetlen
- the number of bytes
-
copyTo
public void copyTo(byte[] dst, int offs)
Copy all the bytes from this string to the given array at the given offset.- Parameters:
dst
- the destinationoffs
- the destination offset
-
appendTo
public void appendTo(ByteBuffer buffer)
Append to a byte buffer.- Parameters:
buffer
- the buffer to append to
-
writeTo
public void writeTo(OutputStream output) throws IOException
Append to an output stream.- Parameters:
output
- the stream to write to- Throws:
IOException
- if an error occurs
-
compareTo
public int compareTo(HttpString other)
Compare this string to another in a case-insensitive manner.- Specified by:
compareTo
in interfaceComparable<HttpString>
- Parameters:
other
- the other string- Returns:
- -1, 0, or 1
-
hashCode
public int hashCode()
Get the hash code.
-
equals
public boolean equals(Object other)
Determine if thisHttpString
is equal to another.
-
equals
public boolean equals(HttpString other)
Determine if thisHttpString
is equal to another.- Parameters:
other
- the other object- Returns:
true
if they are equal,false
otherwise
-
toString
public String toString()
Get theString
representation of thisHttpString
.
-
equalToString
public boolean equalToString(String headerName)
-
-