Class RequestConsumer.Token

java.lang.Object
org.simpleframework.http.message.RequestConsumer.Token
All Implemented Interfaces:
CharSequence
Enclosing class:
RequestConsumer

private static class RequestConsumer.Token extends Object implements CharSequence
This is a sequence of characters representing the header data consumed. Here the internal byte buffer is simply wrapped so that it can be a represented as a CharSequence. Wrapping the consumed array in this manner ensures that no further memory allocation is required.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    byte[]
    This is the array that contains the header bytes.
    int
    This is the offset in the array the token begins at.
    int
    This is the number of bytes to use from the array.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Token(byte[] array, int off, int size)
    Constructor for the ByteSequence object.
  • Method Summary

    Modifier and Type
    Method
    Description
    char
    charAt(int index)
    This is used to acquire the character at the specified index.
    int
    This returns the length of the header in bytes.
    subSequence(int start, int end)
    This returns a section of characters within the specified range.
    This is used to create a string from the header bytes.
    toString(String charset)
    This is used to create a string from the header bytes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.CharSequence

    chars, codePoints, isEmpty
  • Field Details

    • array

      public byte[] array
      This is the array that contains the header bytes.
    • size

      public int size
      This is the number of bytes to use from the array.
    • off

      public int off
      This is the offset in the array the token begins at.
  • Constructor Details

    • Token

      private Token(byte[] array, int off, int size)
      Constructor for the ByteSequence object. This is used to represent the data that has been consumed by the header. It acts as a light weight wrapper for the data and avoids having to create new strings for each event.
      Parameters:
      array - this is the array representing the header
      off - the starting offset for the token range
      size - the number of bytes used for the token
  • Method Details

    • length

      public int length()
      This returns the length of the header in bytes. The length includes the request line and all of the control characters including the carriage return and line feed at the end of the request header.
      Specified by:
      length in interface CharSequence
      Returns:
      this returns the number of bytes for the header
    • charAt

      public char charAt(int index)
      This is used to acquire the character at the specified index. Characters returned from this method are simply the bytes casted to a character. This may not convert the character correctly and a more sensible method should be used.
      Specified by:
      charAt in interface CharSequence
      Parameters:
      index - the index to extract the character from
      Returns:
      this returns the character found at the index
    • subSequence

      public CharSequence subSequence(int start, int end)
      This returns a section of characters within the specified range. Acquiring a section in this manner is simply done by setting a start and end offset within the internal array.
      Specified by:
      subSequence in interface CharSequence
      Parameters:
      start - this is the start index to be used
      end - this is the end index to be used
      Returns:
      this returns a new sequence within the original
    • toString

      public String toString()
      This is used to create a string from the header bytes. This converts the header bytes to a string using a compatible encoding. This may produce different results depending on the time it is invoked, as the header consumes more data.
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
      Returns:
      this returns an encoded version of the header
    • toString

      public String toString(String charset)
      This is used to create a string from the header bytes. This converts the header bytes to a string using a compatible encoding. This may produce different results depending on the time it is invoked, as the header consumes more data.
      Parameters:
      charset - this is the encoding to use for the header
      Returns:
      this returns an encoded version of the header