Basic implementation of a com.good.gd.apache.http.TokenIterator. More...
This implementation parses token
sequences as defined by RFC 2616, section 2. It extends that definition somewhat beyond US-ASCII.
The following notice applies to the original API on which this API is based, and to its documentation. The documentation of this API has been revised from the original.
/* * Copyright (C) 2006 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */
Public Member Functions | |
BasicTokenIterator (final HeaderIterator headerIterator) | |
Creates a new instance of BasicTokenIterator. More... | |
boolean | hasNext () |
Indicates whether there is another token in this iteration. More... | |
String | nextToken () throws NoSuchElementException, ParseException |
Obtains the next token from this iteration. More... | |
final Object | next () throws NoSuchElementException, ParseException |
Returns the next token. More... | |
final void | remove () throws UnsupportedOperationException |
Removing tokens is not supported. More... | |
Static Public Attributes | |
static final String | HTTP_SEPARATORS = " ,;=()<>@:\\\"/[]?{}\t" |
The HTTP separator characters. More... | |
Protected Member Functions | |
int | findNext (int from) throws ParseException |
Determines the next token. More... | |
String | createToken (String value, int start, int end) |
Creates a new token to be returned. More... | |
int | findTokenStart (int from) |
Determines the starting position of the next token. More... | |
int | findTokenSeparator (int from) |
Determines the position of the next token separator. More... | |
int | findTokenEnd (int from) |
Determines the ending position of the current token. More... | |
boolean | isTokenSeparator (char ch) |
Checks whether a character is a token separator. More... | |
boolean | isWhitespace (char ch) |
Checks whether a character is a whitespace character. More... | |
boolean | isTokenChar (char ch) |
Checks whether a character is a valid token character. More... | |
boolean | isHttpSeparator (char ch) |
Checks whether a character is an HTTP separator. More... | |
Protected Attributes | |
final HeaderIterator | headerIt |
The iterator from which to obtain the next header. More... | |
String | currentHeader |
The value of the current header. More... | |
String | currentToken |
The token to be returned by the next call to currentToken. More... | |
int | searchPos |
The position after currentToken in currentHeader. More... | |
BasicTokenIterator | ( | final HeaderIterator | headerIterator | ) |
headerIterator | the iterator for the headers to tokenize |
boolean hasNext | ( | ) |
true
if there is another token, false
otherwise Implements TokenIterator.
String nextToken | ( | ) | throws NoSuchElementException, ParseException |
NoSuchElementException | if the iteration is already over |
ParseException | if an invalid header value is encountered |
Implements TokenIterator.
final Object next | ( | ) | throws NoSuchElementException, ParseException |
Same as nextToken, but with generic return type.
NoSuchElementException | if there are no more tokens |
ParseException | if an invalid header value is encountered |
final void remove | ( | ) | throws UnsupportedOperationException |
UnsupportedOperationException | always |
|
protected |
If found, the token is stored in 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
.
from | 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 encountered |
|
protected |
Called from findNext after the token is identified. The default implementation simply calls java.lang.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 token |
start | the index of the first token character |
end | the index after the last token character |
|
protected |
This method will iterate over headers if necessary.
from | the position in the current header at which to start the search |
|
protected |
Because of multi-header joining rules, the end of a header value is a token separator. This method does therefore not need to iterate over headers.
from | 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 |
This method will not leave the current header value, since the end of the header value is a token boundary.
from | the position of the first character of the token |
from
does not point to a token character in the current header value.
|
protected |
RFC 2616, section 2.1 defines comma as the separator for 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
otherwise
|
protected |
RFC 2616, section 2.2 defines space and horizontal tab as whitespace. The optional preceeding line break is irrelevant, since header continuation is handled transparently when parsing messages.
ch | the character to check |
true
if the character is whitespace, false
otherwise
|
protected |
Whitespace, control characters, and HTTP separators are not valid token characters. The HTTP specification (RFC 2616, section 2.2) defines tokens only for the US-ASCII character set, this method extends the definition to other character sets.
ch | the character to check |
true
if the character is a valid token start, false
otherwise
|
protected |
The implementation in this class checks only for the HTTP separators defined in RFC 2616, section 2.2. If you need to detect other separators beyond the US-ASCII character set, override this method.
ch | the character to check |
true
if the character is an HTTP separator
|
static |
Defined in RFC 2616, section 2.2.
|
protected |
|
protected |
This is the header value that includes currentToken. Undefined if the iteration is over.
|
protected |
null
if the iteration is over.
|
protected |
Undefined if the iteration is over.