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

java.lang.Object
  extended by org.restlet.engine.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, PreferenceReader, RecipientInfoReader, TokenReader, WarningReader

public class HeaderReader<V>
extends Object

HTTP-style header reader.

Author:
Jerome Louvel

Constructor Summary
HeaderReader(String header)
          Constructor.
 
Method Summary
 void addValues(Collection<V> values)
          Adds values to the given list.
protected  boolean canAdd(V value, Collection<V> values)
          Indicates if the value can be added the the list.
protected  Parameter createParameter(String name)
          Creates a new parameter with a null value.
protected  Parameter createParameter(String name, String value)
          Creates a new parameter.
 void mark()
          Marks the current position in this reader.
 int peek()
          Reads the next character without moving the reader index.
 int read()
          Reads the next character.
 String readActualNamedValue()
          Reads a parameter value which is either a token or a quoted string.
 String readComment()
          Reads the next comment.
static Date readDate(String date, boolean cookie)
          Parses a date string.
 String readDigits()
          Reads the next digits.
static Header readHeader(CharSequence header)
          Read a header.
static Header readHeader(InputStream is, StringBuilder sb)
          Read a header.
<NV extends NamedValue<String>>
NV
readNamedValue(Class<NV> resultClass)
          Reads the next pair as a parameter.
 Parameter readParameter()
          Reads the next pair as a parameter.
 String readQuotedString()
          Reads the next quoted string.
 String readRawText()
          Read the next text until a space separator is reached.
 String readRawValue()
          Read the next header value of a multi-value header.
 String readToken()
          Reads the next token.
 V readValue()
          Read the next value.
 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(String header)
Constructor.

Parameters:
header - The header to read.
Method Detail

readDate

public static Date readDate(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 Header readHeader(CharSequence header)
                         throws 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:
IOException

readHeader

public static Header readHeader(InputStream is,
                                StringBuilder sb)
                         throws 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:
IOException

addValues

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

Parameters:
values - The list of values to update.

canAdd

protected boolean canAdd(V value,
                         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(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(String name,
                                    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 without moving the reader index.

Returns:
The next character.

read

public int read()
Reads the next character.

Returns:
The next character.

readActualNamedValue

public String readActualNamedValue()
                            throws IOException
Reads a parameter value which is either a token or a quoted string.

Returns:
A parameter value.
Throws:
IOException

readComment

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

Returns:
The next comment.
Throws:
IOException

readDigits

public String readDigits()
Reads the next digits.

Returns:
The next digits.

readNamedValue

public <NV extends NamedValue<String>> NV readNamedValue(Class<NV> resultClass)
                                             throws IOException
Reads the next pair as a parameter.

Parameters:
resultClass - The named value class to return.
Returns:
The next pair as a parameter.
Throws:
IOException

readParameter

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

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

readQuotedString

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

Returns:
The next quoted string.
Throws:
IOException

readRawText

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

Returns:
The next text.

readRawValue

public 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 String readToken()
Reads the next token.

Returns:
The next token.

readValue

public V readValue()
            throws IOException
Read the next value. There can be multiple values for a single header. Returns null by default.

Returns:
The next value.
Throws:
IOException

readValues

public 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-2013 Restlet.