Package fish.payara.admin.rest.streams
Class JsonStreamWriter
- java.lang.Object
-
- fish.payara.admin.rest.streams.JsonStreamWriter
-
- All Implemented Interfaces:
StreamWriter
public class JsonStreamWriter extends Object implements StreamWriter
AStreamWriter
for handling JSON.
-
-
Constructor Summary
Constructors Constructor Description JsonStreamWriter(OutputStream os)
Creates aStreamWriter
for handling JSON, with anull
prefix and postfix.JsonStreamWriter(OutputStream os, String prefix, String postfix)
Creates aStreamWriter
for handling JSON.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes theOutputStream
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 aBoolean
attribute with the specifiedname
andvalue
.void
writeAttribute(String name, String value)
Writes aString
attribute with the specifiedname
andvalue
.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 specifiedname
.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 specifiedname
.
-
-
-
Constructor Detail
-
JsonStreamWriter
public JsonStreamWriter(OutputStream os, String prefix, String postfix)
Creates aStreamWriter
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 aStreamWriter
for handling JSON, with anull
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 interfaceStreamWriter
- 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 interfaceStreamWriter
- 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 interfaceStreamWriter
- 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 interfaceStreamWriter
- 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 specifiedname
.- Specified by:
writeStartObject
in interfaceStreamWriter
- 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 interfaceStreamWriter
- Throws:
jakarta.json.stream.JsonGenerationException
-
writeAttribute
public void writeAttribute(String name, String value) throws jakarta.json.stream.JsonGenerationException
Description copied from interface:StreamWriter
Writes aString
attribute with the specifiedname
andvalue
. E.g. for JSON this will write:"name":"value"
.- Specified by:
writeAttribute
in interfaceStreamWriter
- Parameters:
name
- The name of the attributevalue
- 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 aBoolean
attribute with the specifiedname
andvalue
. E.g. for JSON this will write:"name":true/false
.- Specified by:
writeAttribute
in interfaceStreamWriter
- Parameters:
name
- The name of the attributevalue
- 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 theOutputStream
associated with this object. Some OutputStreams require closing before any data will be written.- Specified by:
close
in interfaceStreamWriter
- 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 specifiedname
. If the data structure doesn't support arrays, this method will do nothing.- Specified by:
writeStartArray
in interfaceStreamWriter
- Parameters:
element
- The name of the array- Throws:
Exception
- Any exception thrown while writing. E.g. for JSON this might be aJsonGenerationException
.
-
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 interfaceStreamWriter
- Throws:
Exception
- Any exception thrown while writing. E.g. for JSON this might be aJsonGenerationException
.
-
-