org.fudgemsg.json
Class FudgeJSONStreamWriter

java.lang.Object
  extended by org.fudgemsg.AlternativeFudgeStreamWriter
      extended by org.fudgemsg.json.FudgeJSONStreamWriter
All Implemented Interfaces:
Closeable, Flushable, FudgeStreamWriter

public class FudgeJSONStreamWriter
extends AlternativeFudgeStreamWriter

A FudgeStreamWriter implementation for generating JSON representations of Fudge messages. Please refer to JSON Fudge Messages for details on the representation.


Constructor Summary
FudgeJSONStreamWriter(FudgeContext fudgeContext, Writer writer)
          Creates a new stream writer for writing Fudge messages in JSON format to a given Writer.
FudgeJSONStreamWriter(FudgeContext fudgeContext, Writer writer, JSONSettings settings)
          Creates a new stream writer for writing Fudge messages in JSON format to a given Writer.
 
Method Summary
protected  void clearWriter()
          Discards the JSON writer.
 void flush()
          No action taken.
protected  void fudgeEnvelopeEnd()
          Ends the JSON object.
protected  void fudgeEnvelopeStart(int processingDirectives, int schemaVersion)
          Begins a JSON object with the processing directives, schema and taxonomy.
protected  boolean fudgeFieldStart(Short ordinal, String name, FudgeFieldType<?> type)
          Writes out the field name to the JSON object.
protected  void fudgeFieldValue(FudgeFieldType<?> type, Object fieldValue)
          Writes the field value to the JSON object.
protected  void fudgeSubMessageEnd()
          Ends the JSON sub-object.
protected  void fudgeSubMessageStart()
          Starts a sub-object within the JSON object.
 JSONSettings getSettings()
          Returns the settings object
protected  Writer getUnderlying()
          Returns the underlying Writer that is wrapped by JSONWriter instances for messages.
protected  org.json.JSONWriter getWriter()
          Returns the JSON writer being used, allocating one if necessary.
protected  void wrapException(String message, org.json.JSONException e)
          Wraps a JSON exception (which may in turn wrap IOExceptions into either a FudgeRuntimeException or FudgeRuntimeIOException.
protected  void writeArray(byte[] data)
           
protected  void writeArray(double[] data)
           
protected  void writeArray(float[] data)
           
protected  void writeArray(int[] data)
           
protected  void writeArray(long[] data)
           
protected  void writeArray(short[] data)
           
 
Methods inherited from class org.fudgemsg.AlternativeFudgeStreamWriter
close, envelopeComplete, fudgeFieldEnd, getCurrentTaxonomy, getCurrentTaxonomyId, getFudgeContext, setCurrentTaxonomyId, writeEnvelopeHeader, writeField, writeField, writeFields
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FudgeJSONStreamWriter

public FudgeJSONStreamWriter(FudgeContext fudgeContext,
                             Writer writer)
Creates a new stream writer for writing Fudge messages in JSON format to a given Writer.

Parameters:
fudgeContext - the associated FudgeContext
writer - the target to write to

FudgeJSONStreamWriter

public FudgeJSONStreamWriter(FudgeContext fudgeContext,
                             Writer writer,
                             JSONSettings settings)
Creates a new stream writer for writing Fudge messages in JSON format to a given Writer.

Parameters:
fudgeContext - the associated FudgeContext
writer - the target to write to
Method Detail

getSettings

public JSONSettings getSettings()
Returns the settings object


getWriter

protected org.json.JSONWriter getWriter()
Returns the JSON writer being used, allocating one if necessary.

Returns:
the writer

clearWriter

protected void clearWriter()
Discards the JSON writer. The implementation only allows a single use so we must drop the instance after each message envelope completes.


getUnderlying

protected Writer getUnderlying()
Returns the underlying Writer that is wrapped by JSONWriter instances for messages.

Returns:
the writer

wrapException

protected void wrapException(String message,
                             org.json.JSONException e)
Wraps a JSON exception (which may in turn wrap IOExceptions into either a FudgeRuntimeException or FudgeRuntimeIOException.

Parameters:
message - message describing the current operation
e - the originating exception

flush

public void flush()
No action taken.

Specified by:
flush in interface Flushable
Specified by:
flush in interface FudgeStreamWriter
Overrides:
flush in class AlternativeFudgeStreamWriter

fudgeEnvelopeStart

protected void fudgeEnvelopeStart(int processingDirectives,
                                  int schemaVersion)
Begins a JSON object with the processing directives, schema and taxonomy.

Overrides:
fudgeEnvelopeStart in class AlternativeFudgeStreamWriter
Parameters:
processingDirectives - the envelope processing directives
schemaVersion - the envelope schema version

fudgeEnvelopeEnd

protected void fudgeEnvelopeEnd()
Ends the JSON object.

Overrides:
fudgeEnvelopeEnd in class AlternativeFudgeStreamWriter

fudgeFieldStart

protected boolean fudgeFieldStart(Short ordinal,
                                  String name,
                                  FudgeFieldType<?> type)
Writes out the field name to the JSON object.

Overrides:
fudgeFieldStart in class AlternativeFudgeStreamWriter
Parameters:
ordinal - the field ordinal
name - the field name
type - the field type
Returns:
true to continue processing the field, false to ignore it (AlternativeFudgeStreamWriter.fudgeFieldValue(org.fudgemsg.FudgeFieldType, java.lang.Object), AlternativeFudgeStreamWriter.fudgeSubMessageStart(), AlternativeFudgeStreamWriter.fudgeSubMessageEnd() and AlternativeFudgeStreamWriter.fudgeFieldEnd() will not be called for this field)

writeArray

protected void writeArray(byte[] data)
                   throws org.json.JSONException
Throws:
org.json.JSONException

writeArray

protected void writeArray(short[] data)
                   throws org.json.JSONException
Throws:
org.json.JSONException

writeArray

protected void writeArray(int[] data)
                   throws org.json.JSONException
Throws:
org.json.JSONException

writeArray

protected void writeArray(long[] data)
                   throws org.json.JSONException
Throws:
org.json.JSONException

writeArray

protected void writeArray(float[] data)
                   throws org.json.JSONException
Throws:
org.json.JSONException

writeArray

protected void writeArray(double[] data)
                   throws org.json.JSONException
Throws:
org.json.JSONException

fudgeFieldValue

protected void fudgeFieldValue(FudgeFieldType<?> type,
                               Object fieldValue)
Writes the field value to the JSON object.

Overrides:
fudgeFieldValue in class AlternativeFudgeStreamWriter
Parameters:
type - the field type
fieldValue - the value

fudgeSubMessageStart

protected void fudgeSubMessageStart()
Starts a sub-object within the JSON object.

Overrides:
fudgeSubMessageStart in class AlternativeFudgeStreamWriter

fudgeSubMessageEnd

protected void fudgeSubMessageEnd()
Ends the JSON sub-object.

Overrides:
fudgeSubMessageEnd in class AlternativeFudgeStreamWriter


Copyright 2009-Present by OpenGamma Inc. and individual contributors
Released under the Apache License, Version 2.0