• BlackBerry Dynamics
  • Runtime library for Android applications
  • 12.0.1.79
BasicTokenIterator Class Reference

Basic implementation of a com.good.gd.apache.http.TokenIterator. More...

Inheritance diagram for BasicTokenIterator:
TokenIterator

Description

This implementation parses token sequences as defined by RFC 2616, section 2. It extends that definition somewhat beyond US-ASCII.

Version
Revision
602520

Notice

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...
 

Constructor & Destructor Documentation

◆ BasicTokenIterator()

BasicTokenIterator ( final HeaderIterator  headerIterator)
Parameters
headerIteratorthe iterator for the headers to tokenize

Member Function Documentation

◆ hasNext()

boolean hasNext ( )
Returns
true if there is another token, false otherwise

Implements TokenIterator.

◆ nextToken()

String nextToken ( ) throws NoSuchElementException, ParseException
Returns
the next token in this iteration
Exceptions
NoSuchElementExceptionif the iteration is already over
ParseExceptionif an invalid header value is encountered

Implements TokenIterator.

◆ next()

final Object next ( ) throws NoSuchElementException, ParseException

Same as nextToken, but with generic return type.

Returns
the next token in this iteration
Exceptions
NoSuchElementExceptionif there are no more tokens
ParseExceptionif an invalid header value is encountered

◆ remove()

final void remove ( ) throws UnsupportedOperationException
Exceptions
UnsupportedOperationExceptionalways

◆ findNext()

int findNext ( int  from) throws ParseException
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.

Parameters
fromthe position in the current header at which to start the search, -1 to search in the first header
Returns
the position after the found token in the current header, or negative if there was no next token
Exceptions
ParseExceptionif an invalid header value is encountered

◆ createToken()

String createToken ( String  value,
int  start,
int  end 
)
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.

Parameters
valuethe full header value from which to create a token
startthe index of the first token character
endthe index after the last token character
Returns
a string representing the token identified by the arguments

◆ findTokenStart()

int findTokenStart ( int  from)
protected

This method will iterate over headers if necessary.

Parameters
fromthe position in the current header at which to start the search
Returns
the position of the token start in the current header, negative if no token start could be found

◆ findTokenSeparator()

int findTokenSeparator ( int  from)
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.

Parameters
fromthe position in the current header at which to start the search
Returns
the position of a token separator in the current header, or at the end
Exceptions
ParseExceptionif a new token is found before a token separator. RFC 2616, section 2.1 explicitly requires a comma between tokens for #.

◆ findTokenEnd()

int findTokenEnd ( int  from)
protected

This method will not leave the current header value, since the end of the header value is a token boundary.

Parameters
fromthe position of the first character of the token
Returns
the position after the last character of the token. The behavior is undefined if from does not point to a token character in the current header value.

◆ isTokenSeparator()

boolean isTokenSeparator ( char  ch)
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.

Parameters
chthe character to check
Returns
true if the character is a token separator, false otherwise

◆ isWhitespace()

boolean isWhitespace ( char  ch)
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.

Parameters
chthe character to check
Returns
true if the character is whitespace, false otherwise

◆ isTokenChar()

boolean isTokenChar ( char  ch)
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.

Parameters
chthe character to check
Returns
true if the character is a valid token start, false otherwise

◆ isHttpSeparator()

boolean isHttpSeparator ( char  ch)
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.

Parameters
chthe character to check
Returns
true if the character is an HTTP separator

Member Data Documentation

◆ HTTP_SEPARATORS

final String HTTP_SEPARATORS = " ,;=()<>@:\\\"/[]?{}\t"
static

Defined in RFC 2616, section 2.2.

◆ headerIt

final HeaderIterator headerIt
protected

◆ currentHeader

String currentHeader
protected

This is the header value that includes currentToken. Undefined if the iteration is over.

◆ currentToken

String currentToken
protected

null if the iteration is over.

◆ searchPos

int searchPos
protected

Undefined if the iteration is over.