spark.data.io
Class SONWriter

java.lang.Object
  extended by spark.data.io.SONWriter
All Implemented Interfaces:
SparkWriter

public class SONWriter
extends java.lang.Object
implements SparkWriter

This is a concrete implementation of SparkWriter. This will write out SPARK objects in the SON format. The way in which the classes of objects are translated into class names in SON is determined by the TypeFactory used with the writer.

Author:
olsen

Constructor Summary
SONWriter()
          This creates a new SONWriter.
SONWriter(java.lang.String[] typePackageList)
          This creates a new SONWriter.
SONWriter(java.lang.String[] typePackageList, java.io.OutputStream output)
          This creates a new SONWriter.
 
Method Summary
 void close()
          this will close the stream and flush any output buffers.
 void flush()
          This will flush the stream's buffers
 TypeFactory getTypeFactory()
          This will return the TypeFactory currently being used.
 boolean isPretty()
          This returns true if the output is being pretty printed for human consumption rather than condensed for files and network message uses.
 void setOutput(java.io.OutputStream output)
          This will set the OutputStream to which the data is to be written.
 void setPretty(boolean p)
          This tells the writer whether the output should be pretty-printed for human consumption or condensed for system communication or storage.
 void setTypeFactory(TypeFactory factory)
          This is the type factory to be used when converting internal Java classes into an external form.
 java.lang.String toString(SV value)
          This will write the value to a String.
 void write(SV value)
          This is the heart of the SparkWriter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SONWriter

public SONWriter()
This creates a new SONWriter. It will have TypeFactorySimple (just SObj and SArray objects) as its factory and pretty printing will be turned on.


SONWriter

public SONWriter(java.lang.String[] typePackageList)
This creates a new SONWriter. It will have a TypeFactoryReflect (allows subclasses of SO) as its factory. Pretty printing will be turned on.

Parameters:
typePackageList - this is the restricted list of packages from which objects can be written. See TypeFactoryReflect for complete documentation on the package list.

SONWriter

public SONWriter(java.lang.String[] typePackageList,
                 java.io.OutputStream output)
This creates a new SONWriter. It will have a TypeFactoryReflect (allows subclasses of SO) as its factory. Pretty printing will be turned on.

Parameters:
typePackageList - this is the restricted list of packages from which objects can be written. See TypeFactoryReflect for complete documentation on the package list.
output - this is the output stream to which the SON is to be written.
Method Detail

setTypeFactory

public void setTypeFactory(TypeFactory factory)
Description copied from interface: SparkWriter
This is the type factory to be used when converting internal Java classes into an external form.

Specified by:
setTypeFactory in interface SparkWriter
Parameters:
factory - the type factory to be used.

getTypeFactory

public TypeFactory getTypeFactory()
Description copied from interface: SparkWriter
This will return the TypeFactory currently being used.

Specified by:
getTypeFactory in interface SparkWriter
Returns:
a TypeFactory

setOutput

public void setOutput(java.io.OutputStream output)
Description copied from interface: SparkWriter
This will set the OutputStream to which the data is to be written.

Specified by:
setOutput in interface SparkWriter
Parameters:
output - where the output is to be sent.

write

public void write(SV value)
Description copied from interface: SparkWriter
This is the heart of the SparkWriter. This method will write the value in an external form to the Output

Specified by:
write in interface SparkWriter
Parameters:
value - the value to be written.

toString

public java.lang.String toString(SV value)
Description copied from interface: SparkWriter
This will write the value to a String. This is useful for short values the can be printed to the console or used in some other fashion.

Specified by:
toString in interface SparkWriter
Parameters:
value - the value to be written out.
Returns:
The string representation of the value.

isPretty

public boolean isPretty()
Description copied from interface: SparkWriter
This returns true if the output is being pretty printed for human consumption rather than condensed for files and network message uses.

Specified by:
isPretty in interface SparkWriter
Returns:
whether or not pretty printed indentation is set.

setPretty

public void setPretty(boolean p)
Description copied from interface: SparkWriter
This tells the writer whether the output should be pretty-printed for human consumption or condensed for system communication or storage. This is just a suggestion to the writer. The syntax remains the same either way. The common use for this is if pretty is false, extraneous white spaces are removed.

Specified by:
setPretty in interface SparkWriter
Parameters:
p - true if the output is for human consumption.

close

public void close()
Description copied from interface: SparkWriter
this will close the stream and flush any output buffers.

Specified by:
close in interface SparkWriter

flush

public void flush()
Description copied from interface: SparkWriter
This will flush the stream's buffers

Specified by:
flush in interface SparkWriter