org.restlet.engine.http.header
Class HeaderReader<V>

java.lang.Object
  extended by org.restlet.engine.http.header.HeaderReader<V>
Type Parameters:
V - The header value target type. There can be multiple values for a single header.
Direct Known Subclasses:
CacheDirectiveReader, ChallengeRequestReader, ContentTypeReader, CookieReader, CookieSettingReader, DimensionReader, DispositionReader, EncodingReader, ExpectationReader, LanguageReader, MethodReader, ParameterReader, PreferenceReader, RecipientInfoReader, TokenReader, WarningReader

public class HeaderReader<V>
extends java.lang.Object

HTTP-style header reader.

Author:
Jerome Louvel

Constructor Summary
HeaderReader(java.lang.String header)
          Constructor.
 
Method Summary
 void addValues(java.util.Collection<V> values)
          Adds values to the given list.
protected  boolean canAdd(V value, java.util.Collection<V> values)
          Indicates if the value can be added the the list.
protected  Parameter createParameter(java.lang.String name)
          Creates a new parameter with a null value.
protected  Parameter createParameter(java.lang.String name, java.lang.String value)
          Creates a new parameter.
 void mark()
          Marks the current position in this reader.
 int peek()
          Reads the next character.
 int read()
          Reads the next character.
 java.lang.String readComment()
          Reads the next comment.
static java.util.Date readDate(java.lang.String date, boolean cookie)
          Parses a date string.
 java.lang.String readDigits()
          Reads the next digits.
static Parameter readHeader(java.lang.CharSequence header)
          Read a header.
static Parameter readHeader(java.io.InputStream is, java.lang.StringBuilder sb)
          Read a header.
 Parameter readParameter()
          Reads the next pair as a parameter.
 java.lang.String readParameterValue()
          Reads a parameter value which is either a token or a quoted string.
 java.lang.String readQuotedString()
          Reads the next quoted string.
 java.lang.String readRawText()
          Read the next text until a space separator is reached.
 java.lang.String readRawValue()
          Read the next header value of a multi-value header.
 java.lang.String readToken()
          Reads the next token.
 V readValue()
          Read the next value.
 java.util.List<V> readValues()
          Returns a new list with all values added.
 void reset()
          Repositions this stream to the position at the time the mark method was last called on this input stream.
 boolean skipParameterSeparator()
          Skips the next parameter separator (semi-colon) including leading and trailing spaces.
 boolean skipSpaces()
          Skips the next spaces.
 boolean skipValueSeparator()
          Skips the next value separator (comma) including leading and trailing spaces.
 void unread()
          Unreads the last character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HeaderReader

public HeaderReader(java.lang.String header)
Constructor.

Parameters:
header - The header to read.
Method Detail

readDate

public static java.util.Date readDate(java.lang.String date,
                                      boolean cookie)
Parses a date string.

Parameters:
date - The date string to parse.
cookie - Indicates if the date is in the cookie format.
Returns:
The parsed date.

readHeader

public static Parameter readHeader(java.lang.CharSequence header)
                            throws java.io.IOException
Read a header. Return null if the last header was already read.

Parameters:
header - The header line to parse.
Returns:
The header read or null.
Throws:
java.io.IOException

readHeader

public static Parameter readHeader(java.io.InputStream is,
                                   java.lang.StringBuilder sb)
                            throws java.io.IOException
Read a header. Return null if the last header was already read.

Parameters:
is - The message input stream.
sb - The string builder to reuse.
Returns:
The header read or null.
Throws:
java.io.IOException

addValues

public void addValues(java.util.Collection<V> values)
Adds values to the given list.

Parameters:
values - The list of values to update.

canAdd

protected boolean canAdd(V value,
                         java.util.Collection<V> values)
Indicates if the value can be added the the list. Useful to prevent the addition of Encoding.IDENTITY constants for example. By default it returns true for non null values.

Parameters:
value - The value to add.
values - The target collection.
Returns:
True if the value can be added.

createParameter

protected final Parameter createParameter(java.lang.String name)
Creates a new parameter with a null value. Can be overridden.

Parameters:
name - The parameter name.
Returns:
The new parameter.

createParameter

protected Parameter createParameter(java.lang.String name,
                                    java.lang.String value)
Creates a new parameter. Can be overridden.

Parameters:
name - The parameter name.
value - The parameter value or null.
Returns:
The new parameter.

mark

public void mark()
Marks the current position in this reader. A subsequent call to the reset method repositions this reader at the last marked position.


peek

public int peek()
Reads the next character.

Returns:
The next character.

read

public int read()
Reads the next character.

Returns:
The next character.

readComment

public java.lang.String readComment()
                             throws java.io.IOException
Reads the next comment. The first character must be a parenthesis.

Returns:
The next comment.
Throws:
java.io.IOException

readDigits

public java.lang.String readDigits()
Reads the next digits.

Returns:
The next digits.

readParameter

public Parameter readParameter()
                        throws java.io.IOException
Reads the next pair as a parameter.

Returns:
The next pair as a parameter.
Throws:
java.io.IOException

readParameterValue

public java.lang.String readParameterValue()
                                    throws java.io.IOException
Reads a parameter value which is either a token or a quoted string.

Returns:
A parameter value.
Throws:
java.io.IOException

readQuotedString

public java.lang.String readQuotedString()
                                  throws java.io.IOException
Reads the next quoted string. The first character must be a double quote.

Returns:
The next quoted string.
Throws:
java.io.IOException

readRawText

public java.lang.String readRawText()
Read the next text until a space separator is reached.

Returns:
The next text.

readRawValue

public java.lang.String readRawValue()
Read the next header value of a multi-value header. It skips leading and trailing spaces.

Returns:
The next header value or null.
See Also:
HTTP parsing rule

readToken

public java.lang.String readToken()
Reads the next token.

Returns:
The next token.

readValue

public V readValue()
            throws java.io.IOException
Read the next value. There can be multiple values for a single header.

Returns:
The next value.
Throws:
java.io.IOException

readValues

public java.util.List<V> readValues()
Returns a new list with all values added.

Returns:
A new list with all values added.

reset

public void reset()
Repositions this stream to the position at the time the mark method was last called on this input stream.


skipParameterSeparator

public boolean skipParameterSeparator()
Skips the next parameter separator (semi-colon) including leading and trailing spaces.

Returns:
True if a separator was effectively skipped.

skipSpaces

public boolean skipSpaces()
Skips the next spaces.

Returns:
True if spaces were skipped.

skipValueSeparator

public boolean skipValueSeparator()
Skips the next value separator (comma) including leading and trailing spaces.

Returns:
True if a separator was effectively skipped.

unread

public void unread()
Unreads the last character.



Copyright © 2005-2011 Noelios Technologies.