java.lang.Object
org.pentaho.reporting.libraries.base.util.CSVQuoter

public final class CSVQuoter extends Object
The CSVQuoter is a helper class to encode a string for the CSV file format.
Author:
Thomas Morgner.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new CSVQuoter, which uses a comma as the default separator.
    CSVQuoter(char separator)
    Creates a new CSVQuoter, which uses the defined separator.
    CSVQuoter(char separator, char quate)
    Creates a new CSVQuoter with the given separator and quoting character.
    CSVQuoter(char separator, char quate, boolean forceQuoting)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    doQuoting(String original)
    Encodes the string, so that the string can safely be used in CSV files.
    void
    doQuoting(String original, Writer writer)
    A streaming version of the quoting algorithm for more performance.
    char
    Returns the quoting character.
    char
    Gets the separator used in this quoter and the CSV file.
    undoQuoting(String nativeString)
    Decodes the string, so that all escape sequences get removed.

    Methods inherited from class java.lang.Object

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

    • CSVQuoter

      public CSVQuoter()
      Creates a new CSVQuoter, which uses a comma as the default separator.
    • CSVQuoter

      public CSVQuoter(char separator)
      Creates a new CSVQuoter, which uses the defined separator.
      Parameters:
      separator - the separator.
      Throws:
      NullPointerException - if the given separator is null.
    • CSVQuoter

      public CSVQuoter(char separator, char quate)
      Creates a new CSVQuoter with the given separator and quoting character.
      Parameters:
      separator - the separator
      quate - the quoting character
    • CSVQuoter

      public CSVQuoter(char separator, char quate, boolean forceQuoting)
  • Method Details

    • doQuoting

      public String doQuoting(String original)
      Encodes the string, so that the string can safely be used in CSV files. If the string does not need quoting, the original string is returned unchanged.
      Parameters:
      original - the unquoted string.
      Returns:
      The quoted string
    • doQuoting

      public void doQuoting(String original, Writer writer) throws IOException
      A streaming version of the quoting algorithm for more performance. Encodes the string, so that the string can safely be used in CSV files. If the string does not need quoting, the original string is returned unchanged.
      Parameters:
      original - the unquoted string.
      writer - the writer.
      Throws:
      IOException - if an IO error occured.
    • undoQuoting

      public String undoQuoting(String nativeString)
      Decodes the string, so that all escape sequences get removed. If the string was not quoted, then the string is returned unchanged.
      Parameters:
      nativeString - the quoted string.
      Returns:
      The unquoted string.
    • getSeparator

      public char getSeparator()
      Gets the separator used in this quoter and the CSV file.
      Returns:
      the separator (never null).
    • getQuate

      public char getQuate()
      Returns the quoting character.
      Returns:
      the quote character.