|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.http.message.BasicTokenIterator
public class BasicTokenIterator
Basic implementation of a TokenIterator
.
This implementation parses #token
sequences as
defined by RFC 2616, section 2.
It extends that definition somewhat beyond US-ASCII.
Field Summary | |
---|---|
protected String |
currentHeader
The value of the current header. |
protected String |
currentToken
The token to be returned by the next call to nextToken() . |
protected HeaderIterator |
headerIt
The iterator from which to obtain the next header. |
static String |
HTTP_SEPARATORS
The HTTP separator characters. |
protected int |
searchPos
The position after currentToken in currentHeader . |
Constructor Summary | |
---|---|
BasicTokenIterator(HeaderIterator headerIterator)
Creates a new instance of BasicTokenIterator . |
Method Summary | |
---|---|
protected String |
createToken(String value,
int start,
int end)
Creates a new token to be returned. |
protected int |
findNext(int pos)
Determines the next token. |
protected int |
findTokenEnd(int from)
Determines the ending position of the current token. |
protected int |
findTokenSeparator(int pos)
Determines the position of the next token separator. |
protected int |
findTokenStart(int pos)
Determines the starting position of the next token. |
boolean |
hasNext()
Indicates whether there is another token in this iteration. |
protected boolean |
isHttpSeparator(char ch)
Checks whether a character is an HTTP separator. |
protected boolean |
isTokenChar(char ch)
Checks whether a character is a valid token character. |
protected boolean |
isTokenSeparator(char ch)
Checks whether a character is a token separator. |
protected boolean |
isWhitespace(char ch)
Checks whether a character is a whitespace character. |
Object |
next()
Returns the next token. |
String |
nextToken()
Obtains the next token from this iteration. |
void |
remove()
Removing tokens is not supported. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String HTTP_SEPARATORS
protected final HeaderIterator headerIt
protected String currentHeader
currentToken
.
Undefined if the iteration is over.
protected String currentToken
nextToken()
.
null
if the iteration is over.
protected int searchPos
currentToken
in currentHeader
.
Undefined if the iteration is over.
Constructor Detail |
---|
public BasicTokenIterator(HeaderIterator headerIterator)
BasicTokenIterator
.
headerIterator
- the iterator for the headers to tokenizeMethod Detail |
---|
public boolean hasNext()
TokenIterator
hasNext
in interface Iterator<Object>
hasNext
in interface TokenIterator
true
if there is another token,
false
otherwisepublic String nextToken() throws NoSuchElementException, ParseException
nextToken
in interface TokenIterator
NoSuchElementException
- if the iteration is already over
ParseException
- if an invalid header value is encounteredpublic final Object next() throws NoSuchElementException, ParseException
nextToken()
, but with generic return type.
next
in interface Iterator<Object>
NoSuchElementException
- if there are no more tokens
ParseException
- if an invalid header value is encounteredpublic final void remove() throws UnsupportedOperationException
remove
in interface Iterator<Object>
UnsupportedOperationException
- alwaysprotected int findNext(int pos) throws ParseException
currentToken
.
The return value indicates the position after the token
in currentHeader
. If necessary, the next header
will be obtained from headerIt
.
If not found, currentToken
is set to null
.
pos
- the position in the current header at which to
start the search, -1 to search in the first header
ParseException
- if an invalid header value is encounteredprotected String createToken(String value, int start, int end)
findNext
after the token is identified.
The default implementation simply calls
String.substring
.
If header values are significantly longer than tokens, and some tokens are permanently referenced by the application, there can be problems with garbage collection. A substring will hold a reference to the full characters of the original string and therefore occupies more memory than might be expected. To avoid this, override this method and create a new string instead of a substring.
value
- the full header value from which to create a tokenstart
- the index of the first token characterend
- the index after the last token character
protected int findTokenStart(int pos)
pos
- the position in the current header at which to
start the search
protected int findTokenSeparator(int pos)
pos
- the position in the current header at which to
start the search
ParseException
- if a new token is found before a token separator.
RFC 2616, section 2.1 explicitly requires a comma between
tokens for #
.protected int findTokenEnd(int from)
from
- the position of the first character of the token
from
does not
point to a token character in the current header value.protected boolean isTokenSeparator(char ch)
#token
sequences. The end of a header value will
also separate tokens, but that is not a character check.
ch
- the character to check
true
if the character is a token separator,
false
otherwiseprotected boolean isWhitespace(char ch)
ch
- the character to check
true
if the character is whitespace,
false
otherwiseprotected boolean isTokenChar(char ch)
ch
- the character to check
true
if the character is a valid token start,
false
otherwiseprotected boolean isHttpSeparator(char ch)
ch
- the character to check
true
if the character is an HTTP separator
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |