public final class JSONLexer
extends java.lang.Object
JSONLexer
takes a source stream and extracts characters and tokens
from it. It does not perform any sanity checks on the order that
tokens appear. It is used by JSONStreamReader
class to tokenise
JSON source streams.Modifier and Type | Class and Description |
---|---|
static class |
JSONLexer.Token
Tokens that can be identified with at most one character lookahead.
|
Constructor and Description |
---|
JSONLexer(java.io.InputStream inputStream,
java.nio.charset.Charset charset)
Construct a
JSONLexer from an InputStream and a supplied
Charset . |
JSONLexer(java.io.Reader reader)
Construct a
JSONLexer from a Reader . |
JSONLexer(java.lang.String s)
Construct a
JSONLexer from a String . |
Modifier and Type | Method and Description |
---|---|
boolean |
nextNumber(java.lang.Appendable sb)
Parse a number strictly according to the JSON specification.
|
boolean |
nextNumber(java.lang.Appendable sb,
int mDigits,
int eDigits)
Parse a number strictly according to the JSON specification.
|
<T extends java.lang.Appendable> |
nextString(T sb)
Return the characters up to the next close quote character.
|
<T extends java.lang.Appendable> |
nextString(T sb,
long maxLen)
Return the characters up to the next close quote character.
|
JSONLexer.Token |
nextTokenType()
Get the type of the next token in the stream, skipping whitespace.
|
ParsePosition |
parsePosition()
Indicates the current position of the scanner.
|
void |
skipNumber()
Skip a number strictly according to the JSON specification.
|
void |
skipString()
Skip the characters up to the next close quote character.
|
java.lang.String |
toString()
Make a printable string of this
JSONLexer . |
public JSONLexer(java.io.Reader reader)
JSONLexer
from a Reader
.reader
- A reader.public JSONLexer(java.io.InputStream inputStream, java.nio.charset.Charset charset)
JSONLexer
from an InputStream
and a supplied
Charset
.inputStream
- the input stream containing the JSON datacharset
- the character set with which to interpret the
input streampublic JSONLexer(java.lang.String s)
JSONLexer
from a String
.s
- A source string.public JSONLexer.Token nextTokenType() throws JSONException
JSONException
public <T extends java.lang.Appendable> T nextString(T sb) throws JSONException
T
- a subtype of Appendable
, returned to the caller
for chaining purposessb
- the Appendable to which the String value is appendedJSONException
- Unterminated string.public <T extends java.lang.Appendable> T nextString(T sb, long maxLen) throws JSONException
Most practical parsers will limit the length of a string to one
expressible by a String
object, or writable to a File
.
T
- a subtype of Appendable
, returned to the caller
for chaining purposessb
- the Appendable to which the String value is appendedmaxLen
- the maximum length of the decoded string value,
<= 0 to limit to Long.MAX_VALUEJSONException
- Unterminated string.public void skipString() throws JSONException
JSONException
- Unterminated string.public boolean nextNumber(java.lang.Appendable sb) throws JSONException
sb
- The Appendable to which the parsed character sequence is
appendedtrue
if the number is a floating point value, otherwise
false
to indicate an integer valueJSONException
public boolean nextNumber(java.lang.Appendable sb, int mDigits, int eDigits) throws JSONException
Most practical JSON parsers limit the number values to those
expressible by Long
or Double
values.
sb
- The Appendable to which the parsed character sequence is
appendedmDigits
- maximum number of mantissa digits to be parsed,
<= 0 to limit to Integer.MAX_VALUE
eDigits
- maximum number of exponent digits to be parsed,
0 for no exponent, or < 0 to limit to
Integer.MAX_VALUE
true
if the number is a floating point value, otherwise
false
to indicate an integer valueJSONException
public void skipNumber() throws JSONException
JSONException
public ParsePosition parsePosition()
ParsePosition
representing the current location of
the scannerpublic java.lang.String toString()
JSONLexer
.toString
in class java.lang.Object