Class JsonReader

java.lang.Object
de.linusdev.data.parser.JsonReader

public class JsonReader extends Object
A Reader like class, that makes reading a json-object much easier.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
    pushBack(int i)
    Pushes given character back, so the next read(ParseTracker) call will read it.
    The push back buffer supports only a single character, if the buffer is not empty, it will be overwritten, and the old character will be lost.
    int
    read(@NotNull de.linusdev.lutils.other.parser.ParseTracker tracker)
    reads to the next character, which integer value is not below 33.
    @NotNull String
    readMultiLineComment(@NotNull de.linusdev.lutils.other.parser.ParseTracker tracker)
     
    int
    readNextChar(@NotNull de.linusdev.lutils.other.parser.ParseTracker tracker)
    Reads the next char without skipping anything
    readString(boolean allowNewLine, @NotNull de.linusdev.lutils.other.parser.ParseTracker tracker)
    reads until a '"' is read.
    @NotNull String
    readToEOL(@NotNull de.linusdev.lutils.other.parser.ParseTracker tracker)
    Reads until EOL or EOF.
    @Nullable Object
    readValue(@NotNull de.linusdev.lutils.other.parser.ParseTracker tracker, boolean allowToken)
    reads until 44, 125, 93, 47 is read.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JsonReader

      public JsonReader(Reader reader)
  • Method Details

    • pushBack

      public void pushBack(int i)
      Pushes given character back, so the next read(ParseTracker) call will read it.
      The push back buffer supports only a single character, if the buffer is not empty, it will be overwritten, and the old character will be lost.
      Parameters:
      i - character to push back
    • read

      public int read(@NotNull @NotNull de.linusdev.lutils.other.parser.ParseTracker tracker) throws IOException
      reads to the next character, which integer value is not below 33.
      Returns:
      next character or -1 if end of the stream is reached.
      Throws:
      IOException
    • readNextChar

      public int readNextChar(@NotNull @NotNull de.linusdev.lutils.other.parser.ParseTracker tracker) throws IOException
      Reads the next char without skipping anything
      Parameters:
      tracker - to track lines
      Returns:
      the next char or -1 if the end has been reached.
      Throws:
      IOException - while reading
    • readToEOL

      @NotNull public @NotNull String readToEOL(@NotNull @NotNull de.linusdev.lutils.other.parser.ParseTracker tracker) throws IOException
      Reads until EOL or EOF.
      Parameters:
      tracker - ParseTracker
      Returns:
      read value, may be Boolean, null or Number
      Throws:
      IOException - while reading or parsing
    • readMultiLineComment

      @NotNull public @NotNull String readMultiLineComment(@NotNull @NotNull de.linusdev.lutils.other.parser.ParseTracker tracker) throws IOException, de.linusdev.lutils.other.parser.UnexpectedEndException
      Throws:
      IOException
      de.linusdev.lutils.other.parser.UnexpectedEndException
    • readValue

      @Nullable public @Nullable Object readValue(@NotNull @NotNull de.linusdev.lutils.other.parser.ParseTracker tracker, boolean allowToken) throws IOException, de.linusdev.lutils.other.parser.ParseException
      reads until 44, 125, 93, 47 is read. the last char will be pushed back.
      Parameters:
      tracker - ParseTracker
      allowToken - whether JsonParser.setIdentifyNumberValues(boolean) is set to true.
      Returns:
      read value, may be Boolean, null or Number
      Throws:
      IOException - while reading or parsing
      de.linusdev.lutils.other.parser.ParseException - while reading or parsing
    • readString

      public String readString(boolean allowNewLine, @NotNull @NotNull de.linusdev.lutils.other.parser.ParseTracker tracker) throws IOException, de.linusdev.lutils.other.parser.ParseException
      reads until a '"' is read.
      Parameters:
      allowNewLine - whether to allow a line break while reading
      tracker - ParseTracker
      Returns:
      read String
      Throws:
      IOException - while reading or parsing
      de.linusdev.lutils.other.parser.ParseException - while reading or parsing
    • close

      public void close()