de.hpi.fgis.dude.util.data.json
Class DuDeJsonGenerator

java.lang.Object
  extended by de.hpi.fgis.dude.util.data.json.DuDeJsonGenerator
All Implemented Interfaces:
Closeable

public class DuDeJsonGenerator
extends Object
implements Closeable

DuDeJsonGenerator is another implementation for generating Json code. It is used by Jsonable.toJson(DuDeJsonGenerator). This approach is faster than the old implementation {Jsonable#toJsonString(int)} but slower than {Jsonable#toJsonString()}.

Author:
Matthias Pohl

Constructor Summary
protected DuDeJsonGenerator(org.codehaus.jackson.JsonGenerator generator)
          Initializes a new DuDeJsonGenerator with the given generator.
  DuDeJsonGenerator(OutputStream outStream)
          Initializes a new DuDeJsonGenerator.
  DuDeJsonGenerator(Writer writer)
          Initializes a new DuDeJsonGenerator.
 
Method Summary
 void close()
           
 void disableFormattedJson()
          Disables formatted Json.
 void enableFormattedJson()
          Enables formatted Json.
 void flush()
          Flushes the internal buffer.
 void writeArrayEnd()
          Writes an array end into the stream.
 void writeArrayRecordEntry(String fieldname, Collection<? extends Jsonable> jsonables)
          Writes a new collection record entry into the stream
 void writeArrayStart()
          Writes an array start into the stream.
 void writeBoolean(boolean value)
          Writes a raw boolean into the stream.
 void writeBooleanRecordEntry(String fieldname, boolean value)
          Writes a new boolean record entry into the stream
 void writeJsonArray(JsonArray array)
          Writes the passed JsonArray.
 void writeJsonBoolean(JsonBoolean value)
          Writes the passed JsonBoolean.
 void writeJsonNull()
          Writes a JsonNull value to the stream.
 void writeJsonNumber(JsonNumber value)
          Writes the passed JsonNumber.
 void writeJsonRecord(JsonRecord record)
          Writes the passed JsonRecord.
 void writeJsonString(JsonString value)
          Writes the passed JsonString.
 void writeJsonValue(JsonValue value)
          Writes the passed JsonValue.
 void writeNumber(Number number)
          Writes a raw string into the stream.
 void writeNumberRecordEntry(String fieldname, Number value)
          Writes a new number record entry into the stream
 void writeRecord(AutoJsonable jsonable)
          Writes a new record entry into the stream
 void writeRecordEnd()
          Writes a record end into the stream.
 void writeRecordEntry(String fieldname, AutoJsonable jsonable)
          Writes a new record entry into the stream
 void writeRecordEntry(String fieldname, Jsonable jsonable)
          Writes a new record entry into the stream
 void writeRecordEntry(String fieldname, JsonValue value)
          Writes a new record entry into the stream
 void writeRecordFieldName(String fieldname)
          Writes a new field name into the stream.
 void writeRecordStart()
          Writes a record start into the stream.
 void writeString(String string)
          Writes a raw string into the stream.
 void writeStringRecordEntry(String fieldname, String value)
          Writes a new string record entry into the stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DuDeJsonGenerator

public DuDeJsonGenerator(OutputStream outStream)
                  throws IOException
Initializes a new DuDeJsonGenerator.

Parameters:
outStream - The stream that is used for the output.
Throws:
IOException - If an error occurs while accessing the writer.
NullPointerException - If null was passed instead of a OutputStream.

DuDeJsonGenerator

public DuDeJsonGenerator(Writer writer)
                  throws IOException
Initializes a new DuDeJsonGenerator.

Parameters:
writer - The writer that is used internally.
Throws:
IOException - If an error occurs while accessing the writer.
NullPointerException - If null was passed instead of a Writer.

DuDeJsonGenerator

protected DuDeJsonGenerator(org.codehaus.jackson.JsonGenerator generator)
Initializes a new DuDeJsonGenerator with the given generator.

Parameters:
generator - The generator to wrap
Throws:
NullPointerException - If null was passed instead of a JsonGenerator.
Method Detail

flush

public void flush()
           throws IOException
Flushes the internal buffer.

Throws:
IOException - If an error occurs while flushing the data.

enableFormattedJson

public void enableFormattedJson()
Enables formatted Json. Calling this method will induce the generator to create formatted Json code. This makes the code easier to read for humans but increases the runtime.


disableFormattedJson

public void disableFormattedJson()
Disables formatted Json. Calling this method will induce the generator to create unformatted Json code. This makes the code harder to read for humans but decreases the runtime.


writeJsonValue

public void writeJsonValue(JsonValue value)
                    throws org.codehaus.jackson.JsonGenerationException,
                           IOException
Writes the passed JsonValue.

Parameters:
value - The JsonValue that shall be converted into Json code.
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeJsonArray

public void writeJsonArray(JsonArray array)
                    throws org.codehaus.jackson.JsonGenerationException,
                           IOException
Writes the passed JsonArray.

Parameters:
array - The JsonArray that shall be converted into Json code.
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeJsonBoolean

public void writeJsonBoolean(JsonBoolean value)
                      throws org.codehaus.jackson.JsonGenerationException,
                             IOException
Writes the passed JsonBoolean.

Parameters:
value - The JsonBoolean that shall be converted into Json code.
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeJsonNull

public void writeJsonNull()
                   throws org.codehaus.jackson.JsonGenerationException,
                          IOException
Writes a JsonNull value to the stream.

Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeJsonNumber

public void writeJsonNumber(JsonNumber value)
                     throws org.codehaus.jackson.JsonGenerationException,
                            IOException
Writes the passed JsonNumber.

Parameters:
value - The JsonNumber that shall be converted into Json code.
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeJsonRecord

public void writeJsonRecord(JsonRecord record)
                     throws org.codehaus.jackson.JsonGenerationException,
                            IOException
Writes the passed JsonRecord.

Parameters:
record - The JsonRecord that shall be converted into Json code.
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeJsonString

public void writeJsonString(JsonString value)
                     throws org.codehaus.jackson.JsonGenerationException,
                            IOException
Writes the passed JsonString.

Parameters:
value - The JsonString that shall be converted into Json code.
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeRecordStart

public void writeRecordStart()
                      throws org.codehaus.jackson.JsonGenerationException,
                             IOException
Writes a record start into the stream.

Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeRecordEnd

public void writeRecordEnd()
                    throws org.codehaus.jackson.JsonGenerationException,
                           IOException
Writes a record end into the stream.

Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeArrayStart

public void writeArrayStart()
                     throws org.codehaus.jackson.JsonGenerationException,
                            IOException
Writes an array start into the stream.

Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeArrayEnd

public void writeArrayEnd()
                   throws org.codehaus.jackson.JsonGenerationException,
                          IOException
Writes an array end into the stream.

Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeRecordEntry

public void writeRecordEntry(String fieldname,
                             JsonValue value)
                      throws org.codehaus.jackson.JsonGenerationException,
                             IOException
Writes a new record entry into the stream

Parameters:
fieldname - The field name of the entry.
value - The JsonValue that shall be converted into Json code.
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeRecordFieldName

public void writeRecordFieldName(String fieldname)
                          throws org.codehaus.jackson.JsonGenerationException,
                                 IOException
Writes a new field name into the stream.

Parameters:
fieldname - The field name.
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException

writeString

public void writeString(String string)
                 throws org.codehaus.jackson.JsonGenerationException,
                        IOException
Writes a raw string into the stream.

Parameters:
string - The string to write
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeNumber

public void writeNumber(Number number)
                 throws org.codehaus.jackson.JsonGenerationException,
                        IOException
Writes a raw string into the stream.

Parameters:
number - The number to write
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeBoolean

public void writeBoolean(boolean value)
                  throws org.codehaus.jackson.JsonGenerationException,
                         IOException
Writes a raw boolean into the stream.

Parameters:
value - The value to write
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeStringRecordEntry

public void writeStringRecordEntry(String fieldname,
                                   String value)
                            throws org.codehaus.jackson.JsonGenerationException,
                                   IOException
Writes a new string record entry into the stream

Parameters:
fieldname - The field name of the entry.
value - The string to write
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeNumberRecordEntry

public void writeNumberRecordEntry(String fieldname,
                                   Number value)
                            throws org.codehaus.jackson.JsonGenerationException,
                                   IOException
Writes a new number record entry into the stream

Parameters:
fieldname - The field name of the entry.
value - The number to write
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeBooleanRecordEntry

public void writeBooleanRecordEntry(String fieldname,
                                    boolean value)
                             throws org.codehaus.jackson.JsonGenerationException,
                                    IOException
Writes a new boolean record entry into the stream

Parameters:
fieldname - The field name of the entry.
value - The boolean to write
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeArrayRecordEntry

public void writeArrayRecordEntry(String fieldname,
                                  Collection<? extends Jsonable> jsonables)
                           throws org.codehaus.jackson.JsonGenerationException,
                                  IOException
Writes a new collection record entry into the stream

Parameters:
fieldname - The field name of the entry.
jsonables - The collection of Jsonables to write
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeRecordEntry

public void writeRecordEntry(String fieldname,
                             Jsonable jsonable)
                      throws org.codehaus.jackson.JsonGenerationException,
                             IOException
Writes a new record entry into the stream

Parameters:
fieldname - The field name of the entry.
jsonable - The Jsonable to write
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeRecordEntry

public void writeRecordEntry(String fieldname,
                             AutoJsonable jsonable)
                      throws org.codehaus.jackson.JsonGenerationException,
                             IOException
Writes a new record entry into the stream

Parameters:
fieldname - The field name of the entry.
jsonable - The Jsonable to write
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.

writeRecord

public void writeRecord(AutoJsonable jsonable)
                 throws org.codehaus.jackson.JsonGenerationException,
                        IOException
Writes a new record entry into the stream

Parameters:
jsonable - The Jsonable to write
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while accessing the underlying stream.


Copyright © 2011 Hasso Plattner Institute - Chair of Information Systems. All Rights Reserved.