spark.data.io
Class JSONReader

java.lang.Object
  extended by spark.data.io.JSONReader
All Implemented Interfaces:
SparkReader

public class JSONReader
extends java.lang.Object
implements SparkReader

This is a concrete implementation of SparkReader that will read text sources in the JSON format.

Author:
olsen

Constructor Summary
JSONReader()
          This creates a new JSONReader.
JSONReader(java.lang.String input)
          This creates a new JSONReader.
JSONReader(java.lang.String[] typePackageList)
          This creates a new JSONReader.
JSONReader(java.lang.String[] typePackageList, java.io.InputStream input)
          This creates a new JSONReader.
JSONReader(java.lang.String[] typePackageList, java.lang.String input)
          This creates a new JSONReader.
 
Method Summary
 TypeFactory getTypeFactory()
          This will return the TypeFactory being used.
 SV read()
          This is the heart of the reader.
 void setSource(java.io.InputStream source)
          This will set the source from which objects are to be read.
 void setSource(java.lang.String source)
          This will set a string from which objects can be read.
 void setTypeFactory(TypeFactory factory)
          This will set the TypeFactory to be used in constructing objects based on what is read from the external form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONReader

public JSONReader()
This creates a new JSONReader. It will have TypeFactorySimple (just SObj and SArray objects) as its factory.


JSONReader

public JSONReader(java.lang.String[] typePackageList)
This creates a new JSONReader. It will have a TypeFactoryReflect (allows subclasses of SO) as its factory.

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

JSONReader

public JSONReader(java.lang.String[] typePackageList,
                  java.io.InputStream input)
This creates a new JSONReader. 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.
input - this is the input stream from which the JSON is to be read.

JSONReader

public JSONReader(java.lang.String input)
This creates a new JSONReader. It will have TypeFactorySimple (just SObj and SArray objects) as its factory.

Parameters:
input - a string from which the JSON object is to be read.

JSONReader

public JSONReader(java.lang.String[] typePackageList,
                  java.lang.String input)
This creates a new JSONReader. 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.
input - this is the string from which JSON objects are read.
Method Detail

setTypeFactory

public void setTypeFactory(TypeFactory factory)
Description copied from interface: SparkReader
This will set the TypeFactory to be used in constructing objects based on what is read from the external form.

Specified by:
setTypeFactory in interface SparkReader
Parameters:
factory - the factory to be used in translating type names into objects

getTypeFactory

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

Specified by:
getTypeFactory in interface SparkReader
Returns:
a TypeFactory

setSource

public void setSource(java.io.InputStream source)
Description copied from interface: SparkReader
This will set the source from which objects are to be read.

Specified by:
setSource in interface SparkReader
Parameters:
source - an input stream from which to read objects.

setSource

public void setSource(java.lang.String source)
Description copied from interface: SparkReader
This will set a string from which objects can be read.

Specified by:
setSource in interface SparkReader
Parameters:
source - the source string from which objects can be read

read

public SV read()
Description copied from interface: SparkReader
This is the heart of the reader. This is where an object or any Spark value is read from the source.

Specified by:
read in interface SparkReader
Returns:
the value that was read or null if there were no values left in the source.