abk.json
Class AJsonTokener

java.lang.Object
  extended by abk.json.AJsonTokener

public class AJsonTokener
extends Object

AJsonTokener coge una cadena de texto y extrae los caracteres y tokens de ella. A partir de él se puede construir un AJsonBean o un AJsonArray.

Version:
2019-08-15

Field Summary
private  long character
          Current read character position on the current line.
private  long characterPreviousLine
          The number of characters read in the previous line.
private  boolean eof
          Flag to indicate if the end of the input has been found.
private  long index
          Current read index of the input.
private  long line
          Current line of the input.
private  char previous
          Previous character read from the input.
private  Reader reader
          Reader for the input.
private  boolean usePrevious
          Flag to indicate that a previous character was requested.
 
Constructor Summary
AJsonTokener(Reader reader)
          Construct a AJsonTokener from a Reader.
AJsonTokener(String s)
          Construct a AJsonTokener from a string.
 
Method Summary
private  void addKey(AJsonBean jean, String key)
           
 void back()
          Back up one character.
private  void decrementIndexes()
          Decrements the indexes for the back() method based on the previous character read.
 boolean end()
          Comprueba si se ha alcanzado el final de la entrada en proceso
private  void incrementIndexes(int c)
          Increments the internal indexes according to the previous character read and the character passed as the current character.
 char next()
          Get the next character in the source string.
 String next(int n)
          Get the next n characters.
 char nextClean()
          Get the next char in the string, skipping whitespace.
private  String nextKey()
          Devuelve el siguiente token como una cadena de texto para ser usada como la clave de la siguiente propiedad del objeto.
 String nextString(char quote)
          Return the characters up to the next close quote character.
 AJsonElement nextValue()
          Get the next value.
static AJsonElement stringToValue(String string)
          Try to convert a string into a number, boolean, or null.
 ParseException syntaxError(AMessageKey msg)
          Make a ParseException to signal a syntax error.
 ParseException syntaxError(AMessageKey msg, Throwable causedBy)
          Make a ParseException to signal a syntax error.
 AJsonArray toJsonArray()
          Construye un objeto AJsonArray a partir de un AJsonTokener.
 AJsonBean toJsonBean()
          Construye un objeto AJsonBean desde un AJsonTokener.
 String toString()
          Make a printable string of this AJsonTokener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

character

private long character
Current read character position on the current line.


eof

private boolean eof
Flag to indicate if the end of the input has been found.


index

private long index
Current read index of the input.


line

private long line
Current line of the input.


previous

private char previous
Previous character read from the input.


reader

private final Reader reader
Reader for the input.


usePrevious

private boolean usePrevious
Flag to indicate that a previous character was requested.


characterPreviousLine

private long characterPreviousLine
The number of characters read in the previous line.

Constructor Detail

AJsonTokener

public AJsonTokener(Reader reader)
Construct a AJsonTokener from a Reader. The caller must close the Reader.

Parameters:
reader - A reader.

AJsonTokener

public AJsonTokener(String s)
Construct a AJsonTokener from a string.

Parameters:
s - A source string.
Method Detail

back

public void back()
Back up one character. This provides a sort of lookahead capability, so that you can test for a digit or letter before attempting to parse the next number or identifier.

Throws:
UnsupportedOperationException - Thrown if trying to step back more than 1 step or if already at the start of the string

decrementIndexes

private void decrementIndexes()
Decrements the indexes for the back() method based on the previous character read.


end

public boolean end()
Comprueba si se ha alcanzado el final de la entrada en proceso

Returns:
true si estamos al final del fichero y no tenemos pendiente volver atrĂ¡s.

next

public char next()
Get the next character in the source string.

Returns:
The next character, or 0 if past the end of the source string.
Throws:
IllegalStateException - Thrown if there is an error reading the source string.

incrementIndexes

private void incrementIndexes(int c)
Increments the internal indexes according to the previous character read and the character passed as the current character.

Parameters:
c - the current character read.

next

public String next(int n)
            throws ParseException
Get the next n characters.

Parameters:
n - The number of characters to take.
Returns:
A string of n characters.
Throws:
ParseException - Substring bounds error if there are not n characters remaining in the source string.

nextClean

public char nextClean()
Get the next char in the string, skipping whitespace.

Returns:
A character, or 0 if there are no more characters.
Throws:
IllegalStateException - Thrown if there is an error reading the source string.

nextString

public String nextString(char quote)
                  throws ParseException
Return the characters up to the next close quote character. Backslash processing is done. The formal JSON format does not allow strings in single quotes, but an implementation is allowed to accept them.

Parameters:
quote - The quoting character, either " (double quote) or ' (single quote).
Returns:
A String.
Throws:
ParseException - Unterminated string.

nextValue

public AJsonElement nextValue()
                       throws ParseException
Get the next value. The value can be a Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.

Returns:
An object.
Throws:
ParseException - If syntax error.
IllegalStateException - Thrown if there is an error reading the source string.

syntaxError

public ParseException syntaxError(AMessageKey msg)
Make a ParseException to signal a syntax error.

Parameters:
msg - The error message.
Returns:
A ParseException object, suitable for throwing

syntaxError

public ParseException syntaxError(AMessageKey msg,
                                  Throwable causedBy)
Make a ParseException to signal a syntax error.

Parameters:
msg - The error message.
causedBy - The throwable that caused the error.
Returns:
A ParseException object, suitable for throwing

toString

public String toString()
Make a printable string of this AJsonTokener.

Overrides:
toString in class Object
Returns:
" at {index} [character {character} line {line}]"

stringToValue

public static final AJsonElement stringToValue(String string)
Try to convert a string into a number, boolean, or null. If the string can't be converted, return the string.

Parameters:
string - A String.
Returns:
A simple JSON value.

nextKey

private String nextKey()
                throws ParseException
Devuelve el siguiente token como una cadena de texto para ser usada como la clave de la siguiente propiedad del objeto.

Returns:
Nueva clave.
Throws:
ParseException - si el siguiente token no se corresponde con un AJsonString.

toJsonBean

public AJsonBean toJsonBean()
                     throws ParseException
Construye un objeto AJsonBean desde un AJsonTokener.

Returns:
Objeto JSON creado.
Throws:
ParseException - si hay un error de sintaxis o una clave duplicada.

addKey

private void addKey(AJsonBean jean,
                    String key)
             throws ParseException
Throws:
ParseException

toJsonArray

public AJsonArray toJsonArray()
                       throws ParseException
Construye un objeto AJsonArray a partir de un AJsonTokener.

Returns:
Objeto creado.
Throws:
ParseException - Si hay un error de sintaxis.


Copyright © 2024. All rights reserved.