java.lang.Object
com.inductiveautomation.ignition.common.util.csv.CSVWriter
All Implemented Interfaces:
Closeable, AutoCloseable

public class CSVWriter extends Object implements Closeable
A very simple CSV writer released under a commercial-friendly license.
  • Field Details

    • INITIAL_STRING_SIZE

      public static final int INITIAL_STRING_SIZE
      See Also:
    • DEFAULT_ESCAPE_CHARACTER

      public static final char DEFAULT_ESCAPE_CHARACTER
      The character used for escaping quotes.
      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:
    • 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_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 quotechars or escapechars
    • 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, quote char, escape char and line ending.
      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 quotechars or escapechars
      lineEnd - the line feed terminator to use
  • Method Details

    • writeAll

      public void writeAll(List<String[]> allLines)
      Writes the entire list to a CSV file. The list is assumed to be a String[]
      Parameters:
      allLines - a List of String[], with each String[] representing a line of the file.
    • writeColumnNames

      protected void writeColumnNames(ResultSet rs) throws SQLException
      Throws:
      SQLException
    • writeAll

      public void writeAll(ResultSet rs, boolean includeColumnNames) throws SQLException, IOException
      Writes the entire ResultSet to a CSV file.

      The caller is responsible for closing the ResultSet.

      Parameters:
      rs - the recordset to write
      includeColumnNames - true if you want column names in the output, false otherwise
      Throws:
      IOException - thrown by getColumnValue
      SQLException - thrown by getColumnValue
    • writeNext

      public void writeNext(List<String> nextLine)
    • writeNext

      public void writeNext(String[] nextLine)
      Writes the next line to the file.
      Parameters:
      nextLine - a string array with each comma-separated element as a separate entry.
    • processLine

      protected StringBuilder processLine(String nextElement)
    • flush

      public void flush() throws IOException
      Flush underlying stream to writer.
      Throws:
      IOException - if bad things happen
    • 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
    • checkError

      public boolean checkError()
      Checks to see if the there has been an error in the printstream.
    • setResultService

      public void setResultService(ResultSetHelper resultService)