Package org.simpleframework.http.message
Class RequestConsumer.Token
- java.lang.Object
-
- org.simpleframework.http.message.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 aCharSequence
. Wrapping the consumed array in this manner ensures that no further memory allocation is required.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
Token(byte[] array, int off, int size)
Constructor for theByteSequence
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.
-
-
-
Constructor Detail
-
Token
private Token(byte[] array, int off, int size)
Constructor for theByteSequence
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 headeroff
- the starting offset for the token rangesize
- 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 interfacejava.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 interfacejava.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 interfacejava.lang.CharSequence
- Parameters:
start
- this is the start index to be usedend
- 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 interfacejava.lang.CharSequence
- Overrides:
toString
in classjava.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
-
-