public class JsonStreamWriter extends Object implements StreamWriter
StreamWriter
for handling JSON.Constructor and Description |
---|
JsonStreamWriter(OutputStream os)
Creates a
StreamWriter for handling JSON, with a null
prefix and postfix. |
JsonStreamWriter(OutputStream os,
String prefix,
String postfix)
Creates a
StreamWriter for handling JSON. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the
OutputStream associated with this object. |
String |
getPostfix()
Returns a string of data that must appear at the end of the data stream.
|
String |
getPrefix()
Returns a string of data that must appear at the start of the data
stream.
|
void |
writeAttribute(String name,
Boolean value)
Writes a
Boolean attribute with the specified name and
value . |
void |
writeAttribute(String name,
String value)
Writes a
String attribute with the specified name and
value . |
void |
writeEndArray()
Writes the end of an array.
|
void |
writeEndDocument()
Writes the data that is compulsory to appear at the end of the data
structure.
|
void |
writeEndObject()
Writes the end of an object.
|
void |
writeStartArray(String element)
Writes the start of an array, with the specified
name . |
void |
writeStartDocument()
Writes the data that is compulsory to appear at the start of the data
structure.
|
void |
writeStartObject(String element)
Writes the start of a new object, with the specified
name . |
public JsonStreamWriter(OutputStream os, String prefix, String postfix)
StreamWriter
for handling JSON.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.public JsonStreamWriter(OutputStream os)
StreamWriter
for handling JSON, with a null
prefix and postfix.os
- The OutputStream to write to.public String getPostfix()
StreamWriter
getPostfix
in interface StreamWriter
public String getPrefix()
StreamWriter
getPrefix
in interface StreamWriter
public void writeStartDocument() throws javax.json.stream.JsonGenerationException, IOException
StreamWriter
<?xml version="1.0" ?>
writeStartDocument
in interface StreamWriter
javax.json.stream.JsonGenerationException
IOException
public void writeEndDocument() throws javax.json.stream.JsonGenerationException, IOException
StreamWriter
writeEndDocument
in interface StreamWriter
javax.json.stream.JsonGenerationException
IOException
public void writeStartObject(String element) throws javax.json.stream.JsonGenerationException
StreamWriter
name
.writeStartObject
in interface StreamWriter
element
- The name of the objectjavax.json.stream.JsonGenerationException
public void writeEndObject() throws javax.json.stream.JsonGenerationException
StreamWriter
writeEndObject
in interface StreamWriter
javax.json.stream.JsonGenerationException
public void writeAttribute(String name, String value) throws javax.json.stream.JsonGenerationException
StreamWriter
String
attribute with the specified name
and
value
. E.g. for JSON this will write: "name":"value"
.writeAttribute
in interface StreamWriter
name
- The name of the attributevalue
- The value of the attributejavax.json.stream.JsonGenerationException
public void writeAttribute(String name, Boolean value) throws javax.json.stream.JsonGenerationException
StreamWriter
Boolean
attribute with the specified name
and
value
. E.g. for JSON this will write: "name":true/false
.writeAttribute
in interface StreamWriter
name
- The name of the attributevalue
- The value of the attributejavax.json.stream.JsonGenerationException
public void close() throws javax.json.stream.JsonGenerationException
StreamWriter
OutputStream
associated with this object. Some
OutputStreams require closing before any data will be written.close
in interface StreamWriter
javax.json.stream.JsonGenerationException
public void writeStartArray(String element) throws Exception
StreamWriter
name
. If the
data structure doesn't support arrays, this method will do nothing.writeStartArray
in interface StreamWriter
element
- The name of the arrayException
- Any exception thrown while writing. E.g. for JSON this
might be a
JsonGenerationException
.public void writeEndArray() throws Exception
StreamWriter
writeEndArray
in interface StreamWriter
Exception
- Any exception thrown while writing. E.g. for JSON this
might be a
JsonGenerationException
.Copyright © 2021. All rights reserved.