Class CsvDataSetWriter

java.lang.Object
org.dbunit.dataset.csv.CsvDataSetWriter
All Implemented Interfaces:
IDataSetConsumer

public class CsvDataSetWriter extends Object implements IDataSetConsumer
IDataSetConsumer that writes a dataset's tables and rows to CSV files.
Since:
24-set-2003 15.27.05
Version:
$Revision$
Author:
fede
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    todo: customizable separators (field, lines), manage the writers opened for each table
  • Constructor Summary

    Constructors
    Constructor
    Description
    CsvDataSetWriter(File theDirectory)
    Creates a writer that writes CSV files to the given directory.
    CsvDataSetWriter(String theDirectory)
    Creates a writer that writes CSV files to the given directory.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Receive notification of the end of a dataset.
    void
    Receive notification of the end of a table.
    protected static String
    escape(String stringValue)
    Escapes quote and backslash characters in the given string by prefixing them with a backslash.
    protected void
     
    Returns the directory CSV files are written to.
    Returns the writer for the currently active table.
    void
    row(Object[] values)
    Receive notification of a table row.
    void
    setTheDirectory(String theDirectory)
    Sets the directory CSV files are written to.
    void
    setWriter(Writer writer)
    Sets the writer for the currently active table.
    void
    Receive notification of the beginning of a dataset.
    void
    Receive notification of the beginning of a table.
    void
    write(IDataSet dataSet)
    Writes the given dataset's tables and rows to CSV files.
    static void
    write(IDataSet dataset, File dest)
    Writes the given dataset's tables and rows as CSV files to the given directory.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NULL

      public static final String NULL
      todo: customizable separators (field, lines), manage the writers opened for each table
      See Also:
  • Constructor Details

    • CsvDataSetWriter

      public CsvDataSetWriter(String theDirectory)
      Creates a writer that writes CSV files to the given directory.
      Parameters:
      theDirectory - the path of the directory to write CSV files to.
    • CsvDataSetWriter

      public CsvDataSetWriter(File theDirectory)
      Creates a writer that writes CSV files to the given directory.
      Parameters:
      theDirectory - the directory to write CSV files to.
  • Method Details

    • write

      public void write(IDataSet dataSet) throws DataSetException
      Writes the given dataset's tables and rows to CSV files.
      Parameters:
      dataSet - the dataset to write.
      Throws:
      DataSetException - if writing the dataset fails.
    • startDataSet

      public void startDataSet() throws DataSetException
      Receive notification of the beginning of a dataset. This method is invoked only once, before any other methods in this interface.
      Specified by:
      startDataSet in interface IDataSetConsumer
      Throws:
      DataSetException - if the notification cannot be processed.
    • endDataSet

      public void endDataSet() throws DataSetException
      Receive notification of the end of a dataset. This method is invoked only once, and it will be the last method invoked in this interface.
      Specified by:
      endDataSet in interface IDataSetConsumer
      Throws:
      DataSetException - if the notification cannot be processed.
    • startTable

      public void startTable(ITableMetaData metaData) throws DataSetException
      Receive notification of the beginning of a table. This method is invoked at the beginning of every table in the dataset; there will be a corresponding IDataSetConsumer.endDataSet() event for every startTable event (even when the table is empty).
      Specified by:
      startTable in interface IDataSetConsumer
      Parameters:
      metaData - the table metadata
      Throws:
      DataSetException - if the notification cannot be processed.
    • endTable

      public void endTable() throws DataSetException
      Description copied from interface: IDataSetConsumer
      Receive notification of the end of a table.
      Specified by:
      endTable in interface IDataSetConsumer
      Throws:
      DataSetException - if the notification cannot be processed.
    • row

      public void row(Object[] values) throws DataSetException
      Description copied from interface: IDataSetConsumer
      Receive notification of a table row. This method is invoked to report each row of a table.
      Specified by:
      row in interface IDataSetConsumer
      Parameters:
      values - The row values.
      Throws:
      DataSetException - if the notification cannot be processed.
    • escape

      protected static String escape(String stringValue)
      Escapes quote and backslash characters in the given string by prefixing them with a backslash.
      Parameters:
      stringValue - the string to escape.
      Returns:
      the escaped string.
    • getWriter

      public Writer getWriter()
      Returns the writer for the currently active table.
      Returns:
      the writer for the currently active table.
    • setWriter

      public void setWriter(Writer writer)
      Sets the writer for the currently active table.
      Parameters:
      writer - the writer for the currently active table.
    • getTheDirectory

      public String getTheDirectory()
      Returns the directory CSV files are written to.
      Returns:
      the directory CSV files are written to.
    • setTheDirectory

      public void setTheDirectory(String theDirectory)
      Sets the directory CSV files are written to.
      Parameters:
      theDirectory - the directory CSV files are written to.
    • write

      public static void write(IDataSet dataset, File dest) throws DataSetException
      Writes the given dataset's tables and rows as CSV files to the given directory.
      Parameters:
      dataset - the dataset to write.
      dest - the directory to write CSV files to.
      Throws:
      DataSetException - if writing the dataset fails.
    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable