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()
StreamWritergetPostfix in interface StreamWriterpublic String getPrefix()
StreamWritergetPrefix in interface StreamWriterpublic void writeStartDocument()
throws javax.json.stream.JsonGenerationException,
IOException
StreamWriter<?xml version="1.0" ?>writeStartDocument in interface StreamWriterjavax.json.stream.JsonGenerationExceptionIOExceptionpublic void writeEndDocument()
throws javax.json.stream.JsonGenerationException,
IOException
StreamWriterwriteEndDocument in interface StreamWriterjavax.json.stream.JsonGenerationExceptionIOExceptionpublic void writeStartObject(String element) throws javax.json.stream.JsonGenerationException
StreamWritername.writeStartObject in interface StreamWriterelement - The name of the objectjavax.json.stream.JsonGenerationExceptionpublic void writeEndObject()
throws javax.json.stream.JsonGenerationException
StreamWriterwriteEndObject in interface StreamWriterjavax.json.stream.JsonGenerationExceptionpublic void writeAttribute(String name, String value) throws javax.json.stream.JsonGenerationException
StreamWriterString attribute with the specified name and
value. E.g. for JSON this will write: "name":"value".writeAttribute in interface StreamWritername - The name of the attributevalue - The value of the attributejavax.json.stream.JsonGenerationExceptionpublic void writeAttribute(String name, Boolean value) throws javax.json.stream.JsonGenerationException
StreamWriterBoolean attribute with the specified name and
value. E.g. for JSON this will write: "name":true/false.writeAttribute in interface StreamWritername - The name of the attributevalue - The value of the attributejavax.json.stream.JsonGenerationExceptionpublic void close()
throws javax.json.stream.JsonGenerationException
StreamWriterOutputStream associated with this object. Some
OutputStreams require closing before any data will be written.close in interface StreamWriterjavax.json.stream.JsonGenerationExceptionpublic void writeStartArray(String element) throws Exception
StreamWritername. If the
data structure doesn't support arrays, this method will do nothing.writeStartArray in interface StreamWriterelement - The name of the arrayException - Any exception thrown while writing. E.g. for JSON this
might be a
JsonGenerationException.public void writeEndArray()
throws Exception
StreamWriterwriteEndArray in interface StreamWriterException - Any exception thrown while writing. E.g. for JSON this
might be a
JsonGenerationException.Copyright © 2019. All rights reserved.