Class DelimitedWriter

java.lang.Object
org.jacoco.report.csv.DelimitedWriter

class DelimitedWriter extends Object
Helper class for writing out CSV or tab delimited files.

Example Usage:

 delimitedWriter.writeFields("header1", "header2", ...);
 for each line to be written {
   delimitedWriter.writeField(value1);
   delimitedWriter.writeField(value2);
   delimitedWriter.nextLine();
 }
 delimitedWriter.close();
 

  • Field Details

  • Constructor Details

    • DelimitedWriter

      public DelimitedWriter(Writer delegate)
      Creates a new Delimited writer using the default delimiter
      Parameters:
      delegate - Writer to delegate all writes to
    • DelimitedWriter

      public DelimitedWriter(Writer delegate, char delimiter)
      Creates a new Delimited writer using the default delimiter
      Parameters:
      delegate - Writer to delegate all writes to
      delimiter - delimiter to use (usually a comma, tab or space)
  • Method Details

    • write

      public void write(String... fields) throws IOException
      Write multiple fields at once. Values will be auto escaped and quoted as needed. Each value will be separated using the current delimiter
      Parameters:
      fields - Values to write
      Throws:
      IOException - Error writing to the underlying writer object
    • write

      public void write(String field) throws IOException
      Write a single value. Values will be auto escaped and quoted as needed. If this is not the first field of the current line the value will be prepended with the current delimiter
      Parameters:
      field - Value to write
      Throws:
      IOException - Error writing to the underlying writer object
    • write

      public void write(int value) throws IOException
      Write a single integer value.
      Parameters:
      value - Value to write
      Throws:
      IOException - Error writing to the underlying writer object
    • write

      public void write(int... values) throws IOException
      Write muliple integer values
      Parameters:
      values - values to write
      Throws:
      IOException - Error writing to the underlying writer object
    • nextLine

      public void nextLine() throws IOException
      Output a new line and advance the writer to the next line. The line delimiter is the default for the platform.
      Throws:
      IOException - Error writing to the underlying writer object
    • close

      public void close() throws IOException
      Close the underlying writer object. Once closed all write operations will fail
      Throws:
      IOException - Error closing the underlying writer object
    • escape

      private String escape(String value)
      Escapes any occurrences of the quote character in value by replacing it with a double quote. Also Quotes the value if a quote or delimiter value is found.
      Parameters:
      value - String that needs escaping
      Returns:
      New string with all values escaped