Class ColumnQuoteMode

java.lang.Object
org.supercsv.quote.ColumnQuoteMode
All Implemented Interfaces:
QuoteMode

public class ColumnQuoteMode extends Object implements QuoteMode
When using ColumnQuoteMode surrounding quotes are only applied if required to escape special characters (per RFC4180), or if a particular column should always be quoted.
Since:
2.1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Set<Integer>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    ColumnQuoteMode(boolean[] columnsToQuote)
    Constructs a new ColumnQuoteMode that quotes columns if the element representing that column in the supplied array is true.
    ColumnQuoteMode(int... columnsToQuote)
    Constructs a new ColumnQuoteMode that quotes columns by column number.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    quotesRequired(String csvColumn, CsvContext context, CsvPreference preference)
    Determines whether surrounding quotes are mandatory in cases where the CSV column would not normally be quoted (the data to be written doesn't contain special characters).

    Methods inherited from class java.lang.Object

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

    • columnNumbers

      private final Set<Integer> columnNumbers
  • Constructor Details

    • ColumnQuoteMode

      public ColumnQuoteMode(int... columnsToQuote)
      Constructs a new ColumnQuoteMode that quotes columns by column number. If no column numbers are supplied (i.e. no parameters) then quoting will be determined per RFC4180.
      Parameters:
      columnsToQuote - the column numbers to quote
    • ColumnQuoteMode

      public ColumnQuoteMode(boolean[] columnsToQuote)
      Constructs a new ColumnQuoteMode that quotes columns if the element representing that column in the supplied array is true. Please note that false doesn't disable quoting, it just means that quoting is determined by RFC4180.
      Parameters:
      columnsToQuote - array of booleans (one per CSV column) indicating whether each column should be quoted or not
      Throws:
      NullPointerException - if columnsToQuote is null
  • Method Details

    • quotesRequired

      public boolean quotesRequired(String csvColumn, CsvContext context, CsvPreference preference)
      Determines whether surrounding quotes are mandatory in cases where the CSV column would not normally be quoted (the data to be written doesn't contain special characters).
      Specified by:
      quotesRequired in interface QuoteMode
      Parameters:
      csvColumn - an element of a CSV file
      context - the context
      preference - the CSV preferences
      Returns:
      true if surrounding quotes are mandatory, otherwise false