Class JSONObjectReader

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    @ThreadSafety(level=NOT_THREADSAFE)
    public final class JSONObjectReader
    extends java.lang.Object
    implements java.io.Closeable
    This class provides a mechanism for reading JSON objects from an input stream. It assumes that any non-ASCII data that may be read from the input stream is encoded as UTF-8.
    • Constructor Summary

      Constructors 
      Constructor Description
      JSONObjectReader​(java.io.InputStream inputStream)
      Creates a new JSON object reader that will read objects from the provided input stream.
      JSONObjectReader​(java.io.InputStream inputStream, boolean bufferInputStream)
      Creates a new JSON object reader that will read objects from the provided input stream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes this JSON object reader and the underlying input stream.
      JSONObject readObject()
      Reads the next JSON object from the input stream.
      • Methods inherited from class java.lang.Object

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

      • JSONObjectReader

        public JSONObjectReader​(java.io.InputStream inputStream)
        Creates a new JSON object reader that will read objects from the provided input stream.
        Parameters:
        inputStream - The input stream from which the data should be read.
      • JSONObjectReader

        public JSONObjectReader​(java.io.InputStream inputStream,
                                boolean bufferInputStream)
        Creates a new JSON object reader that will read objects from the provided input stream.
        Parameters:
        inputStream - The input stream from which the data should be read.
        bufferInputStream - Indicates whether to buffer the input stream. This should be false if the input stream could be used for any purpose other than reading JSON objects after one or more objects are read.
    • Method Detail

      • readObject

        public JSONObject readObject()
                              throws java.io.IOException,
                                     JSONException
        Reads the next JSON object from the input stream.
        Returns:
        The JSON object that was read, or null if the end of the end of the stream has been reached..
        Throws:
        java.io.IOException - If a problem is encountered while reading from the input stream.
        JSONException - If the data read
      • close

        public void close()
                   throws java.io.IOException
        Closes this JSON object reader and the underlying input stream.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException - If a problem is encountered while closing the underlying input stream.