pivot.serialization
Class CSVSerializer

java.lang.Object
  extended by pivot.serialization.CSVSerializer
All Implemented Interfaces:
Serializer<List<?>>

public class CSVSerializer
extends java.lang.Object
implements Serializer<List<?>>

Implementation of the Serializer interface that reads data from and writes data to a comma-separated value (CSV) file.

TODO Add "firstLineContainsKeys" flag.

TODO Add support for variable delimiters.

Author:
gbrown

Nested Class Summary
 class CSVSerializer.KeySequence
          Class representing the serializers key sequence.
 
Field Summary
static int BUFFER_SIZE
           
static java.lang.String MIME_TYPE
           
 
Constructor Summary
CSVSerializer()
           
CSVSerializer(java.nio.charset.Charset charset)
           
CSVSerializer(java.lang.String charsetName)
           
 
Method Summary
 java.lang.Class<?> getItemClass()
          Returns the item class that will be instantiated by the serializer during a read operation.
 CSVSerializer.KeySequence getKeys()
          Returns a sequence representing the fields that will be read or written by this serializer.
 java.lang.String getMIMEType(List<?> objects)
          Returns the MIME type of the data read and written by this serializer.
 List<?> readObject(java.io.InputStream inputStream)
          Reads values from a comma-separated value stream.
 List<?> readObject(java.io.Reader reader)
          Reads values from a comma-separated value stream.
 void setItemClass(java.lang.Class<?> itemClass)
          Sets the item class that will be instantiated by the serializer during a read operation.
 void writeObject(List<?> items, java.io.OutputStream outputStream)
          Writes values to a comma-separated value stream.
 void writeObject(List<?> items, java.io.Writer writer)
          Writes values to a comma-separated value stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIME_TYPE

public static final java.lang.String MIME_TYPE
See Also:
Constant Field Values

BUFFER_SIZE

public static final int BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

CSVSerializer

public CSVSerializer()

CSVSerializer

public CSVSerializer(java.lang.String charsetName)

CSVSerializer

public CSVSerializer(java.nio.charset.Charset charset)
Method Detail

getKeys

public CSVSerializer.KeySequence getKeys()
Returns a sequence representing the fields that will be read or written by this serializer.


getItemClass

public java.lang.Class<?> getItemClass()
Returns the item class that will be instantiated by the serializer during a read operation.


setItemClass

public void setItemClass(java.lang.Class<?> itemClass)
Sets the item class that will be instantiated by the serializer during a read operation. The class must implement the Dictionary interface.


readObject

public List<?> readObject(java.io.InputStream inputStream)
                   throws java.io.IOException,
                          SerializationException
Reads values from a comma-separated value stream.

Specified by:
readObject in interface Serializer<List<?>>
Parameters:
inputStream - The input stream from which data will be read.
Returns:
The deserialized object.
Throws:
java.io.IOException
SerializationException
See Also:
readObject(Reader)

readObject

public List<?> readObject(java.io.Reader reader)
                   throws java.io.IOException,
                          SerializationException
Reads values from a comma-separated value stream.

Parameters:
reader - The reader from which data will be read.
Returns:
A list containing the data read from the CSV file. The list items are instances of Dictionary populated by mapping columns in the CSV file to keys in the key sequence.
Throws:
java.io.IOException
SerializationException

writeObject

public void writeObject(List<?> items,
                        java.io.OutputStream outputStream)
                 throws java.io.IOException,
                        SerializationException
Writes values to a comma-separated value stream.

Specified by:
writeObject in interface Serializer<List<?>>
Parameters:
items -
outputStream - The output stream to which data will be written.
Throws:
java.io.IOException
SerializationException
See Also:
writeObject(List, Writer)

writeObject

public void writeObject(List<?> items,
                        java.io.Writer writer)
                 throws java.io.IOException,
                        SerializationException
Writes values to a comma-separated value stream.

Parameters:
items - A list containing the data to write to the CSV file. List items must be instances of Dictionary. The dictionary values will be written out in the order specified by the key sequence.
writer - The writer to which data will be written.
Throws:
java.io.IOException
SerializationException

getMIMEType

public java.lang.String getMIMEType(List<?> objects)
Description copied from interface: Serializer
Returns the MIME type of the data read and written by this serializer.

Specified by:
getMIMEType in interface Serializer<List<?>>
Parameters:
objects - If provided, allows the serializer to attach parameters to the returned MIME type containing more detailed information about the data. If null, the base MIME type is returned.