Package org.restlet.engine.header
Class HeaderReader<V>
- java.lang.Object
-
- 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
,StringReader
,TagReader
,TokenReader
,WarningReader
public class HeaderReader<V> extends java.lang.Object
HTTP-style header reader.- Author:
- Jerome Louvel
-
-
Constructor Summary
Constructors Constructor Description HeaderReader(java.lang.String header)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 org.restlet.data.Parameter
createParameter(java.lang.String name)
Creates a new parameter with a null value.protected org.restlet.data.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 without moving the reader index.int
read()
Reads the next character.java.lang.String
readActualNamedValue()
Reads a parameter value which is either a token or a quoted string.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 org.restlet.data.Header
readHeader(java.io.InputStream is, java.lang.StringBuilder sb)
Read a header.static org.restlet.data.Header
readHeader(java.lang.CharSequence header)
Read a header.<NV extends org.restlet.util.NamedValue<java.lang.String>>
NVreadNamedValue(java.lang.Class<NV> resultClass)
Reads the next pair as a parameter.org.restlet.data.Parameter
readParameter()
Reads the next pair as a parameter.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 themark
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.
-
-
-
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 org.restlet.data.Header 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 org.restlet.data.Header 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 ofEncoding.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 org.restlet.data.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 org.restlet.data.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 thereset
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 java.lang.String readActualNamedValue() 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
-
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.
-
readNamedValue
public <NV extends org.restlet.util.NamedValue<java.lang.String>> NV readNamedValue(java.lang.Class<NV> resultClass) throws java.io.IOException
Reads the next pair as a parameter.- Parameters:
resultClass
- The named value class to return.- Returns:
- The next pair as a parameter.
- Throws:
java.io.IOException
-
readParameter
public org.restlet.data.Parameter readParameter() throws java.io.IOException
Reads the next pair as a parameter.- Returns:
- The next pair as a parameter.
- 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 null by default.- 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 themark
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.
-
-