Class RequestConsumer.Token

  • All Implemented Interfaces:
    java.lang.CharSequence
    Enclosing class:
    RequestConsumer

    private static class RequestConsumer.Token
    extends java.lang.Object
    implements java.lang.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[] array
      This is the array that contains the header bytes.
      int off
      This is the offset in the array the token begins at.
      int size
      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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      char charAt​(int index)
      This is used to acquire the character at the specified index.
      int length()
      This returns the length of the header in bytes.
      java.lang.CharSequence subSequence​(int start, int end)
      This returns a section of characters within the specified range.
      java.lang.String toString()
      This is used to create a string from the header bytes.
      java.lang.String toString​(java.lang.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
    • Field Detail

      • 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 Detail

      • 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 Detail

      • 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 java.lang.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 java.lang.CharSequence
        Parameters:
        index - the index to extract the character from
        Returns:
        this returns the character found at the index
      • subSequence

        public java.lang.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 java.lang.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 java.lang.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 java.lang.CharSequence
        Overrides:
        toString in class java.lang.Object
        Returns:
        this returns an encoded version of the header
      • toString

        public java.lang.String toString​(java.lang.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