org.apache.pivot.serialization
Class CSVSerializer

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

public class CSVSerializer
extends Object
implements Serializer<List<?>>

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


Field Summary
static int BUFFER_SIZE
           
static String CSV_EXTENSION
           
static String DEFAULT_CHARSET_NAME
           
static Type DEFAULT_ITEM_TYPE
           
static String MIME_TYPE
           
 
Constructor Summary
CSVSerializer()
           
CSVSerializer(Charset charset)
           
CSVSerializer(Charset charset, Type itemType)
           
CSVSerializer(Type itemType)
           
 
Method Summary
 Charset getCharset()
          Returns the character set used to encode/decode the CSV data.
 ListenerList<CSVSerializerListener> getCSVSerializerListeners()
           
 Type getItemType()
          Returns the type of the item that will be instantiated by the serializer during a read operation.
 Sequence<String> getKeys()
          Returns the keys that will be read or written by this serializer.
 String getMIMEType(List<?> objects)
          Returns the MIME type of the data read and written by this serializer.
 boolean getWriteKeys()
          Returns the serializer's write keys flag.
 boolean isVerbose()
          Returns the serializer's verbosity flag.
 List<?> readObject(InputStream inputStream)
          Reads values from a comma-separated value stream.
 List<?> readObject(Reader reader)
          Reads values from a comma-separated value stream.
 void setKeys(Sequence<String> keys)
          Sets the keys that will be read or written by this serializer.
 void setKeys(String... keys)
          Sets the keys that will be read or written by this serializer.
 void setVerbose(boolean verbose)
          Sets the serializer's verbosity flag.
 void setWriteKeys(boolean writeKeys)
          Sets the serializer's write keys flag.
 void writeObject(List<?> items, OutputStream outputStream)
          Writes values to a comma-separated value stream.
 void writeObject(List<?> items, 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

DEFAULT_CHARSET_NAME

public static final String DEFAULT_CHARSET_NAME
See Also:
Constant Field Values

DEFAULT_ITEM_TYPE

public static final Type DEFAULT_ITEM_TYPE

CSV_EXTENSION

public static final String CSV_EXTENSION
See Also:
Constant Field Values

MIME_TYPE

public static final 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(Charset charset)

CSVSerializer

public CSVSerializer(Type itemType)

CSVSerializer

public CSVSerializer(Charset charset,
                     Type itemType)
Method Detail

getCharset

public Charset getCharset()
Returns the character set used to encode/decode the CSV data.


getItemType

public Type getItemType()
Returns the type of the item that will be instantiated by the serializer during a read operation.


getKeys

public Sequence<String> getKeys()
Returns the keys that will be read or written by this serializer.


setKeys

public void setKeys(Sequence<String> keys)
Sets the keys that will be read or written by this serializer.

Parameters:
keys -

setKeys

public void setKeys(String... keys)
Sets the keys that will be read or written by this serializer.

Parameters:
keys -

getWriteKeys

public boolean getWriteKeys()
Returns the serializer's write keys flag.


setWriteKeys

public void setWriteKeys(boolean writeKeys)
Sets the serializer's write keys flag.

Parameters:
writeKeys - If true, the first line of the output will contain the keys. Otherwise, the first line will contain the first line of data.

isVerbose

public boolean isVerbose()
Returns the serializer's verbosity flag.


setVerbose

public void setVerbose(boolean verbose)
Sets the serializer's verbosity flag. When verbosity is enabled, all data read or written will be echoed to the console.

Parameters:
verbose -

readObject

public List<?> readObject(InputStream inputStream)
                   throws 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:
IOException
SerializationException
See Also:
readObject(Reader)

readObject

public List<?> readObject(Reader reader)
                   throws 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.

If no keys have been specified when this method is called, they are assumed to be defined in the first line of the file.

Throws:
IOException
SerializationException

writeObject

public void writeObject(List<?> items,
                        OutputStream outputStream)
                 throws 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:
IOException
SerializationException
See Also:
writeObject(List, Writer)

writeObject

public void writeObject(List<?> items,
                        Writer writer)
                 throws IOException
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:
IOException

getMIMEType

public 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.

getCSVSerializerListeners

public ListenerList<CSVSerializerListener> getCSVSerializerListeners()