Package org.xbill.DNS
Class Tokenizer
java.lang.Object
org.xbill.DNS.Tokenizer
- All Implemented Interfaces:
AutoCloseable
Tokenizer is used to parse DNS records and zones from text format,
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intA comment; only returned when wantComment is setprivate Tokenizer.Tokenprivate static final Stringprivate Stringstatic final intEnd of filestatic final intEnd of lineprivate Stringstatic final intAn identifier (unquoted string)private final PushbackInputStreamprivate intprivate intstatic final intA quoted stringprivate static final Stringprivate booleanprivate final StringBuilderprivate booleanprivate booleanstatic final intWhitespace; only returned when wantWhitespace is set -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidvoidclose()Closes any files opened by this tokenizer.Creates an exception which includes the current state in the error messageget()Gets the next token from a tokenizer, ignoring whitespace and comments.get(boolean wantWhitespace, boolean wantComment) Gets the next token from a tokenizer.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[]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 intgetChar()voidgetEOL()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[]Gets the next token from a tokenizer and decodes it as hex.Gets the next token from a tokenizer, ensures it is an unquoted string, and converts it to a string.private StringgetIdentifier(String expected) longgetLong()Gets the next token from a tokenizer and converts it to a long.Gets the next token from a tokenizer and converts it to a name.Gets the next token from a tokenizer and converts it to a string.longgetTTL()Gets the next token from a tokenizer and parses it as a TTL.longGets the next token from a tokenizer and parses it as if it were a TTL.intGets the next token from a tokenizer and converts it to an unsigned 16 bit integer.longGets the next token from a tokenizer and converts it to an unsigned 32 bit integer.intgetUInt8()Gets the next token from a tokenizer and converts it to an unsigned 8 bit integer.private StringReturns a concatenation of the remaining strings from a Tokenizer.private Tokenizer.TokensetCurrentToken(int type, StringBuilder value) private intvoidunget()Returns a token to the stream, so that it will be returned by the next call to get().private voidungetChar(int c)
-
Field Details
-
DEFAULT_DELIMITERS
- See Also:
-
QUOTES
- See Also:
-
EOF
public static final int EOFEnd of file- See Also:
-
EOL
public static final int EOLEnd of line- See Also:
-
WHITESPACE
public static final int WHITESPACEWhitespace; only returned when wantWhitespace is set- See Also:
-
IDENTIFIER
public static final int IDENTIFIERAn identifier (unquoted string)- See Also:
-
QUOTED_STRING
public static final int QUOTED_STRINGA quoted string- See Also:
-
COMMENT
public static final int COMMENTA comment; only returned when wantComment is set- See Also:
-
is
-
ungottenToken
private boolean ungottenToken -
multiline
private int multiline -
quoting
private boolean quoting -
delimiters
-
current
-
sb
-
wantClose
private boolean wantClose -
filename
-
line
private int line
-
-
Constructor Details
-
Tokenizer
Creates a Tokenizer from an arbitrary input stream.- Parameters:
is- The InputStream to tokenize.
-
Tokenizer
Creates a Tokenizer from a string.- Parameters:
s- The String to tokenize.
-
Tokenizer
Creates a Tokenizer from a file.- Parameters:
f- The File to tokenize.- Throws:
FileNotFoundException
-
-
Method Details
-
getChar
- Throws:
IOException
-
ungetChar
- Throws:
IOException
-
skipWhitespace
- Throws:
IOException
-
checkUnbalancedParens
- Throws:
TextParseException
-
get
Gets the next token from a tokenizer.- Parameters:
wantWhitespace- If true, leading whitespace will be returned as a token.wantComment- If true, comments are returned as tokens.- Returns:
- The next token in the stream.
- Throws:
TextParseException- The input was invalid.IOException- An I/O error occurred.
-
setCurrentToken
-
get
Gets the next token from a tokenizer, ignoring whitespace and comments.- Returns:
- The next token in the stream.
- Throws:
TextParseException- The input was invalid.IOException- An I/O error occurred.
-
unget
public void unget()Returns a token to the stream, so that it will be returned by the next call to get().- Throws:
IllegalStateException- There are already ungotten tokens.
-
getString
Gets the next token from a tokenizer and converts it to a string.- Returns:
- The next token in the stream, as a string.
- Throws:
TextParseException- The input was invalid or not a string.IOException- An I/O error occurred.
-
getIdentifier
- Throws:
IOException
-
getIdentifier
Gets the next token from a tokenizer, ensures it is an unquoted string, and converts it to a string.- Returns:
- The next token in the stream, as a string.
- Throws:
TextParseException- The input was invalid or not an unquoted string.IOException- An I/O error occurred.
-
getLong
Gets the next token from a tokenizer and converts it to a long.- Returns:
- The next token in the stream, as a long.
- Throws:
TextParseException- The input was invalid or not a long.IOException- An I/O error occurred.
-
getUInt32
Gets the next token from a tokenizer and converts it to an unsigned 32 bit integer.- Returns:
- The next token in the stream, as an unsigned 32 bit integer.
- Throws:
TextParseException- The input was invalid or not an unsigned 32 bit integer.IOException- An I/O error occurred.
-
getUInt16
Gets the next token from a tokenizer and converts it to an unsigned 16 bit integer.- Returns:
- The next token in the stream, as an unsigned 16 bit integer.
- Throws:
TextParseException- The input was invalid or not an unsigned 16 bit integer.IOException- An I/O error occurred.
-
getUInt8
Gets the next token from a tokenizer and converts it to an unsigned 8 bit integer.- Returns:
- The next token in the stream, as an unsigned 8 bit integer.
- Throws:
TextParseException- The input was invalid or not an unsigned 8 bit integer.IOException- An I/O error occurred.
-
getTTL
Gets the next token from a tokenizer and parses it as a TTL.- Returns:
- The next token in the stream, as an unsigned 32 bit integer.
- Throws:
TextParseException- The input was not valid.IOException- An I/O error occurred.- See Also:
-
getTTLLike
Gets the next token from a tokenizer and parses it as if it were a TTL.- Returns:
- The next token in the stream, as an unsigned 32 bit integer.
- Throws:
TextParseException- The input was not valid.IOException- An I/O error occurred.- See Also:
-
getName
Gets the next token from a tokenizer and converts it to a name.- Parameters:
origin- The origin to append to relative names.- Returns:
- The next token in the stream, as a name.
- Throws:
TextParseException- The input was invalid or not a valid name.IOException- An I/O error occurred.RelativeNameException- The parsed name was relative, even with the origin.- See Also:
-
getAddressBytes
Gets the next token from a tokenizer and converts it to a byte array containing an IP address.- Parameters:
family- The address family.- Returns:
- The next token in the stream, as an byte array representing an IP address.
- Throws:
TextParseException- The input was invalid or not a valid address.IOException- An I/O error occurred.- See Also:
-
getAddress
Gets the next token from a tokenizer and converts it to an IP Address.- Parameters:
family- The address family.- Returns:
- The next token in the stream, as an InetAddress
- Throws:
TextParseException- The input was invalid or not a valid address.IOException- An I/O error occurred.- See Also:
-
getEOL
Gets the next token from a tokenizer, which must be an EOL or EOF.- Throws:
TextParseException- The input was invalid or not an EOL or EOF token.IOException- An I/O error occurred.
-
remainingStrings
Returns a concatenation of the remaining strings from a Tokenizer.- Throws:
IOException
-
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.- Parameters:
required- If true, an exception will be thrown if no strings remain; otherwise null be be returned.- Returns:
- The byte array containing the decoded strings, or null if there were no strings to decode.
- Throws:
TextParseException- The input was invalid.IOException- An I/O error occurred.
-
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.- Returns:
- The byte array containing the decoded strings, or null if there were no strings to decode.
- Throws:
TextParseException- The input was invalid.IOException- An I/O error occurred.
-
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.- Parameters:
required- If true, an exception will be thrown if no strings remain; otherwise null be be returned.- Returns:
- The byte array containing the decoded strings, or null if there were no strings to decode.
- Throws:
TextParseException- The input was invalid.IOException- An I/O error occurred.
-
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.- Returns:
- The byte array containing the decoded strings, or null if there were no strings to decode.
- Throws:
TextParseException- The input was invalid.IOException- An I/O error occurred.
-
getHexString
Gets the next token from a tokenizer and decodes it as hex.- Returns:
- The byte array containing the decoded string.
- Throws:
TextParseException- The input was invalid.IOException- An I/O error occurred.
-
getBase32String
Gets the next token from a tokenizer and decodes it as base32.- Parameters:
b32- The base32 context to decode with.- Returns:
- The byte array containing the decoded string.
- Throws:
TextParseException- The input was invalid.IOException- An I/O error occurred.
-
exception
Creates an exception which includes the current state in the error message- Parameters:
s- The error message to include.- Returns:
- The exception to be thrown
-
close
public void close()Closes any files opened by this tokenizer.- Specified by:
closein interfaceAutoCloseable
-