Class JsonStreamReader


  • public class JsonStreamReader
    extends Object
    This class can read atomic JSON tokens from a stream. After construction the reader is positioned before the first token. Call moveNext() to move to the first token. Then you can get the current token with getToken().
    • Constructor Detail

      • JsonStreamReader

        public JsonStreamReader​(InputStream input)
        Constructs a new JSON stream reader. It reads UTF-8 characters from the specified input stream.
        Parameters:
        input - the input stream
      • JsonStreamReader

        public JsonStreamReader​(Reader reader)
        Constructs a new JSON stream reader.
        Parameters:
        reader - the underlying reader
    • Method Detail

      • close

        public void close()
                   throws IOException
        Closes this reader and the underlying reader.
        Throws:
        IOException - if the underlying reader can't be closed
      • setIsStringAtomic

        public void setIsStringAtomic​(boolean isStringAtomic)
        Sets whether a string is an atomic token. If this is true (default), you will receive token STRING. Otherwise you will receive tokens START_STRING, STRING_CHARACTER and END_STRING. Reading a string as an atomic token is much more efficient, but you may want to receive separate character tokens for long strings.
        Parameters:
        isStringAtomic - true if a string is an atomic token (default), false otherwise
      • isStringAtomic

        public boolean isStringAtomic()
        Returns whether a string is an atomic token. If this is true (default), you will receive token STRING. Otherwise you will receive tokens START_STRING, STRING_CHARACTER and END_STRING. Reading a string as an atomic token is more efficient, but you may want to receive separate character tokens for very long strings.
        Returns:
        true if a string is an atomic token (default), false otherwise
      • getDocumentLine

        public int getDocumentLine()
        Returns the current line number in the document. The first line is 1. If the reader is positioned at a token, then the document position is at the end of that token.
        Returns:
        the current line number
      • getDocumentLinePos

        public int getDocumentLinePos()
        Returns the current character number in the current line in the document. The first character is 1. If the reader is positioned at a token, then the document position is at the end of that token.
        Returns:
        the current character number
      • getTokenStartLine

        public int getTokenStartLine()
        Returns the line number in the document where the current token starts. The first line is 1. If the reader is before the first token, then this method returns 1. If the reader is after the last token, then this method return the line at the end of the document.
        Returns:
        the line number where the current token starts
      • getTokenStartLinePos

        public int getTokenStartLinePos()
        Returns the character number in the line in the document where the current token starts. The first character is 1. If the reader is before the first token, then this method returns 1. If the reader is after the last token, then this method return the line at the end of the document.
        Returns:
        the character number where the current token starts
      • moveNext

        public boolean moveNext()
                         throws JsonParseException,
                                IOException
        Moves to the next token. The first time you call this method, it moves to the first token. If the end of the stream is reached and the complete document is valid, this method returns false, meaning there are no more tokens.
        Returns:
        true if there is another token, false if the end of the document
        Throws:
        JsonParseException - if the JSON content is invalid
        IOException - if a reading error occurs
      • getToken

        public JsonAtomicToken getToken()
        Returns the current token. If the reader is positioned before the first token or after the last token, this method returns null.
        Returns:
        the current token or null