Package io.undertow.util
Class HttpString
java.lang.Object
io.undertow.util.HttpString
- All Implemented Interfaces:
Serializable
,Comparable<HttpString>
An HTTP case-insensitive Latin-1 string.
- Author:
- David M. Lloyd
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionHttpString
(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
Modifier and TypeMethodDescriptionvoid
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
Determine if thisHttpString
is equal to another.boolean
equalToString
(String headerName) int
hashCode()
Get the hash code.int
length()
Get the string length.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 Details
-
EMPTY
Empty HttpString instance.
-
-
Constructor Details
-
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
Construct a new instance by reading the remaining bytes from a buffer.- Parameters:
buffer
- the buffer to read
-
HttpString
Construct a new instance from aString
. TheString
will be used as the cachedtoString()
value for thisHttpString
.- Parameters:
string
- the source string
-
-
Method Details
-
tryFromString
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
Append to a byte buffer.- Parameters:
buffer
- the buffer to append to
-
writeTo
Append to an output stream.- Parameters:
output
- the stream to write to- Throws:
IOException
- if an error occurs
-
compareTo
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
Determine if thisHttpString
is equal to another. -
equals
Determine if thisHttpString
is equal to another.- Parameters:
other
- the other object- Returns:
true
if they are equal,false
otherwise
-
toString
Get theString
representation of thisHttpString
. -
equalToString
-