|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.otfeed.support.CSVDataWriter
public class CSVDataWriter
Class that provides CSV formatting for Java POJO beans.
Simplest usage is:IDataWriter writer = new CSVDataWriter(OTTrade.class);which creates a writer to output
OTTrade
properties in a CSV
format. Note that only objects of one class (used in constructor)
can be written. Attempts to write a different object will
yield a runtime exception.
More advanced usage is:
Listwhich creates a writer that outputs only listed properties ofpropertiesList = new LinkedList (); propertiesList.add("timestamp"); propertiesList.add("openPrice"); propertiesList.add("closePrice"); propertiesList.add("volume"); IDataWriter writer = new CSVDatWriter(OOHLC.class, propertiesList);
OTOHLC
object.
Typically, this object will be used in conjunction with
CommonListener
or another class that implements an appropriate
event listener using IDataWriter
as the event sink.
Constructor Summary | |
---|---|
CSVDataWriter(java.lang.Class<?> cls)
Creates new CSVDataWriter to write objects of a given class. |
|
CSVDataWriter(java.lang.Class<?> cls,
java.util.List<java.lang.String> list)
Creates new CSVDataWriter to write listed properties of a given class. |
Method Summary | |
---|---|
void |
close()
Closes the writer stream. |
java.util.Map<java.lang.Class<?>,IFormat<java.lang.Object>> |
getCustomPropertyFormatter()
Allows to customize how properties are being formatted. |
java.lang.String |
getDelimeter()
Delimeter, used to separate properties. |
java.io.PrintWriter |
getPrintWriter()
Determines the output destination. |
boolean |
isHeaders()
Determines whether CVS output strats with list of properties. |
void |
setCustomPropertyFormatter(java.util.Map<java.lang.Class<?>,IFormat<java.lang.Object>> val)
Sets dictionary of custom property formatters. |
void |
setDelimeter(java.lang.String val)
Sets delimeter. |
void |
setHeaders(java.lang.Boolean val)
Sets headers flag. |
void |
setPrintWriter(java.io.PrintWriter val)
Sets output destination. |
void |
writeData(java.lang.String id,
java.lang.Object data)
Writes data out, including optional id string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CSVDataWriter(java.lang.Class<?> cls, java.util.List<java.lang.String> list)
cls
- type of the objects to be written.list
- list of property names. This is useful
if you want to get control over which properties
are included. It allows to skip some properties,
specify the exact order of properties in the CSV
line, or output a single property more than once.public CSVDataWriter(java.lang.Class<?> cls)
headers
property
to OFF is not recommended.
If you need full control over which properties are written out,
and in what order, use CSVDataWriter(Class, List)
constructor.
cls
- type of the objects to be written.Method Detail |
---|
public java.lang.String getDelimeter()
public void setDelimeter(java.lang.String val)
val
- delimeter string.public java.util.Map<java.lang.Class<?>,IFormat<java.lang.Object>> getCustomPropertyFormatter()
CSVDataWriter writer = ...; writer.getCustomPropertyFormatter().put(Date.class, new DateFormat("MM/dd/yyyy"));
public void setCustomPropertyFormatter(java.util.Map<java.lang.Class<?>,IFormat<java.lang.Object>> val)
val
- formatters dictionary.public boolean isHeaders()
true
.
public void setHeaders(java.lang.Boolean val)
val
- headers flag value.public java.io.PrintWriter getPrintWriter()
public void setPrintWriter(java.io.PrintWriter val)
val
- output destination.public void writeData(java.lang.String id, java.lang.Object data)
IDataWriter
writeData
in interface IDataWriter
id
- string, identifying the quote source.data
- quote data.public void close()
close
in interface IDataWriter
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |