org.melati.util
Class HttpHeader.Tokenizer

Package class diagram package HttpHeader.Tokenizer
java.lang.Object
  extended by java.io.StreamTokenizer
      extended by org.melati.util.HttpHeader.Tokenizer
Enclosing class:
HttpHeader

public static class HttpHeader.Tokenizer
extends StreamTokenizer

Tokenizer for parsing occurences of a field.

Header fields have format defined in RFC 2616 and have the same general form as in RFC 822 section 3.1.

This is for fields consisting of tokens, quoted strings and separators and not those consisting of an arbitrary sequence of octets. Tokens are US ASCII characters other than:

The convenience methods defined here provide some guidance on how to interact with the super-type but you can also use inherited methods.

We assume that the next token is always already read when a method starts to interpret a sequence of tokens. In other words the first token is read by the constructor(s) and then each such method returns as a result of reading a token or EOF that it cannot process but without pushing it back. The next token to be interpreted is hence the current token described by the inherited instance variables.

Note that whitespace is automatically skipped by the supertype.

Author:
Jim Wright

Field Summary
 
Fields inherited from class java.io.StreamTokenizer
nval, sval, TT_EOF, TT_EOL, TT_NUMBER, TT_WORD, ttype
 
Method Summary
 boolean isSVal()
          Convenience method to test for token or quoted string.
 int nextLToken()
          Same as nextToken() but does not throw an IOException and handles erroneous line breaks.
 void readChar(char c)
          Read the given character that comes next.
 double readNVal()
          Read the number token that comes next.
 float readQValue()
          Read a token sequence of the form "; q = 0.42" and return the number.
 String readSVal()
          Read the word token or quoted string that comes next.
protected  HttpHeader.TokenAndQValue readTokenAndQValue(HttpHeader.TokenAndQValue result)
          Read a word or quoted string token optionally followed by a string of the form "; q = 0.42" and initialises the given object.
 String readWord()
          Read the word token that comes next.
 void readWord(String word)
          Read the given word token that comes next.
 int skipAnyCommaSeparator()
          Read up to and including the next token after any comma separator(s) and whitespace.
 int skipCommaSeparator()
          Read up to and including the next token after comma separator(s) and whitespace assuming the current token is a comma.
 
Methods inherited from class java.io.StreamTokenizer
commentChar, eolIsSignificant, lineno, lowerCaseMode, nextToken, ordinaryChar, ordinaryChars, parseNumbers, pushBack, quoteChar, resetSyntax, slashSlashComments, slashStarComments, toString, whitespaceChars, wordChars
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

nextLToken

public int nextLToken()
               throws HttpHeader.HttpHeaderException
Same as nextToken() but does not throw an IOException and handles erroneous line breaks.

Returns:
int value of next LToken
Throws:
HttpHeader.HttpHeaderException - Error detected in the fields.

skipCommaSeparator

public final int skipCommaSeparator()
                             throws HttpHeader.HttpHeaderException
Read up to and including the next token after comma separator(s) and whitespace assuming the current token is a comma.

Returns:
Resulting ttype.
Throws:
HttpHeader.HttpHeaderException

skipAnyCommaSeparator

public final int skipAnyCommaSeparator()
                                throws HttpHeader.HttpHeaderException
Read up to and including the next token after any comma separator(s) and whitespace.

This is the same as skipCommaSeparator() but it does nothing if we are and EOF.

Returns:
Resulting ttype.
Throws:
HttpHeader.HttpHeaderException

isSVal

public final boolean isSVal()
Convenience method to test for token or quoted string.

If this returns true then the token value is in sval with any quotes removed.

Returns:
whether token is an SVal

readSVal

public final String readSVal()
                      throws HttpHeader.HttpHeaderException
Read the word token or quoted string that comes next.

Returns:
the SVal
Throws:
HttpHeader.HttpHeaderException - Error detected in the fields.

readWord

public final String readWord()
                      throws HttpHeader.HttpHeaderException
Read the word token that comes next.

Returns:
the word as a String
Throws:
HttpHeader.HttpHeaderException - Error detected in the fields.

readWord

public final void readWord(String word)
                    throws HttpHeader.HttpHeaderException
Read the given word token that comes next.

Throws:
HttpHeader.HttpHeaderException - Error detected in the fields.

readChar

public final void readChar(char c)
                    throws HttpHeader.HttpHeaderException
Read the given character that comes next.

Throws:
HttpHeader.HttpHeaderException - Error detected in the fields.

readNVal

public final double readNVal()
                      throws HttpHeader.HttpHeaderException
Read the number token that comes next.

Returns:
the number's value as a double
Throws:
HttpHeader.HttpHeaderException - Error detected in the fields.

readQValue

public final float readQValue()
                       throws IllegalStateException,
                              HttpHeader.HttpHeaderException
Read a token sequence of the form "; q = 0.42" and return the number.

Returns:
the number's value as a float
Throws:
IllegalStateException - Current token not semicolon.
HttpHeader.HttpHeaderException - Error detected in the fields.

readTokenAndQValue

protected HttpHeader.TokenAndQValue readTokenAndQValue(HttpHeader.TokenAndQValue result)
                                                throws HttpHeader.HttpHeaderException
Read a word or quoted string token optionally followed by a string of the form "; q = 0.42" and initialises the given object.

Returns:
current TokenAndQValue
Throws:
HttpHeader.HttpHeaderException


Copyright © 2000-2010 PanEris. All Rights Reserved.