org.knime.base.node.io.csvwriter
Class CSVWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.BufferedWriter
          extended by org.knime.base.node.io.csvwriter.CSVWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class CSVWriter
extends BufferedWriter

Class to write a DataTable to an output stream.

Author:
Bernd Wiswedel, University of Konstanz

Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
CSVWriter(Writer writer)
          Creates a new writer with default settings.
CSVWriter(Writer writer, FileWriterSettings settings)
          Creates new instance which writes tables to the given writer class.
 
Method Summary
 String getLastWarningMessage()
          Returns a warning message from the last write action.
protected  FileWriterSettings getSettings()
           
 boolean hasWarningMessage()
           
protected  String quoteString(String data, boolean isNumerical)
          Returns a string that can be written out to the file that is treated (with respect to quotes) according to the current settings.
protected  String replaceAndQuote(String data)
          Replaces the quote end pattern contained in the string and puts quotes around the string.
protected  String replaceSeparator(String data)
          Derives a string from the input string that has all appearances of the separator replaced with the specified replacer string.
 void write(DataTable table, ExecutionMonitor exec)
          Writes table with current settings.
 
Methods inherited from class java.io.BufferedWriter
close, flush, newLine, write, write, write
 
Methods inherited from class java.io.Writer
append, append, append, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVWriter

public CSVWriter(Writer writer)
Creates a new writer with default settings.

Parameters:
writer - the writer to write the table to.

CSVWriter

public CSVWriter(Writer writer,
                 FileWriterSettings settings)
Creates new instance which writes tables to the given writer class. An immediate write operation, will write the table headers (both column and row headers) and will write missing values as "" (empty string).

Parameters:
writer - to write to
settings - the object holding all settings, influencing how data tables are written to file.
Method Detail

getSettings

protected FileWriterSettings getSettings()
Returns:
the settings object that configures this writer. Modifying it influences its behavior.

write

public void write(DataTable table,
                  ExecutionMonitor exec)
           throws IOException,
                  CanceledExecutionException
Writes table with current settings.

Parameters:
table - the table to write to the file
exec - an execution monitor where to check for canceled status and report progress to. (In case of cancellation, the file will be deleted.)
Throws:
IOException - if any related I/O error occurs
CanceledExecutionException - if execution in exec has been canceled
NullPointerException - if table is null

quoteString

protected String quoteString(String data,
                             boolean isNumerical)
Returns a string that can be written out to the file that is treated (with respect to quotes) according to the current settings.

Parameters:
data - the string to quote/replaceQuotes/notQuote/etc.
isNumerical - set true, if the data comes from a numerical data cell
Returns:
the string correctly quoted according to the current settings.

replaceAndQuote

protected String replaceAndQuote(String data)
Replaces the quote end pattern contained in the string and puts quotes around the string.

Parameters:
data - the string to examine and change
Returns:
the input string with quotes around it and either replaced or escaped quote end patterns in the string.

replaceSeparator

protected String replaceSeparator(String data)
Derives a string from the input string that has all appearances of the separator replaced with the specified replacer string.

Parameters:
data - the string to examine and to replace the separator in.
Returns:
the input string with all appearances of the separator replaced.

hasWarningMessage

public boolean hasWarningMessage()
Returns:
true if a warning message is available

getLastWarningMessage

public String getLastWarningMessage()
Returns a warning message from the last write action. Or null, if there is no warning set.

Returns:
a warning message from the last write action. Or null, if there is no warning set.


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.