org.fudgemsg.json
Class FudgeJSONStreamReader

java.lang.Object
  extended by org.fudgemsg.json.FudgeJSONStreamReader
All Implemented Interfaces:
Closeable, FudgeStreamReader

public class FudgeJSONStreamReader
extends Object
implements FudgeStreamReader

A FudgeStreamReader implementation for decoding a stream of JSON encoded text into Fudge messages.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.fudgemsg.FudgeStreamReader
FudgeStreamReader.FudgeStreamElement
 
Constructor Summary
FudgeJSONStreamReader(FudgeContext fudgeContext, Reader reader)
           
FudgeJSONStreamReader(FudgeContext fudgeContext, Reader underlying, JSONSettings settings)
           
 
Method Summary
 void close()
          Closes the FudgeStreamReader and attempts to close the underlying data source if appropriate.
 FudgeStreamReader.FudgeStreamElement getCurrentElement()
          Returns the value last returned by FudgeStreamReader.next().
 String getFieldName()
          If the current stream element is a field, returns the field name.
 Integer getFieldOrdinal()
          If the current stream element is a field, returns the ordinal index, or null if the field did not include an ordinal.
 FudgeFieldType<?> getFieldType()
          If the current stream element is a field, returns the FudgeFieldType.
 Object getFieldValue()
          If the current stream element is a field, returns the field value.
 FudgeContext getFudgeContext()
          Returns the FudgeContext bound to the reader used for type and taxonomy resolution.
 int getProcessingDirectives()
          Returns the processing directivies specified in the last envelope header read.
 int getSchemaVersion()
          Returns the schema version specified in the last envelope header read.
 JSONSettings getSettings()
           
 FudgeTaxonomy getTaxonomy()
          Returns the current FudgeTaxonomy corresponding to the taxonomy identifier specified in the message envelope.
 short getTaxonomyId()
          Returns the taxonomy identifier specified in the last envelope header read.
protected  org.json.JSONTokener getTokener()
           
protected  Reader getUnderlying()
           
 boolean hasNext()
          Returns true if there is at least one more element to be returned by a call to FudgeStreamReader.next().
 FudgeStreamReader.FudgeStreamElement next()
          Reads the next stream element from the source and returns the element type.
protected  FudgeStreamReader.FudgeStreamElement setCurrentElement(FudgeStreamReader.FudgeStreamElement currentElement)
           
protected  void setCurrentFieldName(String name)
           
protected  void setEnvelopeFields(int processingDirectives, int schemaVersion, int taxonomyId)
           
protected  void setFieldValue(Object object)
           
protected  RuntimeException wrapException(String message, org.json.JSONException e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FudgeJSONStreamReader

public FudgeJSONStreamReader(FudgeContext fudgeContext,
                             Reader underlying,
                             JSONSettings settings)

FudgeJSONStreamReader

public FudgeJSONStreamReader(FudgeContext fudgeContext,
                             Reader reader)
Method Detail

getUnderlying

protected Reader getUnderlying()

getTokener

protected org.json.JSONTokener getTokener()

close

public void close()
Description copied from interface: FudgeStreamReader
Closes the FudgeStreamReader and attempts to close the underlying data source if appropriate.

Specified by:
close in interface Closeable
Specified by:
close in interface FudgeStreamReader

wrapException

protected RuntimeException wrapException(String message,
                                         org.json.JSONException e)

getCurrentElement

public FudgeStreamReader.FudgeStreamElement getCurrentElement()
Description copied from interface: FudgeStreamReader
Returns the value last returned by FudgeStreamReader.next().

Specified by:
getCurrentElement in interface FudgeStreamReader
Returns:
the type of the current element in the stream

setCurrentElement

protected FudgeStreamReader.FudgeStreamElement setCurrentElement(FudgeStreamReader.FudgeStreamElement currentElement)

getFieldName

public String getFieldName()
Description copied from interface: FudgeStreamReader
If the current stream element is a field, returns the field name. If the underlying stream does not specify a field name, but the ordinal can be resolved through a taxonomy, returns the resolved name.

Specified by:
getFieldName in interface FudgeStreamReader
Returns:
current field name

setCurrentFieldName

protected void setCurrentFieldName(String name)

getFieldOrdinal

public Integer getFieldOrdinal()
Description copied from interface: FudgeStreamReader
If the current stream element is a field, returns the ordinal index, or null if the field did not include an ordinal.

Specified by:
getFieldOrdinal in interface FudgeStreamReader
Returns:
current field ordinal

getFieldType

public FudgeFieldType<?> getFieldType()
Description copied from interface: FudgeStreamReader
If the current stream element is a field, returns the FudgeFieldType.

Specified by:
getFieldType in interface FudgeStreamReader
Returns:
current field type

getFieldValue

public Object getFieldValue()
Description copied from interface: FudgeStreamReader
If the current stream element is a field, returns the field value.

Specified by:
getFieldValue in interface FudgeStreamReader
Returns:
current field value

setFieldValue

protected void setFieldValue(Object object)

getFudgeContext

public FudgeContext getFudgeContext()
Description copied from interface: FudgeStreamReader
Returns the FudgeContext bound to the reader used for type and taxonomy resolution.

Specified by:
getFudgeContext in interface FudgeStreamReader
Returns:
the FudgeContext

getProcessingDirectives

public int getProcessingDirectives()
Description copied from interface: FudgeStreamReader
Returns the processing directivies specified in the last envelope header read.

Specified by:
getProcessingDirectives in interface FudgeStreamReader
Returns:
current processing directive flags

getSchemaVersion

public int getSchemaVersion()
Description copied from interface: FudgeStreamReader
Returns the schema version specified in the last envelope header read.

Specified by:
getSchemaVersion in interface FudgeStreamReader
Returns:
current message schema version

getTaxonomy

public FudgeTaxonomy getTaxonomy()
Description copied from interface: FudgeStreamReader
Returns the current FudgeTaxonomy corresponding to the taxonomy identifier specified in the message envelope. Returns null if the message did not specify a taxonomy or the taxonomy identifier cannot be resolved by the bound FudgeContext.

Specified by:
getTaxonomy in interface FudgeStreamReader
Returns:
current taxonomy if available

setEnvelopeFields

protected void setEnvelopeFields(int processingDirectives,
                                 int schemaVersion,
                                 int taxonomyId)

getTaxonomyId

public short getTaxonomyId()
Description copied from interface: FudgeStreamReader
Returns the taxonomy identifier specified in the last envelope header read.

Specified by:
getTaxonomyId in interface FudgeStreamReader
Returns:
current taxonomy identifier

hasNext

public boolean hasNext()
Description copied from interface: FudgeStreamReader

Returns true if there is at least one more element to be returned by a call to FudgeStreamReader.next(). A return of false indicates the end of a message (or submessage) has been reached. After the end of a sub-message, the next immediate call will indicate whether there are further elements or the end of the outer message. After the end of the main message referenced by the envelope header, the next immediate call may:

  1. Return false if the source does not contain any subsequent Fudge messages; or
  2. Return true if the source may contain further Fudge messages. Calling next() will return the envelope header of the next message if one is present, or null if the source does not contain any further messages.

Specified by:
hasNext in interface FudgeStreamReader
Returns:
true if there is at least one more element to read

next

public FudgeStreamReader.FudgeStreamElement next()
Description copied from interface: FudgeStreamReader
Reads the next stream element from the source and returns the element type.

Specified by:
next in interface FudgeStreamReader
Returns:
the type of the next element in the stream, or null if the end of stream has been reached at a message boundary (i.e. attempting to read the first byte of an envelope)

getSettings

public JSONSettings getSettings()


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