Class CSVWriter

java.lang.Object
scriptella.driver.csv.opencsv.CSVWriter
All Implemented Interfaces:
Closeable, AutoCloseable

public class CSVWriter extends Object implements Closeable
A very simple CSV writer released under a commercial-friendly license.
Author:
Glen Smith, Fyodor Kupolov, Sean Summers
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final char
    The default character used for escaping quotes.
    static final String
    Default line terminator uses platform encoding.
    static final char
    The default quote character to use if none is supplied to the constructor.
    static final char
    The default separator to use if none is supplied to the constructor.
    static final char
    The escape constant to use when you wish to suppress all escaping.
    static final char
    The quote constant to use when you wish to suppress all quoting.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CSVWriter(Writer writer)
    Constructs CSVWriter using a comma for the separator.
    CSVWriter(Writer writer, char separator)
    Constructs CSVWriter with supplied separator.
    CSVWriter(Writer writer, char separator, char quotechar)
    Constructs CSVWriter with supplied separator and quote char.
    CSVWriter(Writer writer, char separator, char quotechar, char escapechar)
    Constructs CSVWriter with supplied separator and quote char.
    CSVWriter(Writer writer, char separator, char quotechar, char escapechar, String lineEnd)
    Constructs CSVWriter with supplied separator and quote char.
    CSVWriter(Writer writer, char separator, char quotechar, String lineEnd)
    Constructs CSVWriter with supplied separator and quote char.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Close the underlying stream writer flushing any buffered content.
    void
    writeNext(String[] nextLine, boolean quoteall)
    Writes the next line to the file.

    Methods inherited from class java.lang.Object

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

    • DEFAULT_ESCAPE_CHARACTER

      public static final char DEFAULT_ESCAPE_CHARACTER
      The default character used for escaping quotes.
      See Also:
    • NO_ESCAPE_CHARACTER

      public static final char NO_ESCAPE_CHARACTER
      The escape constant to use when you wish to suppress all escaping.
      See Also:
    • DEFAULT_SEPARATOR

      public static final char DEFAULT_SEPARATOR
      The default separator to use if none is supplied to the constructor.
      See Also:
    • DEFAULT_QUOTE_CHARACTER

      public static final char DEFAULT_QUOTE_CHARACTER
      The default quote character to use if none is supplied to the constructor.
      See Also:
    • NO_QUOTE_CHARACTER

      public static final char NO_QUOTE_CHARACTER
      The quote constant to use when you wish to suppress all quoting.
      See Also:
    • DEFAULT_LINE_END

      public static final String DEFAULT_LINE_END
      Default line terminator uses platform encoding.
      See Also:
  • Constructor Details

    • CSVWriter

      public CSVWriter(Writer writer)
      Constructs CSVWriter using a comma for the separator.
      Parameters:
      writer - the writer to an underlying CSV source.
    • CSVWriter

      public CSVWriter(Writer writer, char separator)
      Constructs CSVWriter with supplied separator.
      Parameters:
      writer - the writer to an underlying CSV source.
      separator - the delimiter to use for separating entries.
    • CSVWriter

      public CSVWriter(Writer writer, char separator, char quotechar)
      Constructs CSVWriter with supplied separator and quote char.
      Parameters:
      writer - the writer to an underlying CSV source.
      separator - the delimiter to use for separating entries
      quotechar - the character to use for quoted elements
    • CSVWriter

      public CSVWriter(Writer writer, char separator, char quotechar, char escapechar)
      Constructs CSVWriter with supplied separator and quote char.
      Parameters:
      writer - the writer to an underlying CSV source.
      separator - the delimiter to use for separating entries
      quotechar - the character to use for quoted elements
      escapechar - the character to use for escaping
    • CSVWriter

      public CSVWriter(Writer writer, char separator, char quotechar, String lineEnd)
      Constructs CSVWriter with supplied separator and quote char.
      Parameters:
      writer - the writer to an underlying CSV source.
      separator - the delimiter to use for separating entries
      quotechar - the character to use for quoted elements
      lineEnd - the line feed terminator to use
    • CSVWriter

      public CSVWriter(Writer writer, char separator, char quotechar, char escapechar, String lineEnd)
      Constructs CSVWriter with supplied separator and quote char.
      Parameters:
      writer - the writer to an underlying CSV source.
      separator - the delimiter to use for separating entries
      quotechar - the character to use for quoted elements
      lineEnd - the line feed terminator to use
  • Method Details

    • writeNext

      public void writeNext(String[] nextLine, boolean quoteall) throws IOException
      Writes the next line to the file.
      Parameters:
      nextLine - a string array with each comma-separated element as a separate entry.
      Throws:
      IOException - if I/O error occurs
    • close

      public void close() throws IOException
      Close the underlying stream writer flushing any buffered content.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if bad things happen