Class JsonStreamWriter

    • Constructor Detail

      • JsonStreamWriter

        public JsonStreamWriter​(OutputStream os,
                                String prefix,
                                String postfix)
        Creates a StreamWriter for handling JSON.
        Parameters:
        os - The OutputStream to write to.
        prefix - Any data that needs writing at the start of the stream.
        postfix - Any data that needs writing at the end of the stream.
      • JsonStreamWriter

        public JsonStreamWriter​(OutputStream os)
        Creates a StreamWriter for handling JSON, with a null prefix and postfix.
        Parameters:
        os - The OutputStream to write to.
    • Method Detail

      • getPostfix

        public String getPostfix()
        Description copied from interface: StreamWriter
        Returns a string of data that must appear at the end of the data stream.
        Specified by:
        getPostfix in interface StreamWriter
        Returns:
        postfix
      • getPrefix

        public String getPrefix()
        Description copied from interface: StreamWriter
        Returns a string of data that must appear at the start of the data stream. E.g. a namespace declaration.
        Specified by:
        getPrefix in interface StreamWriter
        Returns:
        prefix
      • writeStartDocument

        public void writeStartDocument()
                                throws jakarta.json.stream.JsonGenerationException,
                                       IOException
        Description copied from interface: StreamWriter
        Writes the data that is compulsory to appear at the start of the data structure.
        E.g. for XML this might be: <?xml version="1.0" ?>
        Specified by:
        writeStartDocument in interface StreamWriter
        Throws:
        jakarta.json.stream.JsonGenerationException
        IOException
      • writeEndDocument

        public void writeEndDocument()
                              throws jakarta.json.stream.JsonGenerationException,
                                     IOException
        Description copied from interface: StreamWriter
        Writes the data that is compulsory to appear at the end of the data structure.
        Specified by:
        writeEndDocument in interface StreamWriter
        Throws:
        jakarta.json.stream.JsonGenerationException
        IOException
      • writeStartObject

        public void writeStartObject​(String element)
                              throws jakarta.json.stream.JsonGenerationException
        Description copied from interface: StreamWriter
        Writes the start of a new object, with the specified name.
        Specified by:
        writeStartObject in interface StreamWriter
        Parameters:
        element - The name of the object
        Throws:
        jakarta.json.stream.JsonGenerationException
      • writeEndObject

        public void writeEndObject()
                            throws jakarta.json.stream.JsonGenerationException
        Description copied from interface: StreamWriter
        Writes the end of an object. An object must have been started, or an exception will be thrown.
        Specified by:
        writeEndObject in interface StreamWriter
        Throws:
        jakarta.json.stream.JsonGenerationException
      • writeAttribute

        public void writeAttribute​(String name,
                                   String value)
                            throws jakarta.json.stream.JsonGenerationException
        Description copied from interface: StreamWriter
        Writes a String attribute with the specified name and value. E.g. for JSON this will write: "name":"value".
        Specified by:
        writeAttribute in interface StreamWriter
        Parameters:
        name - The name of the attribute
        value - The value of the attribute
        Throws:
        jakarta.json.stream.JsonGenerationException
      • writeAttribute

        public void writeAttribute​(String name,
                                   Boolean value)
                            throws jakarta.json.stream.JsonGenerationException
        Description copied from interface: StreamWriter
        Writes a Boolean attribute with the specified name and value. E.g. for JSON this will write: "name":true/false.
        Specified by:
        writeAttribute in interface StreamWriter
        Parameters:
        name - The name of the attribute
        value - The value of the attribute
        Throws:
        jakarta.json.stream.JsonGenerationException
      • close

        public void close()
                   throws jakarta.json.stream.JsonGenerationException
        Description copied from interface: StreamWriter
        Closes the OutputStream associated with this object. Some OutputStreams require closing before any data will be written.
        Specified by:
        close in interface StreamWriter
        Throws:
        jakarta.json.stream.JsonGenerationException
      • writeStartArray

        public void writeStartArray​(String element)
                             throws Exception
        Description copied from interface: StreamWriter
        Writes the start of an array, with the specified name. If the data structure doesn't support arrays, this method will do nothing.
        Specified by:
        writeStartArray in interface StreamWriter
        Parameters:
        element - The name of the array
        Throws:
        Exception - Any exception thrown while writing. E.g. for JSON this might be a JsonGenerationException.
      • writeEndArray

        public void writeEndArray()
                           throws Exception
        Description copied from interface: StreamWriter
        Writes the end of an array. An array must have been started, or an exception will be thrown. If the data structure doesn't support arrays, this method will do nothing.
        Specified by:
        writeEndArray in interface StreamWriter
        Throws:
        Exception - Any exception thrown while writing. E.g. for JSON this might be a JsonGenerationException.