org.fudgemsg
Class FudgeDataOutputStreamWriter

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

public class FudgeDataOutputStreamWriter
extends Object
implements FudgeStreamWriter

Implementation of a FudgeStreamWriter that writes to a DataOutput.


Constructor Summary
FudgeDataOutputStreamWriter(FudgeContext fudgeContext, DataOutput dataOutput)
          Creates a new FudgeDataOutputStreamWriter associated with the given FudgeContext and DataOutput target.
FudgeDataOutputStreamWriter(FudgeContext fudgeContext, OutputStream outputStream)
          Creates a new FudgeDataOutputStreamWriter by wrapping a OutputStream with a DataOutput.
 
Method Summary
 void close()
          Flushes and closes this writer and the underlying target.
 void envelopeComplete()
          No data is written - the end of the envelope is implied by the size from the header.
 void flush()
          Flushes any data from the internal buffers to the target stream and attempts to flush the underlying stream if appropriate.
 FudgeTaxonomy getCurrentTaxonomy()
          Returns the taxonomy (if any) that is currently being used to encode fields.
 int getCurrentTaxonomyId()
          Returns the current taxonomy identifier.
protected  DataOutput getDataOutput()
           
 FudgeContext getFudgeContext()
          Returns the bound FudgeContext used for type and taxonomy resolution.
 boolean isFlushOnEnvelopeComplete()
          Indicates if flush() is to be called on envelope completion.
 void setCurrentTaxonomyId(int taxonomyId)
          Sets the current taxonomy, by identifier, to be used to encode fields.
 void setFlushOnEnvelopeComplete(boolean automaticFlush)
          Set whether to call flush() on envelope completion.
 String toString()
          
 void writeEnvelopeHeader(int processingDirectives, int schemaVersion, int messageSize)
          Writes a message envelope header.
 void writeField(FudgeField field)
          Writes a message field.
 void writeField(Short ordinal, String name, FudgeFieldType type, Object fieldValue)
          Writes a message field.
 void writeFields(FudgeFieldContainer msg)
          Writes a set of fields.
protected  void writeFieldValue(FudgeFieldType type, Object value, int valueSize)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FudgeDataOutputStreamWriter

public FudgeDataOutputStreamWriter(FudgeContext fudgeContext,
                                   DataOutput dataOutput)
Creates a new FudgeDataOutputStreamWriter associated with the given FudgeContext and DataOutput target. The Fudge context is used to hold all encoding parameters such as taxonomy and type resolution.

Parameters:
fudgeContext - the FudgeContext to associate with
dataOutput - the target to write Fudge elements to

FudgeDataOutputStreamWriter

public FudgeDataOutputStreamWriter(FudgeContext fudgeContext,
                                   OutputStream outputStream)
Creates a new FudgeDataOutputStreamWriter by wrapping a OutputStream with a DataOutput.

Parameters:
fudgeContext - the FudgeContext to associate with
outputStream - the target to write Fudge elements to
Method Detail

close

public void close()
Flushes and closes this writer and the underlying target.

Specified by:
close in interface Closeable
Specified by:
close in interface FudgeStreamWriter

flush

public void flush()
Flushes any data from the internal buffers to the target stream and attempts to flush the underlying stream if appropriate.

Specified by:
flush in interface Flushable
Specified by:
flush in interface FudgeStreamWriter

getFudgeContext

public FudgeContext getFudgeContext()
Returns the bound FudgeContext used for type and taxonomy resolution.

Specified by:
getFudgeContext in interface FudgeStreamWriter
Returns:
the FudgeContext

getDataOutput

protected DataOutput getDataOutput()
Returns:
the dataOutput

getCurrentTaxonomy

public FudgeTaxonomy getCurrentTaxonomy()
Returns the taxonomy (if any) that is currently being used to encode fields. Returns null if no taxonomy is specified or the taxonomy identifier cannot be resolved by the bound FudgeContext.

Specified by:
getCurrentTaxonomy in interface FudgeStreamWriter
Returns:
the FudgeTaxonomy

setCurrentTaxonomyId

public void setCurrentTaxonomyId(int taxonomyId)
Sets the current taxonomy, by identifier, to be used to encode fields.

Specified by:
setCurrentTaxonomyId in interface FudgeStreamWriter
Parameters:
taxonomyId - the taxonomy identifier

getCurrentTaxonomyId

public int getCurrentTaxonomyId()
Returns the current taxonomy identifier.

Specified by:
getCurrentTaxonomyId in interface FudgeStreamWriter
Returns:
current taxonomy identifier

writeEnvelopeHeader

public void writeEnvelopeHeader(int processingDirectives,
                                int schemaVersion,
                                int messageSize)
Writes a message envelope header.

Specified by:
writeEnvelopeHeader in interface FudgeStreamWriter
Parameters:
processingDirectives - the processing directive flags
schemaVersion - the schema version value
messageSize - the Fudge encoded size of the underlying message, including the message envelope

envelopeComplete

public void envelopeComplete()
No data is written - the end of the envelope is implied by the size from the header. If the writer is set to automatically flush on message completion (the default) then flush() will be called to flush the underlying stream if possible.

Specified by:
envelopeComplete in interface FudgeStreamWriter

isFlushOnEnvelopeComplete

public boolean isFlushOnEnvelopeComplete()
Indicates if flush() is to be called on envelope completion.

Returns:
true if flush is to be called, false otherwise

setFlushOnEnvelopeComplete

public void setFlushOnEnvelopeComplete(boolean automaticFlush)
Set whether to call flush() on envelope completion. The default behavior is to do so.

Parameters:
automaticFlush - true to call flush on envelope completion, false otherwise

writeFields

public void writeFields(FudgeFieldContainer msg)
Writes a set of fields.

Specified by:
writeFields in interface FudgeStreamWriter
Parameters:
msg - the fields to write.

writeField

public void writeField(FudgeField field)
Writes a message field.

Specified by:
writeField in interface FudgeStreamWriter
Parameters:
field - the message field to write

writeField

public void writeField(Short ordinal,
                       String name,
                       FudgeFieldType type,
                       Object fieldValue)
Writes a message field.

Specified by:
writeField in interface FudgeStreamWriter
Parameters:
ordinal - the ordinal index of the field, or null to omit.
name - the name of the field, null to omit. If the ordinal is omitted and the name matches an entry in the current taxonomy the name will be replaced by the taxonomy resolved ordinal.
type - the type of the underlying data
fieldValue - value of the field

writeFieldValue

protected void writeFieldValue(FudgeFieldType type,
                               Object value,
                               int valueSize)
Parameters:
type - the FudgeFieldType defining how to write this
value - the value to write
valueSize - the size of the value

toString

public String toString()

Overrides:
toString in class Object


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