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:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final HttpString
    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.
    Construct a new instance from a String.
    Construct a new instance by reading the remaining bytes from a buffer.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Append to a byte buffer.
    byte
    byteAt(int idx)
    Get the byte at an index.
    int
    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)
    Copy len bytes from this string to the given array at the given offset.
    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.
    boolean
    Determine if this HttpString is equal to another.
    boolean
    equals(Object other)
    Determine if this HttpString is equal to another.
    boolean
    equalToString(String headerName)
     
    int
    Get the hash code.
    int
    Get the string length.
    Get the String representation of this HttpString.
    static HttpString
    Attempt to convert a String to an HttpString.
    void
    Append to an output stream.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • EMPTY

      public static final HttpString 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 copy
      offset - the offset into the array to start copying
      length - 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 a String. The String will be used as the cached toString() value for this HttpString.
      Parameters:
      string - the source string
  • Method Details

    • tryFromString

      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 - 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)
      Copy len bytes from this string at offset srcOffs to the given array at the given offset.
      Parameters:
      srcOffs - the source offset
      dst - the destination
      offs - the destination offset
      len - the number of bytes to copy
    • copyTo

      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 - the destination
      offs - the destination offset
      len - 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 destination
      offs - 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 interface Comparable<HttpString>
      Parameters:
      other - the other string
      Returns:
      -1, 0, or 1
    • hashCode

      public int hashCode()
      Get the hash code.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code
    • equals

      public boolean equals(Object other)
      Determine if this HttpString is equal to another.
      Overrides:
      equals in class Object
      Parameters:
      other - the other object
      Returns:
      true if they are equal, false otherwise
    • equals

      public boolean equals(HttpString other)
      Determine if this HttpString is equal to another.
      Parameters:
      other - the other object
      Returns:
      true if they are equal, false otherwise
    • toString

      public String toString()
      Get the String representation of this HttpString.
      Overrides:
      toString in class Object
      Returns:
      the string
    • equalToString

      public boolean equalToString(String headerName)