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
HTTP-style header reader.
- Author:
- Jerome Louvel
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddValues(Collection<V> values) Adds values to the given list.protected booleancanAdd(V value, Collection<V> values) Indicates if the value can be added the the list.protected final ParametercreateParameter(String name) Creates a new parameter with a null value.protected ParametercreateParameter(String name, String value) Creates a new parameter.voidmark()Marks the current position in this reader.intpeek()Reads the next character without moving the reader index.intread()Reads the next character.Reads a parameter value which is either a token or a quoted string.Reads the next comment.static DateParses a date string.Reads the next digits.static HeaderreadHeader(InputStream is, StringBuilder sb) Read a header.static HeaderreadHeader(CharSequence header) Read a header.<NV extends NamedValue<String>>
NVreadNamedValue(Class<NV> resultClass) Reads the next pair as a parameter.Reads the next pair as a parameter.Reads the next quoted string.Read the next text until a space separator is reached.Read the next header value of a multi-value header.Reads the next token.Read the next value.Returns a new list with all values added.voidreset()Repositions this stream to the position at the time themarkmethod was last called on this input stream.booleanSkips the next parameter separator (semi-colon) including leading and trailing spaces.booleanSkips the next spaces.booleanSkips the next value separator (comma) including leading and trailing spaces.voidunread()Unreads the last character.
-
Constructor Details
-
HeaderReader
Constructor.- Parameters:
header- The header to read.
-
-
Method Details
-
readDate
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
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
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
Adds values to the given list.- Parameters:
values- The list of values to update.
-
canAdd
Indicates if the value can be added the the list. Useful to prevent the addition ofEncoding.IDENTITYconstants 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
Creates a new parameter with a null value. Can be overridden.- Parameters:
name- The parameter name.- Returns:
- The new parameter.
-
createParameter
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 theresetmethod 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
Reads a parameter value which is either a token or a quoted string.- Returns:
- A parameter value.
- Throws:
IOException
-
readComment
Reads the next comment. The first character must be a parenthesis.- Returns:
- The next comment.
- Throws:
IOException
-
readDigits
Reads the next digits.- Returns:
- The next digits.
-
readNamedValue
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
Reads the next pair as a parameter.- Returns:
- The next pair as a parameter.
- Throws:
IOException
-
readQuotedString
Reads the next quoted string. The first character must be a double quote.- Returns:
- The next quoted string.
- Throws:
IOException
-
readRawText
Read the next text until a space separator is reached.- Returns:
- The next text.
-
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:
-
readToken
Reads the next token.- Returns:
- The next token.
-
readValue
Read the next value. There can be multiple values for a single header. Returns null by default.- Returns:
- The next value.
- Throws:
IOException
-
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 themarkmethod 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.
-