public class Tokenizer
extends java.lang.Object
implements java.lang.AutoCloseable
Modifier and Type | Class and Description |
---|---|
static class |
Tokenizer.Token |
Modifier and Type | Field and Description |
---|---|
static int |
COMMENT
A comment; only returned when wantComment is set
|
private Tokenizer.Token |
current |
private static java.lang.String |
DEFAULT_DELIMITERS |
private java.lang.String |
delimiters |
static int |
EOF
End of file
|
static int |
EOL
End of line
|
private java.lang.String |
filename |
static int |
IDENTIFIER
An identifier (unquoted string)
|
private java.io.PushbackInputStream |
is |
private int |
line |
private int |
multiline |
static int |
QUOTED_STRING
A quoted string
|
private static java.lang.String |
QUOTES |
private boolean |
quoting |
private java.lang.StringBuilder |
sb |
private boolean |
ungottenToken |
private boolean |
wantClose |
static int |
WHITESPACE
Whitespace; only returned when wantWhitespace is set
|
Constructor and Description |
---|
Tokenizer(java.io.File f)
Creates a Tokenizer from a file.
|
Tokenizer(java.io.InputStream is)
Creates a Tokenizer from an arbitrary input stream.
|
Tokenizer(java.lang.String s)
Creates a Tokenizer from a string.
|
Modifier and Type | Method and Description |
---|---|
private void |
checkUnbalancedParens() |
void |
close()
Closes any files opened by this tokenizer.
|
TextParseException |
exception(java.lang.String s)
Creates an exception which includes the current state in the error message
|
Tokenizer.Token |
get()
Gets the next token from a tokenizer, ignoring whitespace and comments.
|
Tokenizer.Token |
get(boolean wantWhitespace,
boolean wantComment)
Gets the next token from a tokenizer.
|
java.net.InetAddress |
getAddress(int family)
Gets the next token from a tokenizer and converts it to an IP Address.
|
byte[] |
getAddressBytes(int family)
Gets the next token from a tokenizer and converts it to a byte array containing an IP address.
|
byte[] |
getBase32String(base32 b32)
Gets the next token from a tokenizer and decodes it as base32.
|
byte[] |
getBase64()
Gets the remaining string tokens until an EOL/EOF is seen, concatenates them together, and
converts the base64 encoded data to a byte array.
|
byte[] |
getBase64(boolean required)
Gets the remaining string tokens until an EOL/EOF is seen, concatenates them together, and
converts the base64 encoded data to a byte array.
|
private int |
getChar() |
void |
getEOL()
Gets the next token from a tokenizer, which must be an EOL or EOF.
|
byte[] |
getHex()
Gets the remaining string tokens until an EOL/EOF is seen, concatenates them together, and
converts the hex encoded data to a byte array.
|
byte[] |
getHex(boolean required)
Gets the remaining string tokens until an EOL/EOF is seen, concatenates them together, and
converts the hex encoded data to a byte array.
|
byte[] |
getHexString()
Gets the next token from a tokenizer and decodes it as hex.
|
java.lang.String |
getIdentifier()
Gets the next token from a tokenizer, ensures it is an unquoted string, and converts it to a
string.
|
private java.lang.String |
getIdentifier(java.lang.String expected) |
long |
getLong()
Gets the next token from a tokenizer and converts it to a long.
|
Name |
getName(Name origin)
Gets the next token from a tokenizer and converts it to a name.
|
java.lang.String |
getString()
Gets the next token from a tokenizer and converts it to a string.
|
long |
getTTL()
Gets the next token from a tokenizer and parses it as a TTL.
|
long |
getTTLLike()
Gets the next token from a tokenizer and parses it as if it were a TTL.
|
int |
getUInt16()
Gets the next token from a tokenizer and converts it to an unsigned 16 bit integer.
|
long |
getUInt32()
Gets the next token from a tokenizer and converts it to an unsigned 32 bit integer.
|
int |
getUInt8()
Gets the next token from a tokenizer and converts it to an unsigned 8 bit integer.
|
private java.lang.String |
remainingStrings()
Returns a concatenation of the remaining strings from a Tokenizer.
|
private Tokenizer.Token |
setCurrentToken(int type,
java.lang.StringBuilder value) |
private int |
skipWhitespace() |
void |
unget()
Returns a token to the stream, so that it will be returned by the next call to get().
|
private void |
ungetChar(int c) |
private static final java.lang.String DEFAULT_DELIMITERS
private static final java.lang.String QUOTES
public static final int EOF
public static final int EOL
public static final int WHITESPACE
public static final int IDENTIFIER
public static final int QUOTED_STRING
public static final int COMMENT
private final java.io.PushbackInputStream is
private boolean ungottenToken
private int multiline
private boolean quoting
private java.lang.String delimiters
private Tokenizer.Token current
private final java.lang.StringBuilder sb
private boolean wantClose
private java.lang.String filename
private int line
public Tokenizer(java.io.InputStream is)
is
- The InputStream to tokenize.public Tokenizer(java.lang.String s)
s
- The String to tokenize.public Tokenizer(java.io.File f) throws java.io.FileNotFoundException
f
- The File to tokenize.java.io.FileNotFoundException
private int getChar() throws java.io.IOException
java.io.IOException
private void ungetChar(int c) throws java.io.IOException
java.io.IOException
private int skipWhitespace() throws java.io.IOException
java.io.IOException
private void checkUnbalancedParens() throws TextParseException
TextParseException
public Tokenizer.Token get(boolean wantWhitespace, boolean wantComment) throws java.io.IOException
wantWhitespace
- If true, leading whitespace will be returned as a token.wantComment
- If true, comments are returned as tokens.TextParseException
- The input was invalid.java.io.IOException
- An I/O error occurred.private Tokenizer.Token setCurrentToken(int type, java.lang.StringBuilder value)
public Tokenizer.Token get() throws java.io.IOException
TextParseException
- The input was invalid.java.io.IOException
- An I/O error occurred.public void unget()
java.lang.IllegalStateException
- There are already ungotten tokens.public java.lang.String getString() throws java.io.IOException
TextParseException
- The input was invalid or not a string.java.io.IOException
- An I/O error occurred.private java.lang.String getIdentifier(java.lang.String expected) throws java.io.IOException
java.io.IOException
public java.lang.String getIdentifier() throws java.io.IOException
TextParseException
- The input was invalid or not an unquoted string.java.io.IOException
- An I/O error occurred.public long getLong() throws java.io.IOException
TextParseException
- The input was invalid or not a long.java.io.IOException
- An I/O error occurred.public long getUInt32() throws java.io.IOException
TextParseException
- The input was invalid or not an unsigned 32 bit integer.java.io.IOException
- An I/O error occurred.public int getUInt16() throws java.io.IOException
TextParseException
- The input was invalid or not an unsigned 16 bit integer.java.io.IOException
- An I/O error occurred.public int getUInt8() throws java.io.IOException
TextParseException
- The input was invalid or not an unsigned 8 bit integer.java.io.IOException
- An I/O error occurred.public long getTTL() throws java.io.IOException
TextParseException
- The input was not valid.java.io.IOException
- An I/O error occurred.TTL
public long getTTLLike() throws java.io.IOException
TextParseException
- The input was not valid.java.io.IOException
- An I/O error occurred.TTL
public Name getName(Name origin) throws java.io.IOException
origin
- The origin to append to relative names.TextParseException
- The input was invalid or not a valid name.java.io.IOException
- An I/O error occurred.RelativeNameException
- The parsed name was relative, even with the origin.Name
public byte[] getAddressBytes(int family) throws java.io.IOException
family
- The address family.TextParseException
- The input was invalid or not a valid address.java.io.IOException
- An I/O error occurred.Address
public java.net.InetAddress getAddress(int family) throws java.io.IOException
family
- The address family.TextParseException
- The input was invalid or not a valid address.java.io.IOException
- An I/O error occurred.Address
public void getEOL() throws java.io.IOException
TextParseException
- The input was invalid or not an EOL or EOF token.java.io.IOException
- An I/O error occurred.private java.lang.String remainingStrings() throws java.io.IOException
java.io.IOException
public byte[] getBase64(boolean required) throws java.io.IOException
required
- If true, an exception will be thrown if no strings remain; otherwise null be be
returned.TextParseException
- The input was invalid.java.io.IOException
- An I/O error occurred.public byte[] getBase64() throws java.io.IOException
TextParseException
- The input was invalid.java.io.IOException
- An I/O error occurred.public byte[] getHex(boolean required) throws java.io.IOException
required
- If true, an exception will be thrown if no strings remain; otherwise null be be
returned.TextParseException
- The input was invalid.java.io.IOException
- An I/O error occurred.public byte[] getHex() throws java.io.IOException
TextParseException
- The input was invalid.java.io.IOException
- An I/O error occurred.public byte[] getHexString() throws java.io.IOException
TextParseException
- The input was invalid.java.io.IOException
- An I/O error occurred.public byte[] getBase32String(base32 b32) throws java.io.IOException
b32
- The base32 context to decode with.TextParseException
- The input was invalid.java.io.IOException
- An I/O error occurred.public TextParseException exception(java.lang.String s)
s
- The error message to include.public void close()
close
in interface java.lang.AutoCloseable