public class Tokenizer
extends net.morimekta.util.io.LineBufferedReader
Modifier and Type | Class and Description |
---|---|
static interface |
Tokenizer.TokenValidator |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUFFER_SIZE |
Constructor and Description |
---|
Tokenizer(InputStream in)
Create a JSON tokenizer that reads from the input steam.
|
Tokenizer(InputStream in,
int bufferSize)
Create a JSON tokenizer that reads from the input steam.
|
Tokenizer(Reader in,
int bufferSize,
boolean preLoadAll)
Create a tokenizer that will read everything from the input stream and
handle it as a single multi-line buffer.
|
Modifier and Type | Method and Description |
---|---|
protected TokenizerException |
eof(String format,
Object... params) |
Token |
expect(String expected)
Expect a new JSON token on the stream.
|
Token |
expect(String expected,
Tokenizer.TokenValidator validator)
Expect at a valid token containing anything.
|
Token |
expectIdentifier(String message) |
Token |
expectInteger(String message) |
Token |
expectLiteral(String message) |
char |
expectSymbol(String expected,
char... symbols) |
protected TokenizerException |
failure(int startLineNo,
int startLinePos,
int length,
String format,
Object... params) |
protected TokenizerException |
failure(String format,
Object... params) |
TokenizerException |
failure(Token token,
String message,
Object... params) |
boolean |
hasNext()
Whether there is another token on the stream.
|
Token |
next()
Returns the next token on the stream, or null if there are no more JSON
tokens on the stream.
|
protected Token |
nextSymbol() |
Token |
peek()
Return the next token or throw an exception.
|
Token |
peek(String message)
Return the next token or throw an exception.
|
String |
readBinary(char end)
Read the 'content' of encoded binary.
|
public static final int DEFAULT_BUFFER_SIZE
public Tokenizer(InputStream in)
in
- Input stream to parse from.public Tokenizer(InputStream in, int bufferSize)
in
- Input stream to parse from.bufferSize
- The size of the char buffer. Default is 2048 chars
(4096 bytes).public Tokenizer(Reader in, int bufferSize, boolean preLoadAll)
in
- Reader of content to parse.bufferSize
- The size of the char buffer. Default is 2048 chars
(4096 bytes).preLoadAll
- Load all content up front. Handy for config and thrift
program files.@Nonnull public Token expect(@Nonnull String expected) throws IOException
expected
- Message to add to exception if there are no more JSON
tokens on the stream.IOException
- If unable to read from stream.public Token expect(@Nonnull String expected, @Nonnull Tokenizer.TokenValidator validator) throws IOException
expected
- The expectation description.validator
- Validator callback.IOException
- If failed to read a token.public char expectSymbol(@Nonnull String expected, char... symbols) throws IOException
expected
- Message to add to exception if there are no more JSON
tokens on the stream.symbols
- List of symbol characters to expect.IOException
- If unable to read from stream.public Token expectIdentifier(@Nonnull String message) throws IOException
IOException
@Nonnull public Token expectInteger(String message) throws IOException
IOException
@Nonnull public Token expectLiteral(String message) throws IOException
IOException
public boolean hasNext() throws IOException
IOException
- If unable to read from stream.public String readBinary(char end) throws IOException
end
- The char that ends the binary content.TokenizerException
- On illegal content.IOException
public Token peek() throws IOException
IOException
- If unable to read from stream.@Nonnull public Token peek(String message) throws IOException
message
- Message to add to exception if there are no more JSON
tokens on the stream.IOException
- If unable to read from stream.@Nullable public Token next() throws IOException
IOException
- If unable to read from stream.@Nonnull protected Token nextSymbol() throws IOException
IOException
@Nonnull public TokenizerException failure(Token token, String message, Object... params)
@Nonnull protected final TokenizerException failure(int startLineNo, int startLinePos, int length, String format, Object... params)
@Nonnull protected final TokenizerException eof(String format, Object... params)
@Nonnull protected TokenizerException failure(String format, Object... params)
Copyright © 2015–2018 morimekta.net. All rights reserved.