java.lang.Objectcom.screenscraper.csv.CsvWriter
public class CsvWriter
Basic Usage:
CsvWriter writer = new CsvWriter( "somefile.csv" );
writer.setHeaderRow( String[] );
writer.writeNext( String[] );
writer.close();
| Constructor Summary | |
|---|---|
CsvWriter(java.lang.String filePath)
Constructs CSVWriter with the given filePath as the output file |
|
CsvWriter(java.lang.String filePath,
boolean addTimeStamp)
Constructs CSVWriter with the given filePath If the timestamp is set to true, a timestamp will be added to the given filename (yyyy-MM-dd'T'hh'H'mm'M'ss'S') |
|
CsvWriter(java.lang.String filePath,
char separator)
Constructs CSVWriter with the given filePath and separator. |
|
CsvWriter(java.lang.String filePath,
char separator,
boolean addTimeStamp)
Constructs CSVWriter with the given filePath and separator If the timestamp is set to true, a timestamp will be added to the given filename (yyyy-MM-dd'T'hh'H'mm'M'ss'S') |
|
CsvWriter(java.lang.String filePath,
char separator,
char quotechar)
Constructs CSVWriter with the given filePath, separator and quotchar |
|
CsvWriter(java.lang.String filePath,
char separator,
char quotechar,
char escapechar)
Constructs CSVWriter with the given filePath, separator, quote character and escape character |
|
CsvWriter(java.lang.String filePath,
char separator,
char quotechar,
char escapechar,
java.lang.String lineEnd)
Constructs CSVWriter with supplied separator, quote char, escape char and line ending. |
|
CsvWriter(java.lang.String filePath,
char separator,
char quotechar,
java.lang.String lineEnd)
Constructs CSVWriter with the given filePath, separator, quote character, escape character and line end character |
|
| Method Summary | |
|---|---|
void |
close()
Close the underlying stream writer flushing any buffered content. |
void |
flush()
Flush underlying stream to writer. |
java.lang.String |
getCsvPath()
Returns the path of the file being written to. |
java.lang.String[] |
getHeaderRow()
Returns the header row |
java.lang.String[] |
getMappingLabels()
Returns the mapping labels |
void |
setHeader(java.lang.String[] header)
Sets the header row to the given String[] and also sets mapping Values to the same String[] The header is only written if the file doesn't originally exist when writing to it. |
void |
setMapValues(java.lang.String[] mapVals)
Set the values used to map the key values of a Map |
void |
setMapValuesAndLowercaseUnderscore(java.lang.String[] mapVals)
Set the mapping values with the given String[], but convert them to lowercase and underscores for spaces eg. |
void |
setMapValuesAndUnderscore(java.lang.String[] mapVals)
Set the mapping values with the given String[], but convert them to have underscores for spaces eg. |
void |
setMapValuesAndUppercaseUnderscore(java.lang.String[] mapVals)
Set the mapping values with the given String[], but convert them to uppercase and underscores for spaces eg. |
void |
write(java.util.List nextLine)
Writes the next line to the file. |
void |
write(java.util.Map nextLine)
Writes the next line to the file. |
void |
write(java.lang.String[] nextLine)
Writes the next line to the file. |
void |
writeAll(DataSet set)
Writes all the dataRecords in the set to the CSV (The map values must be set for this to work) |
void |
writeAll(java.util.List lines)
Writes the entire list to a CSV file. |
void |
writeAll(java.sql.ResultSet rs,
boolean includeColumnNames)
Writes the entire ResultSet to a CSV file. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CsvWriter(java.lang.String filePath)
throws java.io.IOException
filePath - the filepath for the underlying CSV source.
java.io.IOException
public CsvWriter(java.lang.String filePath,
char separator)
throws java.io.IOException
filePath - the filepath for the underlying CSV source.separator - the delimiter to use for separating entries.
java.io.IOException
public CsvWriter(java.lang.String filePath,
boolean addTimeStamp)
throws java.io.IOException
filePath - the filepath for the underlying CSV source.addTimeStamp - whether to add a current time stamp to the filename
java.io.IOException
public CsvWriter(java.lang.String filePath,
char separator,
boolean addTimeStamp)
throws java.io.IOException
filePath - the filepath for the underlying CSV source.separator - the delimiter to use for separating entries.addTimeStamp - whether to add a current time stamp to the filename
java.io.IOException
public CsvWriter(java.lang.String filePath,
char separator,
char quotechar)
throws java.io.IOException
filePath - the filepath for the underlying CSV source.separator - the delimiter to use for separating entriesquotechar - the character to use for quoted elements
java.io.IOException
public CsvWriter(java.lang.String filePath,
char separator,
char quotechar,
char escapechar)
throws java.io.IOException
filePath - the filepath for the underlying CSV source.separator - the delimiter to use for separating entriesquotechar - the character to use for quoted elementsescapechar - the character to use for escaping quotechars or escapechars
java.io.IOException
public CsvWriter(java.lang.String filePath,
char separator,
char quotechar,
java.lang.String lineEnd)
throws java.io.IOException
filePath - the filepath for the underlying CSV source.separator - the delimiter to use for separating entriesquotechar - the character to use for quoted elementslineEnd - the line feed terminator to use
java.io.IOException
public CsvWriter(java.lang.String filePath,
char separator,
char quotechar,
char escapechar,
java.lang.String lineEnd)
throws java.io.IOException
filePath - the filepath for the underlying CSV source.separator - the delimiter to use for separating entriesquotechar - the character to use for quoted elementsescapechar - the character to use for escaping quotechars or escapecharslineEnd - the line feed terminator to use
java.io.IOException| Method Detail |
|---|
public void setHeader(java.lang.String[] header)
header - public void setMapValues(java.lang.String[] mapVals)
mapVals - public void setMapValuesAndUppercaseUnderscore(java.lang.String[] mapVals)
mapVals - public void setMapValuesAndLowercaseUnderscore(java.lang.String[] mapVals)
mapVals - public void setMapValuesAndUnderscore(java.lang.String[] mapVals)
mapVals - public void writeAll(java.util.List lines)
public void writeAll(DataSet set)
set - public void write(java.util.List nextLine)
nextLine - a list of Strings with each comma-separated element as a separate entry.public void write(java.util.Map nextLine)
nextLine - a map of String => Stringpublic void write(java.lang.String[] nextLine)
nextLine - a string array with each comma-separated element as a separate entry.
public void flush()
throws java.io.IOException
java.io.IOException - if bad things happen
public void close()
throws java.io.IOException
java.io.IOException - if bad things happen
public void writeAll(java.sql.ResultSet rs,
boolean includeColumnNames)
throws java.sql.SQLException,
java.io.IOException
rs - the recordset to writeincludeColumnNames - true if you want column names in the output, false otherwise
java.sql.SQLException
java.io.IOExceptionpublic java.lang.String getCsvPath()
public java.lang.String[] getHeaderRow()
public java.lang.String[] getMappingLabels()