Class SmileParser

java.lang.Object
io.helidon.json.JsonParserBase
io.helidon.json.smile.SmileParser
All Implemented Interfaces:
JsonParser

public final class SmileParser extends JsonParserBase
Smile binary JSON parser implementation.

This class is not thread safe.

  • Method Details

    • create

      public static JsonParser create(byte[] json)
      Create a Smile parser from in-memory Smile-encoded bytes.
      Parameters:
      json - Smile binary data
      Returns:
      a new Smile parser instance
    • create

      public static JsonParser create(InputStream inputStream)
      Create a Smile parser from an input stream.
      Parameters:
      inputStream - stream containing Smile data
      Returns:
      a new Smile parser instance
    • create

      public static JsonParser create(InputStream inputStream, int bufferSize)
      Create a Smile parser from an input stream.
      Parameters:
      inputStream - stream containing Smile data
      bufferSize - size of the internal streaming buffer
      Returns:
      a new Smile parser instance
    • hasNext

      public boolean hasNext()
      Description copied from interface: JsonParser
      Checks if there are more tokens available in the JSON stream.

      This method should be called before attempting to read any tokens to avoid exceptions when reaching the end of the JSON content.

      Returns:
      true if more tokens are available, false if end of stream is reached
    • nextToken

      public byte nextToken()
      Description copied from interface: JsonParser
      Reads the next JSON token without consuming it.

      This method advances the parser to the next significant token (skipping whitespace) but does not consume it. The token can then be read using appropriate read methods.

      Returns:
      the byte value of the next token
    • currentByte

      public byte currentByte()
      Description copied from interface: JsonParser
      Return the last byte that was read from the stream.

      This method can be used to inspect the current parser position without advancing it. Useful for debugging or conditional parsing logic.

      Returns:
      the last byte read, or 0 if no bytes have been read yet
    • readJsonValue

      public JsonValue readJsonValue()
      Description copied from interface: JsonParser
      Reads a complete JSON value from the current position.

      This method parses and returns the next complete JSON value (object, array, string, number, boolean, or null) from the current parser position.

      Specified by:
      readJsonValue in interface JsonParser
      Overrides:
      readJsonValue in class JsonParserBase
      Returns:
      the parsed JsonValue
      See Also:
    • readJsonObject

      public JsonObject readJsonObject()
      Description copied from interface: JsonParser
      Reads a JSON object from the current position.

      This method expects the next token to be an object start ('{') and parses the complete object including all nested values.

      Specified by:
      readJsonObject in interface JsonParser
      Overrides:
      readJsonObject in class JsonParserBase
      Returns:
      the parsed JsonObject
      See Also:
    • readJsonArray

      public JsonArray readJsonArray()
      Description copied from interface: JsonParser
      Reads a JSON array from the current position.

      This method expects the next token to be an array start ('[') and parses the complete array including all nested values.

      Specified by:
      readJsonArray in interface JsonParser
      Overrides:
      readJsonArray in class JsonParserBase
      Returns:
      the parsed JsonArray
      See Also:
    • readJsonString

      public JsonString readJsonString()
      Description copied from interface: JsonParser
      Reads a JSON string value from the current position.

      This method expects the next token to be a string and returns the parsed string value.

      Returns:
      the parsed JsonString
      See Also:
    • readJsonNumber

      public JsonNumber readJsonNumber()
      Description copied from interface: JsonParser
      Reads a JSON number value from the current position.

      This method expects the next token to be a number and returns the parsed numeric value.

      Returns:
      the parsed JsonNumber
      See Also:
    • readString

      public String readString()
      Description copied from interface: JsonParser
      Reads a string value from the current position. The value has to start and end with the ".

      This method expects the next token to be a string and returns the string content as a Java String.

      Returns:
      the string value
    • readStringAsHash

      public int readStringAsHash()
      Description copied from interface: JsonParser
      Reads a string value and returns its FNV-1a hash.

      This method is optimized for performance when only string comparison is needed, avoiding string object allocation.

      Returns:
      the hash of the string value
    • readChar

      public char readChar()
      Description copied from interface: JsonParser
      Reads a char value from the current position. The value has to start and end with the ".

      This method expects the next token to be a string and returns the string content as a Java char value. It has to be one character.

      Returns:
      the char value
    • readBoolean

      public boolean readBoolean()
      Description copied from interface: JsonParser
      Reads a boolean value from the current position.

      This method expects the next token to be a boolean (true/false) and returns the corresponding Java boolean value.

      Returns:
      the boolean value
    • readByte

      public byte readByte()
      Description copied from interface: JsonParser
      Reads a numeric value as a byte.

      This method expects the next token to be a number and converts it to a byte.

      Returns:
      the byte value
    • readShort

      public short readShort()
      Description copied from interface: JsonParser
      Reads a numeric value as a short.

      This method expects the next token to be a number and converts it to a short.

      Returns:
      the short value
    • readInt

      public int readInt()
      Description copied from interface: JsonParser
      Reads a numeric value as an int.

      This method expects the next token to be a number and converts it to an int.

      Returns:
      the int value
    • readLong

      public long readLong()
      Description copied from interface: JsonParser
      Reads a numeric value as a long.

      This method expects the next token to be a number and converts it to a long.

      Returns:
      the long value
    • readFloat

      public float readFloat()
      Description copied from interface: JsonParser
      Reads a numeric value as a float.

      This method expects the next token to be a number and converts it to a float. It also accepts quoted NaN, Infinity, and -Infinity values emitted by the JSON generator.

      Returns:
      the float value
    • readDouble

      public double readDouble()
      Description copied from interface: JsonParser
      Reads a numeric value as a double.

      This method expects the next token to be a number and converts it to a double. It also accepts quoted NaN, Infinity, and -Infinity values emitted by the JSON generator.

      Returns:
      the double value
    • readBigInteger

      public BigInteger readBigInteger()
      Description copied from interface: JsonParser
      Reads a numeric value as BigInteger.
      Returns:
      the big integer value
    • readBigDecimal

      public BigDecimal readBigDecimal()
      Description copied from interface: JsonParser
      Reads a numeric value as BigDecimal.
      Returns:
      the big decimal value
    • readBinary

      public byte[] readBinary()
      Description copied from interface: JsonParser
      Reads a binary value.
      Returns:
      the decoded binary value
    • checkNull

      public boolean checkNull()
      Description copied from interface: JsonParser
      Checks if the current position contains a null value.

      This method peeks at the next value to determine if it's null and advances the parser position if it is.

      Returns:
      true if the next value is null, false otherwise
    • skip

      public void skip()
      Description copied from interface: JsonParser
      Skips the current JSON value without parsing it.

      This method advances the parser past the current value (object, array, string, number, boolean, or null) without constructing Java objects. Useful for skipping unwanted parts of large JSON documents.

    • createException

      public JsonException createException(String message)
      Description copied from interface: JsonParser
      Create a JsonException with the given message.
      Parameters:
      message - the exception message
      Returns:
      a JsonException
    • createException

      public JsonException createException(String message, Exception e)
      Description copied from interface: JsonParser
      Create a JsonException with the given message and cause.
      Parameters:
      message - the exception message
      e - the cause
      Returns:
      a JsonException
    • mark

      public void mark()
      Description copied from interface: JsonParser
      Marks the current position in the JSON.

      This method saves the current parser position so it can be returned to later using JsonParser.resetToMark(). Useful for backtracking during parsing operations.

    • clearMark

      public void clearMark()
      Description copied from interface: JsonParser
      Clears the current mark.

      This method clears any previously set mark. Should be always called when backtracking is no longer needed.

    • resetToMark

      public void resetToMark()
      Description copied from interface: JsonParser
      Resets the parser position to the previously marked position.

      This method restores the parser to the position that was saved with JsonParser.mark(). Allows for backtracking to a previous parsing state.