org.fudgemsg
Class FudgeDataInputStreamReader

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

public class FudgeDataInputStreamReader
extends Object
implements FudgeStreamReader

An implementation of FudgeStreamReader for consuming data from a DataInput.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.fudgemsg.FudgeStreamReader
FudgeStreamReader.FudgeStreamElement
 
Constructor Summary
FudgeDataInputStreamReader(FudgeContext fudgeContext, DataInput dataInput)
          Creates a new FudgeDataInputStreamReader associated with the given FudgeContext and DataInput data source.
FudgeDataInputStreamReader(FudgeContext fudgeContext, InputStream inputStream)
          Creates a new FudgeDataInputStreamReader by wrapping a InputStream with a DataInput.
 
Method Summary
 void close()
          Closes this reader.
protected  void consumeFieldData()
          Reads the next field (prefix and value) from the input stream, setting internal state to be returned by getFieldName, getFieldOrdinal, getFieldType, getCurrentElement and getFieldValue.
protected  boolean consumeMessageEnvelope()
          Reads the next message envelope from the input stream, setting internal state go be returned by getCurrentElement, getProcessingDirectives, getSchemaVersion, getTaxonomyId and getEnvelopeSize.
 FudgeStreamReader.FudgeStreamElement getCurrentElement()
          Returns the value last returned by FudgeStreamReader.next().
protected  DataInput getDataInput()
          Returns the underlying DataInput.
 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.
 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.
 boolean hasNext()
          Returns true if there is at least one more element to be returned by a call to FudgeStreamReader.next().
protected  boolean isEndOfSubMessage()
          Detects the end of a sub-message field; i.e.
 FudgeStreamReader.FudgeStreamElement next()
          Reads the next stream element from the source and returns the element type.
static Object readFieldValue(DataInput is, FudgeFieldType<?> type, int varSize)
          Reads a Fudge encoded field value from an input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FudgeDataInputStreamReader

public FudgeDataInputStreamReader(FudgeContext fudgeContext,
                                  DataInput dataInput)
Creates a new FudgeDataInputStreamReader associated with the given FudgeContext and DataInput data source. The Fudge context is used to hold all decoding parameters such as taxonomy and type resolution.

Parameters:
fudgeContext - the FudgeContext to associate with
dataInput - the source of data to read Fudge elements from

FudgeDataInputStreamReader

public FudgeDataInputStreamReader(FudgeContext fudgeContext,
                                  InputStream inputStream)
Creates a new FudgeDataInputStreamReader by wrapping a InputStream with a DataInput.

Parameters:
fudgeContext - the FudgeContext to associate with
inputStream - the source of data to read Fudge elements from
Method Detail

close

public void close()
Closes this reader. If the underlying data source implements the Closeable interface, Closeable.close() will be called on it.

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

getCurrentElement

public FudgeStreamReader.FudgeStreamElement getCurrentElement()
Returns the value last returned by FudgeStreamReader.next().

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

getFieldName

public String getFieldName()
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

getFieldOrdinal

public Integer getFieldOrdinal()
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()
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()
If the current stream element is a field, returns the field value.

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

getFudgeContext

public FudgeContext getFudgeContext()
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()
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()
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()
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

getTaxonomyId

public short getTaxonomyId()
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()

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()
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)

isEndOfSubMessage

protected boolean isEndOfSubMessage()
Detects the end of a sub-message field; i.e. the last field within the sub-message has been fully consumed. After the end has been reached, further calls to next() will resume consuming fields from the containing message again.

Returns:
true if the end of the sub-message has been reached, false otherwise.

getDataInput

protected DataInput getDataInput()
Returns the underlying DataInput.

Returns:
the DataInput

consumeFieldData

protected void consumeFieldData()
                         throws IOException
Reads the next field (prefix and value) from the input stream, setting internal state to be returned by getFieldName, getFieldOrdinal, getFieldType, getCurrentElement and getFieldValue. The input stream is left positioned at the start of the next field.

Throws:
IOException - if the underlying stream raises one

readFieldValue

public static Object readFieldValue(DataInput is,
                                    FudgeFieldType<?> type,
                                    int varSize)
Reads a Fudge encoded field value from an input stream.

Parameters:
is - the DataInput wrapped input steram
type - the FudgeFieldType of the data to read
varSize - number of bytes in a variable width field payload
Returns:
the field value

consumeMessageEnvelope

protected boolean consumeMessageEnvelope()
                                  throws IOException
Reads the next message envelope from the input stream, setting internal state go be returned by getCurrentElement, getProcessingDirectives, getSchemaVersion, getTaxonomyId and getEnvelopeSize.

Returns:
true if there was an envelope to consume, false if an EOF was found on reading the first byte
Throws:
IOException - if the underlying data source raises an IOException other than an EOFException on the first byte of the envelope


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