You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@commons.apache.org by gg...@apache.org on 2018/01/29 17:25:24 UTC

svn commit: r1024533 [22/46] - in /websites/production/commons/content/proper/commons-csv/archives/1.5: ./ apidocs/ apidocs/org/ apidocs/org/apache/ apidocs/org/apache/commons/ apidocs/org/apache/commons/csv/ apidocs/org/apache/commons/csv/class-use/ a...

Added: websites/production/commons/content/proper/commons-csv/archives/1.5/jacoco/org.apache.commons.csv/CSVFormat.java.html
==============================================================================
--- websites/production/commons/content/proper/commons-csv/archives/1.5/jacoco/org.apache.commons.csv/CSVFormat.java.html (added)
+++ websites/production/commons/content/proper/commons-csv/archives/1.5/jacoco/org.apache.commons.csv/CSVFormat.java.html Mon Jan 29 17:25:21 2018
@@ -0,0 +1,1952 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>CSVFormat.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Commons CSV</a> &gt; <a href="index.source.html" class="el_package">org.apache.commons.csv</a> &gt; <span class="el_source">CSVFormat.ja
 va</span></div><h1>CSVFormat.java</h1><pre class="source lang-java linenums">/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the &quot;License&quot;); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.csv;
+
+import static org.apache.commons.csv.Constants.BACKSLASH;
+import static org.apache.commons.csv.Constants.COMMA;
+import static org.apache.commons.csv.Constants.COMMENT;
+import static org.apache.commons.csv.Constants.EMPTY;
+import static org.apache.commons.csv.Constants.CR;
+import static org.apache.commons.csv.Constants.CRLF;
+import static org.apache.commons.csv.Constants.DOUBLE_QUOTE_CHAR;
+import static org.apache.commons.csv.Constants.LF;
+import static org.apache.commons.csv.Constants.PIPE;
+import static org.apache.commons.csv.Constants.SP;
+import static org.apache.commons.csv.Constants.TAB;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Serializable;
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Specifies the format of a CSV file and parses input.
+ *
+ * &lt;h2&gt;Using predefined formats&lt;/h2&gt;
+ *
+ * &lt;p&gt;
+ * You can use one of the predefined formats:
+ * &lt;/p&gt;
+ *
+ * &lt;ul&gt;
+ * &lt;li&gt;{@link #DEFAULT}&lt;/li&gt;
+ * &lt;li&gt;{@link #EXCEL}&lt;/li&gt;
+ * &lt;li&gt;{@link #MYSQL}&lt;/li&gt;
+ * &lt;li&gt;{@link #RFC4180}&lt;/li&gt;
+ * &lt;li&gt;{@link #TDF}&lt;/li&gt;
+ * &lt;/ul&gt;
+ *
+ * &lt;p&gt;
+ * For example:
+ * &lt;/p&gt;
+ *
+ * &lt;pre&gt;
+ * CSVParser parser = CSVFormat.EXCEL.parse(reader);
+ * &lt;/pre&gt;
+ *
+ * &lt;p&gt;
+ * The {@link CSVParser} provides static methods to parse other input types, for example:
+ * &lt;/p&gt;
+ *
+ * &lt;pre&gt;
+ * CSVParser parser = CSVParser.parse(file, StandardCharsets.US_ASCII, CSVFormat.EXCEL);
+ * &lt;/pre&gt;
+ *
+ * &lt;h2&gt;Defining formats&lt;/h2&gt;
+ *
+ * &lt;p&gt;
+ * You can extend a format by calling the {@code with} methods. For example:
+ * &lt;/p&gt;
+ *
+ * &lt;pre&gt;
+ * CSVFormat.EXCEL.withNullString(&amp;quot;N/A&amp;quot;).withIgnoreSurroundingSpaces(true);
+ * &lt;/pre&gt;
+ *
+ * &lt;h2&gt;Defining column names&lt;/h2&gt;
+ *
+ * &lt;p&gt;
+ * To define the column names you want to use to access records, write:
+ * &lt;/p&gt;
+ *
+ * &lt;pre&gt;
+ * CSVFormat.EXCEL.withHeader(&amp;quot;Col1&amp;quot;, &amp;quot;Col2&amp;quot;, &amp;quot;Col3&amp;quot;);
+ * &lt;/pre&gt;
+ *
+ * &lt;p&gt;
+ * Calling {@link #withHeader(String...)} let's you use the given names to address values in a {@link CSVRecord}, and
+ * assumes that your CSV source does not contain a first record that also defines column names.
+ *
+ * If it does, then you are overriding this metadata with your names and you should skip the first record by calling
+ * {@link #withSkipHeaderRecord(boolean)} with {@code true}.
+ * &lt;/p&gt;
+ *
+ * &lt;h2&gt;Parsing&lt;/h2&gt;
+ *
+ * &lt;p&gt;
+ * You can use a format directly to parse a reader. For example, to parse an Excel file with columns header, write:
+ * &lt;/p&gt;
+ *
+ * &lt;pre&gt;
+ * Reader in = ...;
+ * CSVFormat.EXCEL.withHeader(&amp;quot;Col1&amp;quot;, &amp;quot;Col2&amp;quot;, &amp;quot;Col3&amp;quot;).parse(in);
+ * &lt;/pre&gt;
+ *
+ * &lt;p&gt;
+ * For other input types, like resources, files, and URLs, use the static methods on {@link CSVParser}.
+ * &lt;/p&gt;
+ *
+ * &lt;h2&gt;Referencing columns safely&lt;/h2&gt;
+ *
+ * &lt;p&gt;
+ * If your source contains a header record, you can simplify your code and safely reference columns, by using
+ * {@link #withHeader(String...)} with no arguments:
+ * &lt;/p&gt;
+ *
+ * &lt;pre&gt;
+ * CSVFormat.EXCEL.withHeader();
+ * &lt;/pre&gt;
+ *
+ * &lt;p&gt;
+ * This causes the parser to read the first record and use its values as column names.
+ *
+ * Then, call one of the {@link CSVRecord} get method that takes a String column name argument:
+ * &lt;/p&gt;
+ *
+ * &lt;pre&gt;
+ * String value = record.get(&amp;quot;Col1&amp;quot;);
+ * &lt;/pre&gt;
+ *
+ * &lt;p&gt;
+ * This makes your code impervious to changes in column order in the CSV file.
+ * &lt;/p&gt;
+ *
+ * &lt;h2&gt;Notes&lt;/h2&gt;
+ *
+ * &lt;p&gt;
+ * This class is immutable.
+ * &lt;/p&gt;
+ */
+public final class CSVFormat implements Serializable {
+
+    /**
+     * Predefines formats.
+     *
+     * @since 1.2
+     */
+<span class="fc" id="L163">    public enum Predefined {</span>
+
+        /**
+         * @see CSVFormat#DEFAULT
+         */
+<span class="fc" id="L168">        Default(CSVFormat.DEFAULT),</span>
+
+        /**
+         * @see CSVFormat#EXCEL
+         */
+<span class="fc" id="L173">        Excel(CSVFormat.EXCEL),</span>
+
+        /**
+         * @see CSVFormat#INFORMIX_UNLOAD
+         * @since 1.3
+         */
+<span class="fc" id="L179">        InformixUnload(CSVFormat.INFORMIX_UNLOAD),</span>
+
+        /**
+         * @see CSVFormat#INFORMIX_UNLOAD_CSV
+         * @since 1.3
+         */
+<span class="fc" id="L185">        InformixUnloadCsv(CSVFormat.INFORMIX_UNLOAD_CSV),</span>
+
+        /**
+         * @see CSVFormat#MYSQL
+         */
+<span class="fc" id="L190">        MySQL(CSVFormat.MYSQL),</span>
+
+        /**
+         * @see CSVFormat#POSTGRESQL_CSV
+         * @since 1.5
+         */
+<span class="fc" id="L196">        PostgreSQLCsv(CSVFormat.POSTGRESQL_CSV),</span>
+
+        /**
+         * @see CSVFormat#POSTGRESQL_CSV
+         */
+<span class="fc" id="L201">        PostgreSQLText(CSVFormat.POSTGRESQL_TEXT),</span>
+
+        /**
+         * @see CSVFormat#RFC4180
+         */
+<span class="fc" id="L206">        RFC4180(CSVFormat.RFC4180),</span>
+
+        /**
+         * @see CSVFormat#TDF
+         */
+<span class="fc" id="L211">        TDF(CSVFormat.TDF);</span>
+
+        private final CSVFormat format;
+
+<span class="fc" id="L215">        Predefined(final CSVFormat format) {</span>
+<span class="fc" id="L216">            this.format = format;</span>
+<span class="fc" id="L217">        }</span>
+
+        /**
+         * Gets the format.
+         *
+         * @return the format.
+         */
+        public CSVFormat getFormat() {
+<span class="fc" id="L225">            return format;</span>
+        }
+    }
+
+    /**
+     * Standard comma separated format, as for {@link #RFC4180} but allowing empty lines.
+     *
+     * &lt;p&gt;
+     * Settings are:
+     * &lt;/p&gt;
+     * &lt;ul&gt;
+     * &lt;li&gt;withDelimiter(',')&lt;/li&gt;
+     * &lt;li&gt;withQuote('&quot;')&lt;/li&gt;
+     * &lt;li&gt;withRecordSeparator(&quot;\r\n&quot;)&lt;/li&gt;
+     * &lt;li&gt;withIgnoreEmptyLines(true)&lt;/li&gt;
+     * &lt;/ul&gt;
+     *
+     * @see Predefined#Default
+     */
+<span class="fc" id="L244">    public static final CSVFormat DEFAULT = new CSVFormat(COMMA, DOUBLE_QUOTE_CHAR, null, null, null, false, true, CRLF,</span>
+            null, null, null, false, false, false, false, false);
+
+    /**
+     * Excel file format (using a comma as the value delimiter). Note that the actual value delimiter used by Excel is
+     * locale dependent, it might be necessary to customize this format to accommodate to your regional settings.
+     *
+     * &lt;p&gt;
+     * For example for parsing or generating a CSV file on a French system the following format will be used:
+     * &lt;/p&gt;
+     *
+     * &lt;pre&gt;
+     * CSVFormat fmt = CSVFormat.EXCEL.withDelimiter(';');
+     * &lt;/pre&gt;
+     *
+     * &lt;p&gt;
+     * Settings are:
+     * &lt;/p&gt;
+     * &lt;ul&gt;
+     * &lt;li&gt;{@link #withDelimiter(char) withDelimiter(',')}&lt;/li&gt;
+     * &lt;li&gt;{@link #withQuote(char) withQuote('&quot;')}&lt;/li&gt;
+     * &lt;li&gt;{@link #withRecordSeparator(String) withRecordSeparator(&quot;\r\n&quot;)}&lt;/li&gt;
+     * &lt;li&gt;{@link #withIgnoreEmptyLines(boolean) withIgnoreEmptyLines(false)}&lt;/li&gt;
+     * &lt;li&gt;{@link #withAllowMissingColumnNames(boolean) withAllowMissingColumnNames(true)}&lt;/li&gt;
+     * &lt;/ul&gt;
+     * &lt;p&gt;
+     * Note: this is currently like {@link #RFC4180} plus {@link #withAllowMissingColumnNames(boolean)
+     * withAllowMissingColumnNames(true)}.
+     * &lt;/p&gt;
+     *
+     * @see Predefined#Excel
+     */
+    // @formatter:off
+<span class="fc" id="L277">    public static final CSVFormat EXCEL = DEFAULT</span>
+            .withIgnoreEmptyLines(false)
+            .withAllowMissingColumnNames();
+    // @formatter:on
+
+    /**
+     * Default Informix CSV UNLOAD format used by the {@code UNLOAD TO file_name} operation.
+     *
+     * &lt;p&gt;
+     * This is a comma-delimited format with a LF character as the line separator. Values are not quoted and special
+     * characters are escaped with {@code '\'}. The default NULL string is {@code &quot;\\N&quot;}.
+     * &lt;/p&gt;
+     *
+     * &lt;p&gt;
+     * Settings are:
+     * &lt;/p&gt;
+     * &lt;ul&gt;
+     * &lt;li&gt;withDelimiter(',')&lt;/li&gt;
+     * &lt;li&gt;withQuote(&quot;\&quot;&quot;)&lt;/li&gt;
+     * &lt;li&gt;withRecordSeparator('\n')&lt;/li&gt;
+     * &lt;li&gt;withEscape('\\')&lt;/li&gt;
+     * &lt;/ul&gt;
+     *
+     * @see Predefined#MySQL
+     * @see &lt;a href=
+     *      &quot;http://www.ibm.com/support/knowledgecenter/SSBJG3_2.5.0/com.ibm.gen_busug.doc/c_fgl_InOutSql_UNLOAD.htm&quot;&gt;
+     *      http://www.ibm.com/support/knowledgecenter/SSBJG3_2.5.0/com.ibm.gen_busug.doc/c_fgl_InOutSql_UNLOAD.htm&lt;/a&gt;
+     * @since 1.3
+     */
+    // @formatter:off
+<span class="fc" id="L307">    public static final CSVFormat INFORMIX_UNLOAD = DEFAULT</span>
+            .withDelimiter(PIPE)
+            .withEscape(BACKSLASH)
+            .withQuote(DOUBLE_QUOTE_CHAR)
+            .withRecordSeparator(LF);
+    // @formatter:on
+
+    /**
+     * Default Informix CSV UNLOAD format used by the {@code UNLOAD TO file_name} operation (escaping is disabled.)
+     *
+     * &lt;p&gt;
+     * This is a comma-delimited format with a LF character as the line separator. Values are not quoted and special
+     * characters are escaped with {@code '\'}. The default NULL string is {@code &quot;\\N&quot;}.
+     * &lt;/p&gt;
+     *
+     * &lt;p&gt;
+     * Settings are:
+     * &lt;/p&gt;
+     * &lt;ul&gt;
+     * &lt;li&gt;withDelimiter(',')&lt;/li&gt;
+     * &lt;li&gt;withQuote(&quot;\&quot;&quot;)&lt;/li&gt;
+     * &lt;li&gt;withRecordSeparator('\n')&lt;/li&gt;
+     * &lt;/ul&gt;
+     *
+     * @see Predefined#MySQL
+     * @see &lt;a href=
+     *      &quot;http://www.ibm.com/support/knowledgecenter/SSBJG3_2.5.0/com.ibm.gen_busug.doc/c_fgl_InOutSql_UNLOAD.htm&quot;&gt;
+     *      http://www.ibm.com/support/knowledgecenter/SSBJG3_2.5.0/com.ibm.gen_busug.doc/c_fgl_InOutSql_UNLOAD.htm&lt;/a&gt;
+     * @since 1.3
+     */
+    // @formatter:off
+<span class="fc" id="L338">    public static final CSVFormat INFORMIX_UNLOAD_CSV = DEFAULT</span>
+            .withDelimiter(COMMA)
+            .withQuote(DOUBLE_QUOTE_CHAR)
+            .withRecordSeparator(LF);
+    // @formatter:on
+
+    /**
+     * Default MySQL format used by the {@code SELECT INTO OUTFILE} and {@code LOAD DATA INFILE} operations.
+     *
+     * &lt;p&gt;
+     * This is a tab-delimited format with a LF character as the line separator. Values are not quoted and special
+     * characters are escaped with {@code '\'}. The default NULL string is {@code &quot;\\N&quot;}.
+     * &lt;/p&gt;
+     *
+     * &lt;p&gt;
+     * Settings are:
+     * &lt;/p&gt;
+     * &lt;ul&gt;
+     * &lt;li&gt;withDelimiter('\t')&lt;/li&gt;
+     * &lt;li&gt;withQuote(null)&lt;/li&gt;
+     * &lt;li&gt;withRecordSeparator('\n')&lt;/li&gt;
+     * &lt;li&gt;withIgnoreEmptyLines(false)&lt;/li&gt;
+     * &lt;li&gt;withEscape('\\')&lt;/li&gt;
+     * &lt;li&gt;withNullString(&quot;\\N&quot;)&lt;/li&gt;
+     * &lt;li&gt;withQuoteMode(QuoteMode.ALL_NON_NULL)&lt;/li&gt;
+     * &lt;/ul&gt;
+     *
+     * @see Predefined#MySQL
+     * @see &lt;a href=&quot;http://dev.mysql.com/doc/refman/5.1/en/load-data.html&quot;&gt; http://dev.mysql.com/doc/refman/5.1/en/load
+     *      -data.html&lt;/a&gt;
+     */
+    // @formatter:off
+<span class="fc" id="L370">    public static final CSVFormat MYSQL = DEFAULT</span>
+            .withDelimiter(TAB)
+            .withEscape(BACKSLASH)
+            .withIgnoreEmptyLines(false)
+            .withQuote(null)
+            .withRecordSeparator(LF)
+            .withNullString(&quot;\\N&quot;)
+            .withQuoteMode(QuoteMode.ALL_NON_NULL);
+    // @formatter:off
+
+    /**
+     * Default PostgreSQL CSV format used by the {@code COPY} operation.
+     *
+     * &lt;p&gt;
+     * This is a comma-delimited format with a LF character as the line separator. Values are double quoted and special
+     * characters are escaped with {@code '&quot;'}. The default NULL string is {@code &quot;&quot;}.
+     * &lt;/p&gt;
+     *
+     * &lt;p&gt;
+     * Settings are:
+     * &lt;/p&gt;
+     * &lt;ul&gt;
+     * &lt;li&gt;withDelimiter(',')&lt;/li&gt;
+     * &lt;li&gt;withQuote('&quot;')&lt;/li&gt;
+     * &lt;li&gt;withRecordSeparator('\n')&lt;/li&gt;
+     * &lt;li&gt;withIgnoreEmptyLines(false)&lt;/li&gt;
+     * &lt;li&gt;withEscape('\\')&lt;/li&gt;
+     * &lt;li&gt;withNullString(&quot;&quot;)&lt;/li&gt;
+     * &lt;li&gt;withQuoteMode(QuoteMode.ALL_NON_NULL)&lt;/li&gt;
+     * &lt;/ul&gt;
+     *
+     * @see Predefined#MySQL
+     * @see &lt;a href=&quot;http://dev.mysql.com/doc/refman/5.1/en/load-data.html&quot;&gt; http://dev.mysql.com/doc/refman/5.1/en/load
+     *      -data.html&lt;/a&gt;
+     * @since 1.5
+     */
+    // @formatter:off
+<span class="fc" id="L407">    public static final CSVFormat POSTGRESQL_CSV = DEFAULT</span>
+            .withDelimiter(COMMA)
+            .withEscape(DOUBLE_QUOTE_CHAR)
+            .withIgnoreEmptyLines(false)
+            .withQuote(DOUBLE_QUOTE_CHAR)
+            .withRecordSeparator(LF)
+            .withNullString(EMPTY)
+            .withQuoteMode(QuoteMode.ALL_NON_NULL);
+    // @formatter:off
+
+    /**
+     * Default PostgreSQL text format used by the {@code COPY} operation.
+     *
+     * &lt;p&gt;
+     * This is a tab-delimited format with a LF character as the line separator. Values are double quoted and special
+     * characters are escaped with {@code '&quot;'}. The default NULL string is {@code &quot;\\N&quot;}.
+     * &lt;/p&gt;
+     *
+     * &lt;p&gt;
+     * Settings are:
+     * &lt;/p&gt;
+     * &lt;ul&gt;
+     * &lt;li&gt;withDelimiter('\t')&lt;/li&gt;
+     * &lt;li&gt;withQuote('&quot;')&lt;/li&gt;
+     * &lt;li&gt;withRecordSeparator('\n')&lt;/li&gt;
+     * &lt;li&gt;withIgnoreEmptyLines(false)&lt;/li&gt;
+     * &lt;li&gt;withEscape('\\')&lt;/li&gt;
+     * &lt;li&gt;withNullString(&quot;\\N&quot;)&lt;/li&gt;
+     * &lt;li&gt;withQuoteMode(QuoteMode.ALL_NON_NULL)&lt;/li&gt;
+     * &lt;/ul&gt;
+     *
+     * @see Predefined#MySQL
+     * @see &lt;a href=&quot;http://dev.mysql.com/doc/refman/5.1/en/load-data.html&quot;&gt; http://dev.mysql.com/doc/refman/5.1/en/load
+     *      -data.html&lt;/a&gt;
+     * @since 1.5
+     */
+    // @formatter:off
+<span class="fc" id="L444">    public static final CSVFormat POSTGRESQL_TEXT = DEFAULT</span>
+            .withDelimiter(TAB)
+            .withEscape(DOUBLE_QUOTE_CHAR)
+            .withIgnoreEmptyLines(false)
+            .withQuote(DOUBLE_QUOTE_CHAR)
+            .withRecordSeparator(LF)
+            .withNullString(&quot;\\N&quot;)
+            .withQuoteMode(QuoteMode.ALL_NON_NULL);
+    // @formatter:off
+
+    /**
+     * Comma separated format as defined by &lt;a href=&quot;http://tools.ietf.org/html/rfc4180&quot;&gt;RFC 4180&lt;/a&gt;.
+     *
+     * &lt;p&gt;
+     * Settings are:
+     * &lt;/p&gt;
+     * &lt;ul&gt;
+     * &lt;li&gt;withDelimiter(',')&lt;/li&gt;
+     * &lt;li&gt;withQuote('&quot;')&lt;/li&gt;
+     * &lt;li&gt;withRecordSeparator(&quot;\r\n&quot;)&lt;/li&gt;
+     * &lt;li&gt;withIgnoreEmptyLines(false)&lt;/li&gt;
+     * &lt;/ul&gt;
+     *
+     * @see Predefined#RFC4180
+     */
+<span class="fc" id="L469">    public static final CSVFormat RFC4180 = DEFAULT.withIgnoreEmptyLines(false);</span>
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Tab-delimited format.
+     *
+     * &lt;p&gt;
+     * Settings are:
+     * &lt;/p&gt;
+     * &lt;ul&gt;
+     * &lt;li&gt;withDelimiter('\t')&lt;/li&gt;
+     * &lt;li&gt;withQuote('&quot;')&lt;/li&gt;
+     * &lt;li&gt;withRecordSeparator(&quot;\r\n&quot;)&lt;/li&gt;
+     * &lt;li&gt;withIgnoreSurroundingSpaces(true)&lt;/li&gt;
+     * &lt;/ul&gt;
+     *
+     * @see Predefined#TDF
+     */
+    // @formatter:off
+<span class="fc" id="L489">    public static final CSVFormat TDF = DEFAULT</span>
+            .withDelimiter(TAB)
+            .withIgnoreSurroundingSpaces();
+    // @formatter:on
+
+    /**
+     * Returns true if the given character is a line break character.
+     *
+     * @param c
+     *            the character to check
+     *
+     * @return true if &lt;code&gt;c&lt;/code&gt; is a line break character
+     */
+    private static boolean isLineBreak(final char c) {
+<span class="fc bfc" id="L503" title="All 4 branches covered.">        return c == LF || c == CR;</span>
+    }
+
+    /**
+     * Returns true if the given character is a line break character.
+     *
+     * @param c
+     *            the character to check, may be null
+     *
+     * @return true if &lt;code&gt;c&lt;/code&gt; is a line break character (and not null)
+     */
+    private static boolean isLineBreak(final Character c) {
+<span class="fc bfc" id="L515" title="All 4 branches covered.">        return c != null &amp;&amp; isLineBreak(c.charValue());</span>
+    }
+
+    /**
+     * Creates a new CSV format with the specified delimiter.
+     *
+     * &lt;p&gt;
+     * Use this method if you want to create a CSVFormat from scratch. All fields but the delimiter will be initialized
+     * with null/false.
+     * &lt;/p&gt;
+     *
+     * @param delimiter
+     *            the char used for value separation, must not be a line break character
+     * @return a new CSV format.
+     * @throws IllegalArgumentException
+     *             if the delimiter is a line break character
+     *
+     * @see #DEFAULT
+     * @see #RFC4180
+     * @see #MYSQL
+     * @see #EXCEL
+     * @see #TDF
+     */
+    public static CSVFormat newFormat(final char delimiter) {
+<span class="fc" id="L539">        return new CSVFormat(delimiter, null, null, null, null, false, false, null, null, null, null, false, false,</span>
+                false, false, false);
+    }
+
+    /**
+     * Gets one of the predefined formats from {@link CSVFormat.Predefined}.
+     *
+     * @param format
+     *            name
+     * @return one of the predefined formats
+     * @since 1.2
+     */
+    public static CSVFormat valueOf(final String format) {
+<span class="fc" id="L552">        return CSVFormat.Predefined.valueOf(format).getFormat();</span>
+    }
+
+    private final boolean allowMissingColumnNames;
+
+    private final Character commentMarker; // null if commenting is disabled
+
+    private final char delimiter;
+
+    private final Character escapeCharacter; // null if escaping is disabled
+
+    private final String[] header; // array of header column names
+
+    private final String[] headerComments; // array of header comment lines
+
+    private final boolean ignoreEmptyLines;
+
+    private final boolean ignoreHeaderCase; // should ignore header names case
+
+    private final boolean ignoreSurroundingSpaces; // Should leading/trailing spaces be ignored around values?
+
+    private final String nullString; // the string to be used for null values
+
+    private final Character quoteCharacter; // null if quoting is disabled
+
+    private final QuoteMode quoteMode;
+
+    private final String recordSeparator; // for outputs
+
+    private final boolean skipHeaderRecord;
+
+    private final boolean trailingDelimiter;
+
+    private final boolean trim;
+
+    /**
+     * Creates a customized CSV format.
+     *
+     * @param delimiter
+     *            the char used for value separation, must not be a line break character
+     * @param quoteChar
+     *            the Character used as value encapsulation marker, may be {@code null} to disable
+     * @param quoteMode
+     *            the quote mode
+     * @param commentStart
+     *            the Character used for comment identification, may be {@code null} to disable
+     * @param escape
+     *            the Character used to escape special characters in values, may be {@code null} to disable
+     * @param ignoreSurroundingSpaces
+     *            {@code true} when whitespaces enclosing values should be ignored
+     * @param ignoreEmptyLines
+     *            {@code true} when the parser should skip empty lines
+     * @param recordSeparator
+     *            the line separator to use for output
+     * @param nullString
+     *            the line separator to use for output
+     * @param headerComments
+     *            the comments to be printed by the Printer before the actual CSV data
+     * @param header
+     *            the header
+     * @param skipHeaderRecord
+     *            TODO
+     * @param allowMissingColumnNames
+     *            TODO
+     * @param ignoreHeaderCase
+     *            TODO
+     * @param trim
+     *            TODO
+     * @param trailingDelimiter
+     *            TODO
+     * @throws IllegalArgumentException
+     *             if the delimiter is a line break character
+     */
+    private CSVFormat(final char delimiter, final Character quoteChar, final QuoteMode quoteMode,
+            final Character commentStart, final Character escape, final boolean ignoreSurroundingSpaces,
+            final boolean ignoreEmptyLines, final String recordSeparator, final String nullString,
+            final Object[] headerComments, final String[] header, final boolean skipHeaderRecord,
+            final boolean allowMissingColumnNames, final boolean ignoreHeaderCase, final boolean trim,
+<span class="fc" id="L630">            final boolean trailingDelimiter) {</span>
+<span class="fc" id="L631">        this.delimiter = delimiter;</span>
+<span class="fc" id="L632">        this.quoteCharacter = quoteChar;</span>
+<span class="fc" id="L633">        this.quoteMode = quoteMode;</span>
+<span class="fc" id="L634">        this.commentMarker = commentStart;</span>
+<span class="fc" id="L635">        this.escapeCharacter = escape;</span>
+<span class="fc" id="L636">        this.ignoreSurroundingSpaces = ignoreSurroundingSpaces;</span>
+<span class="fc" id="L637">        this.allowMissingColumnNames = allowMissingColumnNames;</span>
+<span class="fc" id="L638">        this.ignoreEmptyLines = ignoreEmptyLines;</span>
+<span class="fc" id="L639">        this.recordSeparator = recordSeparator;</span>
+<span class="fc" id="L640">        this.nullString = nullString;</span>
+<span class="fc" id="L641">        this.headerComments = toStringArray(headerComments);</span>
+<span class="fc bfc" id="L642" title="All 2 branches covered.">        this.header = header == null ? null : header.clone();</span>
+<span class="fc" id="L643">        this.skipHeaderRecord = skipHeaderRecord;</span>
+<span class="fc" id="L644">        this.ignoreHeaderCase = ignoreHeaderCase;</span>
+<span class="fc" id="L645">        this.trailingDelimiter = trailingDelimiter;</span>
+<span class="fc" id="L646">        this.trim = trim;</span>
+<span class="fc" id="L647">        validate();</span>
+<span class="fc" id="L648">    }</span>
+
+    @Override
+    public boolean equals(final Object obj) {
+<span class="fc bfc" id="L652" title="All 2 branches covered.">        if (this == obj) {</span>
+<span class="fc" id="L653">            return true;</span>
+        }
+<span class="fc bfc" id="L655" title="All 2 branches covered.">        if (obj == null) {</span>
+<span class="fc" id="L656">            return false;</span>
+        }
+<span class="fc bfc" id="L658" title="All 2 branches covered.">        if (getClass() != obj.getClass()) {</span>
+<span class="fc" id="L659">            return false;</span>
+        }
+
+<span class="fc" id="L662">        final CSVFormat other = (CSVFormat) obj;</span>
+<span class="fc bfc" id="L663" title="All 2 branches covered.">        if (delimiter != other.delimiter) {</span>
+<span class="fc" id="L664">            return false;</span>
+        }
+<span class="fc bfc" id="L666" title="All 2 branches covered.">        if (quoteMode != other.quoteMode) {</span>
+<span class="fc" id="L667">            return false;</span>
+        }
+<span class="fc bfc" id="L669" title="All 2 branches covered.">        if (quoteCharacter == null) {</span>
+<span class="fc bfc" id="L670" title="All 2 branches covered.">            if (other.quoteCharacter != null) {</span>
+<span class="fc" id="L671">                return false;</span>
+            }
+<span class="fc bfc" id="L673" title="All 2 branches covered.">        } else if (!quoteCharacter.equals(other.quoteCharacter)) {</span>
+<span class="fc" id="L674">            return false;</span>
+        }
+<span class="fc bfc" id="L676" title="All 2 branches covered.">        if (commentMarker == null) {</span>
+<span class="fc bfc" id="L677" title="All 2 branches covered.">            if (other.commentMarker != null) {</span>
+<span class="fc" id="L678">                return false;</span>
+            }
+<span class="fc bfc" id="L680" title="All 2 branches covered.">        } else if (!commentMarker.equals(other.commentMarker)) {</span>
+<span class="fc" id="L681">            return false;</span>
+        }
+<span class="fc bfc" id="L683" title="All 2 branches covered.">        if (escapeCharacter == null) {</span>
+<span class="pc bpc" id="L684" title="1 of 2 branches missed.">            if (other.escapeCharacter != null) {</span>
+<span class="nc" id="L685">                return false;</span>
+            }
+<span class="fc bfc" id="L687" title="All 2 branches covered.">        } else if (!escapeCharacter.equals(other.escapeCharacter)) {</span>
+<span class="fc" id="L688">            return false;</span>
+        }
+<span class="fc bfc" id="L690" title="All 2 branches covered.">        if (nullString == null) {</span>
+<span class="pc bpc" id="L691" title="1 of 2 branches missed.">            if (other.nullString != null) {</span>
+<span class="nc" id="L692">                return false;</span>
+            }
+<span class="fc bfc" id="L694" title="All 2 branches covered.">        } else if (!nullString.equals(other.nullString)) {</span>
+<span class="fc" id="L695">            return false;</span>
+        }
+<span class="fc bfc" id="L697" title="All 2 branches covered.">        if (!Arrays.equals(header, other.header)) {</span>
+<span class="fc" id="L698">            return false;</span>
+        }
+<span class="fc bfc" id="L700" title="All 2 branches covered.">        if (ignoreSurroundingSpaces != other.ignoreSurroundingSpaces) {</span>
+<span class="fc" id="L701">            return false;</span>
+        }
+<span class="fc bfc" id="L703" title="All 2 branches covered.">        if (ignoreEmptyLines != other.ignoreEmptyLines) {</span>
+<span class="fc" id="L704">            return false;</span>
+        }
+<span class="fc bfc" id="L706" title="All 2 branches covered.">        if (skipHeaderRecord != other.skipHeaderRecord) {</span>
+<span class="fc" id="L707">            return false;</span>
+        }
+<span class="fc bfc" id="L709" title="All 2 branches covered.">        if (recordSeparator == null) {</span>
+<span class="pc bpc" id="L710" title="1 of 2 branches missed.">            if (other.recordSeparator != null) {</span>
+<span class="nc" id="L711">                return false;</span>
+            }
+<span class="fc bfc" id="L713" title="All 2 branches covered.">        } else if (!recordSeparator.equals(other.recordSeparator)) {</span>
+<span class="fc" id="L714">            return false;</span>
+        }
+<span class="fc" id="L716">        return true;</span>
+    }
+
+    /**
+     * Formats the specified values.
+     *
+     * @param values
+     *            the values to format
+     * @return the formatted values
+     */
+    public String format(final Object... values) {
+<span class="fc" id="L727">        final StringWriter out = new StringWriter();</span>
+<span class="fc" id="L728">        try (final CSVPrinter csvPrinter = new CSVPrinter(out, this)) {</span>
+<span class="fc" id="L729">            csvPrinter.printRecord(values);</span>
+<span class="fc" id="L730">            return out.toString().trim();</span>
+<span class="pc bpc" id="L731" title="4 of 8 branches missed.">        } catch (final IOException e) {</span>
+            // should not happen because a StringWriter does not do IO.
+<span class="nc" id="L733">            throw new IllegalStateException(e);</span>
+        }
+    }
+
+    /**
+     * Specifies whether missing column names are allowed when parsing the header line.
+     *
+     * @return {@code true} if missing column names are allowed when parsing the header line, {@code false} to throw an
+     *         {@link IllegalArgumentException}.
+     */
+    public boolean getAllowMissingColumnNames() {
+<span class="fc" id="L744">        return allowMissingColumnNames;</span>
+    }
+
+    /**
+     * Returns the character marking the start of a line comment.
+     *
+     * @return the comment start marker, may be {@code null}
+     */
+    public Character getCommentMarker() {
+<span class="fc" id="L753">        return commentMarker;</span>
+    }
+
+    /**
+     * Returns the character delimiting the values (typically ';', ',' or '\t').
+     *
+     * @return the delimiter character
+     */
+    public char getDelimiter() {
+<span class="fc" id="L762">        return delimiter;</span>
+    }
+
+    /**
+     * Returns the escape character.
+     *
+     * @return the escape character, may be {@code null}
+     */
+    public Character getEscapeCharacter() {
+<span class="fc" id="L771">        return escapeCharacter;</span>
+    }
+
+    /**
+     * Returns a copy of the header array.
+     *
+     * @return a copy of the header array; {@code null} if disabled, the empty array if to be read from the file
+     */
+    public String[] getHeader() {
+<span class="fc bfc" id="L780" title="All 2 branches covered.">        return header != null ? header.clone() : null;</span>
+    }
+
+    /**
+     * Returns a copy of the header comment array.
+     *
+     * @return a copy of the header comment array; {@code null} if disabled.
+     */
+    public String[] getHeaderComments() {
+<span class="fc bfc" id="L789" title="All 2 branches covered.">        return headerComments != null ? headerComments.clone() : null;</span>
+    }
+
+    /**
+     * Specifies whether empty lines between records are ignored when parsing input.
+     *
+     * @return {@code true} if empty lines between records are ignored, {@code false} if they are turned into empty
+     *         records.
+     */
+    public boolean getIgnoreEmptyLines() {
+<span class="fc" id="L799">        return ignoreEmptyLines;</span>
+    }
+
+    /**
+     * Specifies whether header names will be accessed ignoring case.
+     *
+     * @return {@code true} if header names cases are ignored, {@code false} if they are case sensitive.
+     * @since 1.3
+     */
+    public boolean getIgnoreHeaderCase() {
+<span class="fc" id="L809">        return ignoreHeaderCase;</span>
+    }
+
+    /**
+     * Specifies whether spaces around values are ignored when parsing input.
+     *
+     * @return {@code true} if spaces around values are ignored, {@code false} if they are treated as part of the value.
+     */
+    public boolean getIgnoreSurroundingSpaces() {
+<span class="fc" id="L818">        return ignoreSurroundingSpaces;</span>
+    }
+
+    /**
+     * Gets the String to convert to and from {@code null}.
+     * &lt;ul&gt;
+     * &lt;li&gt;&lt;strong&gt;Reading:&lt;/strong&gt; Converts strings equal to the given {@code nullString} to {@code null} when reading
+     * records.&lt;/li&gt;
+     * &lt;li&gt;&lt;strong&gt;Writing:&lt;/strong&gt; Writes {@code null} as the given {@code nullString} when writing records.&lt;/li&gt;
+     * &lt;/ul&gt;
+     *
+     * @return the String to convert to and from {@code null}. No substitution occurs if {@code null}
+     */
+    public String getNullString() {
+<span class="fc" id="L832">        return nullString;</span>
+    }
+
+    /**
+     * Returns the character used to encapsulate values containing special characters.
+     *
+     * @return the quoteChar character, may be {@code null}
+     */
+    public Character getQuoteCharacter() {
+<span class="fc" id="L841">        return quoteCharacter;</span>
+    }
+
+    /**
+     * Returns the quote policy output fields.
+     *
+     * @return the quote policy
+     */
+    public QuoteMode getQuoteMode() {
+<span class="fc" id="L850">        return quoteMode;</span>
+    }
+
+    /**
+     * Returns the record separator delimiting output records.
+     *
+     * @return the record separator
+     */
+    public String getRecordSeparator() {
+<span class="fc" id="L859">        return recordSeparator;</span>
+    }
+
+    /**
+     * Returns whether to skip the header record.
+     *
+     * @return whether to skip the header record.
+     */
+    public boolean getSkipHeaderRecord() {
+<span class="fc" id="L868">        return skipHeaderRecord;</span>
+    }
+
+    /**
+     * Returns whether to add a trailing delimiter.
+     *
+     * @return whether to add a trailing delimiter.
+     * @since 1.3
+     */
+    public boolean getTrailingDelimiter() {
+<span class="fc" id="L878">        return trailingDelimiter;</span>
+    }
+
+    /**
+     * Returns whether to trim leading and trailing blanks.
+     *
+     * @return whether to trim leading and trailing blanks.
+     */
+    public boolean getTrim() {
+<span class="fc" id="L887">        return trim;</span>
+    }
+
+    @Override
+    public int hashCode() {
+<span class="fc" id="L892">        final int prime = 31;</span>
+<span class="fc" id="L893">        int result = 1;</span>
+
+<span class="fc" id="L895">        result = prime * result + delimiter;</span>
+<span class="pc bpc" id="L896" title="1 of 2 branches missed.">        result = prime * result + ((quoteMode == null) ? 0 : quoteMode.hashCode());</span>
+<span class="pc bpc" id="L897" title="1 of 2 branches missed.">        result = prime * result + ((quoteCharacter == null) ? 0 : quoteCharacter.hashCode());</span>
+<span class="pc bpc" id="L898" title="1 of 2 branches missed.">        result = prime * result + ((commentMarker == null) ? 0 : commentMarker.hashCode());</span>
+<span class="pc bpc" id="L899" title="1 of 2 branches missed.">        result = prime * result + ((escapeCharacter == null) ? 0 : escapeCharacter.hashCode());</span>
+<span class="pc bpc" id="L900" title="1 of 2 branches missed.">        result = prime * result + ((nullString == null) ? 0 : nullString.hashCode());</span>
+<span class="pc bpc" id="L901" title="1 of 2 branches missed.">        result = prime * result + (ignoreSurroundingSpaces ? 1231 : 1237);</span>
+<span class="fc bfc" id="L902" title="All 2 branches covered.">        result = prime * result + (ignoreHeaderCase ? 1231 : 1237);</span>
+<span class="pc bpc" id="L903" title="1 of 2 branches missed.">        result = prime * result + (ignoreEmptyLines ? 1231 : 1237);</span>
+<span class="pc bpc" id="L904" title="1 of 2 branches missed.">        result = prime * result + (skipHeaderRecord ? 1231 : 1237);</span>
+<span class="pc bpc" id="L905" title="1 of 2 branches missed.">        result = prime * result + ((recordSeparator == null) ? 0 : recordSeparator.hashCode());</span>
+<span class="fc" id="L906">        result = prime * result + Arrays.hashCode(header);</span>
+<span class="fc" id="L907">        return result;</span>
+    }
+
+    /**
+     * Specifies whether comments are supported by this format.
+     *
+     * Note that the comment introducer character is only recognized at the start of a line.
+     *
+     * @return {@code true} is comments are supported, {@code false} otherwise
+     */
+    public boolean isCommentMarkerSet() {
+<span class="fc bfc" id="L918" title="All 2 branches covered.">        return commentMarker != null;</span>
+    }
+
+    /**
+     * Returns whether escape are being processed.
+     *
+     * @return {@code true} if escapes are processed
+     */
+    public boolean isEscapeCharacterSet() {
+<span class="fc bfc" id="L927" title="All 2 branches covered.">        return escapeCharacter != null;</span>
+    }
+
+    /**
+     * Returns whether a nullString has been defined.
+     *
+     * @return {@code true} if a nullString is defined
+     */
+    public boolean isNullStringSet() {
+<span class="fc bfc" id="L936" title="All 2 branches covered.">        return nullString != null;</span>
+    }
+
+    /**
+     * Returns whether a quoteChar has been defined.
+     *
+     * @return {@code true} if a quoteChar is defined
+     */
+    public boolean isQuoteCharacterSet() {
+<span class="fc bfc" id="L945" title="All 2 branches covered.">        return quoteCharacter != null;</span>
+    }
+
+    /**
+     * Parses the specified content.
+     *
+     * &lt;p&gt;
+     * See also the various static parse methods on {@link CSVParser}.
+     * &lt;/p&gt;
+     *
+     * @param in
+     *            the input stream
+     * @return a parser over a stream of {@link CSVRecord}s.
+     * @throws IOException
+     *             If an I/O error occurs
+     */
+    public CSVParser parse(final Reader in) throws IOException {
+<span class="fc" id="L962">        return new CSVParser(in, this);</span>
+    }
+
+    /**
+     * Prints to the specified output.
+     *
+     * &lt;p&gt;
+     * See also {@link CSVPrinter}.
+     * &lt;/p&gt;
+     *
+     * @param out
+     *            the output.
+     * @return a printer to an output.
+     * @throws IOException
+     *             thrown if the optional header cannot be printed.
+     */
+    public CSVPrinter print(final Appendable out) throws IOException {
+<span class="fc" id="L979">        return new CSVPrinter(out, this);</span>
+    }
+
+    /**
+     * Prints to the {@link System#out}.
+     *
+     * &lt;p&gt;
+     * See also {@link CSVPrinter}.
+     * &lt;/p&gt;
+     *
+     * @return a printer to {@link System#out}.
+     * @throws IOException
+     *             thrown if the optional header cannot be printed.
+     * @since 1.5
+     */
+    public CSVPrinter printer() throws IOException {
+<span class="fc" id="L995">        return new CSVPrinter(System.out, this);</span>
+    }
+
+    /**
+     * Prints to the specified output.
+     *
+     * &lt;p&gt;
+     * See also {@link CSVPrinter}.
+     * &lt;/p&gt;
+     *
+     * @param out
+     *            the output.
+     * @param charset
+     *            A charset.
+     * @return a printer to an output.
+     * @throws IOException
+     *             thrown if the optional header cannot be printed.
+     * @since 1.5
+     */
+    @SuppressWarnings(&quot;resource&quot;)
+    public CSVPrinter print(final File out, Charset charset) throws IOException {
+        // The writer will be closed when close() is called.
+<span class="fc" id="L1017">        return new CSVPrinter(new OutputStreamWriter(new FileOutputStream(out), charset), this);</span>
+    }
+
+    /**
+     * Prints to the specified output.
+     *
+     * &lt;p&gt;
+     * See also {@link CSVPrinter}.
+     * &lt;/p&gt;
+     *
+     * @param out
+     *            the output.
+     * @param charset
+     *            A charset.
+     * @return a printer to an output.
+     * @throws IOException
+     *             thrown if the optional header cannot be printed.
+     * @since 1.5
+     */
+    public CSVPrinter print(final Path out, Charset charset) throws IOException {
+<span class="fc" id="L1037">        return print(Files.newBufferedWriter(out, charset));</span>
+    }
+
+    /**
+     * Prints the {@code value} as the next value on the line to {@code out}. The value will be escaped or encapsulated
+     * as needed. Useful when one wants to avoid creating CSVPrinters.
+     *
+     * @param value
+     *            value to output.
+     * @param out
+     *            where to print the value.
+     * @param newRecord
+     *            if this a new record.
+     * @throws IOException
+     *             If an I/O error occurs.
+     * @since 1.4
+     */
+    public void print(final Object value, final Appendable out, final boolean newRecord) throws IOException {
+        // null values are considered empty
+        // Only call CharSequence.toString() if you have to, helps GC-free use cases.
+        CharSequence charSequence;
+<span class="fc bfc" id="L1058" title="All 2 branches covered.">        if (value == null) {</span>
+            // https://issues.apache.org/jira/browse/CSV-203
+<span class="fc bfc" id="L1060" title="All 2 branches covered.">            if (null == nullString) {</span>
+<span class="fc" id="L1061">                charSequence = EMPTY;</span>
+            } else {
+<span class="fc bfc" id="L1063" title="All 2 branches covered.">                if (QuoteMode.ALL == quoteMode) {</span>
+<span class="fc" id="L1064">                    charSequence = quoteCharacter + nullString + quoteCharacter;</span>
+                } else {
+<span class="fc" id="L1066">                    charSequence = nullString;</span>
+                }
+            }
+        } else {
+<span class="fc bfc" id="L1070" title="All 2 branches covered.">            charSequence = value instanceof CharSequence ? (CharSequence) value : value.toString();</span>
+        }
+<span class="fc bfc" id="L1072" title="All 2 branches covered.">        charSequence = getTrim() ? trim(charSequence) : charSequence;</span>
+<span class="fc" id="L1073">        this.print(value, charSequence, 0, charSequence.length(), out, newRecord);</span>
+<span class="fc" id="L1074">    }</span>
+
+    private void print(final Object object, final CharSequence value, final int offset, final int len,
+            final Appendable out, final boolean newRecord) throws IOException {
+<span class="fc bfc" id="L1078" title="All 2 branches covered.">        if (!newRecord) {</span>
+<span class="fc" id="L1079">            out.append(getDelimiter());</span>
+        }
+<span class="fc bfc" id="L1081" title="All 2 branches covered.">        if (object == null) {</span>
+<span class="fc" id="L1082">            out.append(value);</span>
+<span class="fc bfc" id="L1083" title="All 2 branches covered.">        } else if (isQuoteCharacterSet()) {</span>
+            // the original object is needed so can check for Number
+<span class="fc" id="L1085">            printAndQuote(object, value, offset, len, out, newRecord);</span>
+<span class="fc bfc" id="L1086" title="All 2 branches covered.">        } else if (isEscapeCharacterSet()) {</span>
+<span class="fc" id="L1087">            printAndEscape(value, offset, len, out);</span>
+        } else {
+<span class="fc" id="L1089">            out.append(value, offset, offset + len);</span>
+        }
+<span class="fc" id="L1091">    }</span>
+
+    /*
+     * Note: must only be called if escaping is enabled, otherwise will generate NPE
+     */
+    private void printAndEscape(final CharSequence value, final int offset, final int len, final Appendable out)
+            throws IOException {
+<span class="fc" id="L1098">        int start = offset;</span>
+<span class="fc" id="L1099">        int pos = offset;</span>
+<span class="fc" id="L1100">        final int end = offset + len;</span>
+
+<span class="fc" id="L1102">        final char delim = getDelimiter();</span>
+<span class="fc" id="L1103">        final char escape = getEscapeCharacter().charValue();</span>
+
+<span class="fc bfc" id="L1105" title="All 2 branches covered.">        while (pos &lt; end) {</span>
+<span class="fc" id="L1106">            char c = value.charAt(pos);</span>
+<span class="fc bfc" id="L1107" title="All 8 branches covered.">            if (c == CR || c == LF || c == delim || c == escape) {</span>
+                // write out segment up until this char
+<span class="fc bfc" id="L1109" title="All 2 branches covered.">                if (pos &gt; start) {</span>
+<span class="fc" id="L1110">                    out.append(value, start, pos);</span>
+                }
+<span class="fc bfc" id="L1112" title="All 2 branches covered.">                if (c == LF) {</span>
+<span class="fc" id="L1113">                    c = 'n';</span>
+<span class="fc bfc" id="L1114" title="All 2 branches covered.">                } else if (c == CR) {</span>
+<span class="fc" id="L1115">                    c = 'r';</span>
+                }
+
+<span class="fc" id="L1118">                out.append(escape);</span>
+<span class="fc" id="L1119">                out.append(c);</span>
+
+<span class="fc" id="L1121">                start = pos + 1; // start on the current char after this one</span>
+            }
+
+<span class="fc" id="L1124">            pos++;</span>
+<span class="fc" id="L1125">        }</span>
+
+        // write last segment
+<span class="fc bfc" id="L1128" title="All 2 branches covered.">        if (pos &gt; start) {</span>
+<span class="fc" id="L1129">            out.append(value, start, pos);</span>
+        }
+<span class="fc" id="L1131">    }</span>
+
+    /*
+     * Note: must only be called if quoting is enabled, otherwise will generate NPE
+     */
+    // the original object is needed so can check for Number
+    private void printAndQuote(final Object object, final CharSequence value, final int offset, final int len,
+            final Appendable out, final boolean newRecord) throws IOException {
+<span class="fc" id="L1139">        boolean quote = false;</span>
+<span class="fc" id="L1140">        int start = offset;</span>
+<span class="fc" id="L1141">        int pos = offset;</span>
+<span class="fc" id="L1142">        final int end = offset + len;</span>
+
+<span class="fc" id="L1144">        final char delimChar = getDelimiter();</span>
+<span class="fc" id="L1145">        final char quoteChar = getQuoteCharacter().charValue();</span>
+
+<span class="fc" id="L1147">        QuoteMode quoteModePolicy = getQuoteMode();</span>
+<span class="fc bfc" id="L1148" title="All 2 branches covered.">        if (quoteModePolicy == null) {</span>
+<span class="fc" id="L1149">            quoteModePolicy = QuoteMode.MINIMAL;</span>
+        }
+<span class="pc bpc" id="L1151" title="1 of 5 branches missed.">        switch (quoteModePolicy) {</span>
+        case ALL:
+        case ALL_NON_NULL:
+<span class="fc" id="L1154">            quote = true;</span>
+<span class="fc" id="L1155">            break;</span>
+        case NON_NUMERIC:
+<span class="fc bfc" id="L1157" title="All 2 branches covered.">            quote = !(object instanceof Number);</span>
+<span class="fc" id="L1158">            break;</span>
+        case NONE:
+            // Use the existing escaping code
+<span class="fc" id="L1161">            printAndEscape(value, offset, len, out);</span>
+<span class="fc" id="L1162">            return;</span>
+        case MINIMAL:
+<span class="fc bfc" id="L1164" title="All 2 branches covered.">            if (len &lt;= 0) {</span>
+                // always quote an empty token that is the first
+                // on the line, as it may be the only thing on the
+                // line. If it were not quoted in that case,
+                // an empty line has no tokens.
+<span class="fc bfc" id="L1169" title="All 2 branches covered.">                if (newRecord) {</span>
+<span class="fc" id="L1170">                    quote = true;</span>
+                }
+            } else {
+<span class="fc" id="L1173">                char c = value.charAt(pos);</span>
+
+                // RFC4180 (https://tools.ietf.org/html/rfc4180) TEXTDATA =  %x20-21 / %x23-2B / %x2D-7E
+<span class="fc bfc" id="L1176" title="All 14 branches covered.">                if (newRecord &amp;&amp; (c &lt; 0x20 || c &gt; 0x21 &amp;&amp; c &lt; 0x23 || c &gt; 0x2B &amp;&amp; c &lt; 0x2D || c &gt; 0x7E)) {</span>
+<span class="fc" id="L1177">                    quote = true;</span>
+<span class="fc bfc" id="L1178" title="All 2 branches covered.">                } else if (c &lt;= COMMENT) {</span>
+                    // Some other chars at the start of a value caused the parser to fail, so for now
+                    // encapsulate if we start in anything less than '#'. We are being conservative
+                    // by including the default comment char too.
+<span class="fc" id="L1182">                    quote = true;</span>
+                } else {
+<span class="fc bfc" id="L1184" title="All 2 branches covered.">                    while (pos &lt; end) {</span>
+<span class="fc" id="L1185">                        c = value.charAt(pos);</span>
+<span class="fc bfc" id="L1186" title="All 8 branches covered.">                        if (c == LF || c == CR || c == quoteChar || c == delimChar) {</span>
+<span class="fc" id="L1187">                            quote = true;</span>
+<span class="fc" id="L1188">                            break;</span>
+                        }
+<span class="fc" id="L1190">                        pos++;</span>
+                    }
+
+<span class="fc bfc" id="L1193" title="All 2 branches covered.">                    if (!quote) {</span>
+<span class="fc" id="L1194">                        pos = end - 1;</span>
+<span class="fc" id="L1195">                        c = value.charAt(pos);</span>
+                        // Some other chars at the end caused the parser to fail, so for now
+                        // encapsulate if we end in anything less than ' '
+<span class="fc bfc" id="L1198" title="All 2 branches covered.">                        if (c &lt;= SP) {</span>
+<span class="fc" id="L1199">                            quote = true;</span>
+                        }
+                    }
+                }
+            }
+
+<span class="fc bfc" id="L1205" title="All 2 branches covered.">            if (!quote) {</span>
+                // no encapsulation needed - write out the original value
+<span class="fc" id="L1207">                out.append(value, start, end);</span>
+<span class="fc" id="L1208">                return;</span>
+            }
+            break;
+        default:
+<span class="nc" id="L1212">            throw new IllegalStateException(&quot;Unexpected Quote value: &quot; + quoteModePolicy);</span>
+        }
+
+<span class="fc bfc" id="L1215" title="All 2 branches covered.">        if (!quote) {</span>
+            // no encapsulation needed - write out the original value
+<span class="fc" id="L1217">            out.append(value, start, end);</span>
+<span class="fc" id="L1218">            return;</span>
+        }
+
+        // we hit something that needed encapsulation
+<span class="fc" id="L1222">        out.append(quoteChar);</span>
+
+        // Pick up where we left off: pos should be positioned on the first character that caused
+        // the need for encapsulation.
+<span class="fc bfc" id="L1226" title="All 2 branches covered.">        while (pos &lt; end) {</span>
+<span class="fc" id="L1227">            final char c = value.charAt(pos);</span>
+<span class="fc bfc" id="L1228" title="All 2 branches covered.">            if (c == quoteChar) {</span>
+                // write out the chunk up until this point
+
+                // add 1 to the length to write out the encapsulator also
+<span class="fc" id="L1232">                out.append(value, start, pos + 1);</span>
+                // put the next starting position on the encapsulator so we will
+                // write it out again with the next string (effectively doubling it)
+<span class="fc" id="L1235">                start = pos;</span>
+            }
+<span class="fc" id="L1237">            pos++;</span>
+<span class="fc" id="L1238">        }</span>
+
+        // write the last segment
+<span class="fc" id="L1241">        out.append(value, start, pos);</span>
+<span class="fc" id="L1242">        out.append(quoteChar);</span>
+<span class="fc" id="L1243">    }</span>
+
+    /**
+     * Outputs the trailing delimiter (if set) followed by the record separator (if set).
+     *
+     * @param out
+     *            where to write
+     * @throws IOException
+     *             If an I/O error occurs
+     * @since 1.4
+     */
+    public void println(final Appendable out) throws IOException {
+<span class="fc bfc" id="L1255" title="All 2 branches covered.">        if (getTrailingDelimiter()) {</span>
+<span class="fc" id="L1256">            out.append(getDelimiter());</span>
+        }
+<span class="fc bfc" id="L1258" title="All 2 branches covered.">        if (recordSeparator != null) {</span>
+<span class="fc" id="L1259">            out.append(recordSeparator);</span>
+        }
+<span class="fc" id="L1261">    }</span>
+
+    /**
+     * Prints the given {@code values} to {@code out} as a single record of delimiter separated values followed by the
+     * record separator.
+     *
+     * &lt;p&gt;
+     * The values will be quoted if needed. Quotes and new-line characters will be escaped. This method adds the record
+     * separator to the output after printing the record, so there is no need to call {@link #println(Appendable)}.
+     * &lt;/p&gt;
+     *
+     * @param out
+     *            where to write.
+     * @param values
+     *            values to output.
+     * @throws IOException
+     *             If an I/O error occurs.
+     * @since 1.4
+     */
+    public void printRecord(final Appendable out, final Object... values) throws IOException {
+<span class="fc bfc" id="L1281" title="All 2 branches covered.">        for (int i = 0; i &lt; values.length; i++) {</span>
+<span class="fc bfc" id="L1282" title="All 2 branches covered.">            print(values[i], out, i == 0);</span>
+        }
+<span class="fc" id="L1284">        println(out);</span>
+<span class="fc" id="L1285">    }</span>
+
+    @Override
+    public String toString() {
+<span class="fc" id="L1289">        final StringBuilder sb = new StringBuilder();</span>
+<span class="fc" id="L1290">        sb.append(&quot;Delimiter=&lt;&quot;).append(delimiter).append('&gt;');</span>
+<span class="fc bfc" id="L1291" title="All 2 branches covered.">        if (isEscapeCharacterSet()) {</span>
+<span class="fc" id="L1292">            sb.append(' ');</span>
+<span class="fc" id="L1293">            sb.append(&quot;Escape=&lt;&quot;).append(escapeCharacter).append('&gt;');</span>
+        }
+<span class="pc bpc" id="L1295" title="1 of 2 branches missed.">        if (isQuoteCharacterSet()) {</span>
+<span class="fc" id="L1296">            sb.append(' ');</span>
+<span class="fc" id="L1297">            sb.append(&quot;QuoteChar=&lt;&quot;).append(quoteCharacter).append('&gt;');</span>
+        }
+<span class="fc bfc" id="L1299" title="All 2 branches covered.">        if (isCommentMarkerSet()) {</span>
+<span class="fc" id="L1300">            sb.append(' ');</span>
+<span class="fc" id="L1301">            sb.append(&quot;CommentStart=&lt;&quot;).append(commentMarker).append('&gt;');</span>
+        }
+<span class="pc bpc" id="L1303" title="1 of 2 branches missed.">        if (isNullStringSet()) {</span>
+<span class="nc" id="L1304">            sb.append(' ');</span>
+<span class="nc" id="L1305">            sb.append(&quot;NullString=&lt;&quot;).append(nullString).append('&gt;');</span>
+        }
+<span class="fc bfc" id="L1307" title="All 2 branches covered.">        if (recordSeparator != null) {</span>
+<span class="fc" id="L1308">            sb.append(' ');</span>
+<span class="fc" id="L1309">            sb.append(&quot;RecordSeparator=&lt;&quot;).append(recordSeparator).append('&gt;');</span>
+        }
+<span class="fc bfc" id="L1311" title="All 2 branches covered.">        if (getIgnoreEmptyLines()) {</span>
+<span class="fc" id="L1312">            sb.append(&quot; EmptyLines:ignored&quot;);</span>
+        }
+<span class="fc bfc" id="L1314" title="All 2 branches covered.">        if (getIgnoreSurroundingSpaces()) {</span>
+<span class="fc" id="L1315">            sb.append(&quot; SurroundingSpaces:ignored&quot;);</span>
+        }
+<span class="pc bpc" id="L1317" title="1 of 2 branches missed.">        if (getIgnoreHeaderCase()) {</span>
+<span class="nc" id="L1318">            sb.append(&quot; IgnoreHeaderCase:ignored&quot;);</span>
+        }
+<span class="fc" id="L1320">        sb.append(&quot; SkipHeaderRecord:&quot;).append(skipHeaderRecord);</span>
+<span class="pc bpc" id="L1321" title="1 of 2 branches missed.">        if (headerComments != null) {</span>
+<span class="nc" id="L1322">            sb.append(' ');</span>
+<span class="nc" id="L1323">            sb.append(&quot;HeaderComments:&quot;).append(Arrays.toString(headerComments));</span>
+        }
+<span class="pc bpc" id="L1325" title="1 of 2 branches missed.">        if (header != null) {</span>
+<span class="nc" id="L1326">            sb.append(' ');</span>
+<span class="nc" id="L1327">            sb.append(&quot;Header:&quot;).append(Arrays.toString(header));</span>
+        }
+<span class="fc" id="L1329">        return sb.toString();</span>
+    }
+
+    private String[] toStringArray(final Object[] values) {
+<span class="fc bfc" id="L1333" title="All 2 branches covered.">        if (values == null) {</span>
+<span class="fc" id="L1334">            return null;</span>
+        }
+<span class="fc" id="L1336">        final String[] strings = new String[values.length];</span>
+<span class="fc bfc" id="L1337" title="All 2 branches covered.">        for (int i = 0; i &lt; values.length; i++) {</span>
+<span class="fc" id="L1338">            final Object value = values[i];</span>
+<span class="fc bfc" id="L1339" title="All 2 branches covered.">            strings[i] = value == null ? null : value.toString();</span>
+        }
+<span class="fc" id="L1341">        return strings;</span>
+    }
+
+    private CharSequence trim(final CharSequence charSequence) {
+<span class="pc bpc" id="L1345" title="1 of 2 branches missed.">        if (charSequence instanceof String) {</span>
+<span class="fc" id="L1346">            return ((String) charSequence).trim();</span>
+        }
+<span class="nc" id="L1348">        final int count = charSequence.length();</span>
+<span class="nc" id="L1349">        int len = count;</span>
+<span class="nc" id="L1350">        int pos = 0;</span>
+
+<span class="nc bnc" id="L1352" title="All 4 branches missed.">        while (pos &lt; len &amp;&amp; charSequence.charAt(pos) &lt;= SP) {</span>
+<span class="nc" id="L1353">            pos++;</span>
+        }
+<span class="nc bnc" id="L1355" title="All 4 branches missed.">        while (pos &lt; len &amp;&amp; charSequence.charAt(len - 1) &lt;= SP) {</span>
+<span class="nc" id="L1356">            len--;</span>
+        }
+<span class="nc bnc" id="L1358" title="All 4 branches missed.">        return pos &gt; 0 || len &lt; count ? charSequence.subSequence(pos, len) : charSequence;</span>
+    }
+
+    /**
+     * Verifies the consistency of the parameters and throws an IllegalArgumentException if necessary.
+     *
+     * @throws IllegalArgumentException
+     */
+    private void validate() throws IllegalArgumentException {
+<span class="pc bpc" id="L1367" title="1 of 2 branches missed.">        if (isLineBreak(delimiter)) {</span>
+<span class="nc" id="L1368">            throw new IllegalArgumentException(&quot;The delimiter cannot be a line break&quot;);</span>
+        }
+
+<span class="fc bfc" id="L1371" title="All 4 branches covered.">        if (quoteCharacter != null &amp;&amp; delimiter == quoteCharacter.charValue()) {</span>
+<span class="fc" id="L1372">            throw new IllegalArgumentException(</span>
+                    &quot;The quoteChar character and the delimiter cannot be the same ('&quot; + quoteCharacter + &quot;')&quot;);
+        }
+
+<span class="fc bfc" id="L1376" title="All 4 branches covered.">        if (escapeCharacter != null &amp;&amp; delimiter == escapeCharacter.charValue()) {</span>
+<span class="fc" id="L1377">            throw new IllegalArgumentException(</span>
+                    &quot;The escape character and the delimiter cannot be the same ('&quot; + escapeCharacter + &quot;')&quot;);
+        }
+
+<span class="fc bfc" id="L1381" title="All 4 branches covered.">        if (commentMarker != null &amp;&amp; delimiter == commentMarker.charValue()) {</span>
+<span class="fc" id="L1382">            throw new IllegalArgumentException(</span>
+                    &quot;The comment start character and the delimiter cannot be the same ('&quot; + commentMarker + &quot;')&quot;);
+        }
+
+<span class="fc bfc" id="L1386" title="All 4 branches covered.">        if (quoteCharacter != null &amp;&amp; quoteCharacter.equals(commentMarker)) {</span>
+<span class="fc" id="L1387">            throw new IllegalArgumentException(</span>
+                    &quot;The comment start character and the quoteChar cannot be the same ('&quot; + commentMarker + &quot;')&quot;);
+        }
+
+<span class="fc bfc" id="L1391" title="All 4 branches covered.">        if (escapeCharacter != null &amp;&amp; escapeCharacter.equals(commentMarker)) {</span>
+<span class="fc" id="L1392">            throw new IllegalArgumentException(</span>
+                    &quot;The comment start and the escape character cannot be the same ('&quot; + commentMarker + &quot;')&quot;);
+        }
+
+<span class="fc bfc" id="L1396" title="All 4 branches covered.">        if (escapeCharacter == null &amp;&amp; quoteMode == QuoteMode.NONE) {</span>
+<span class="fc" id="L1397">            throw new IllegalArgumentException(&quot;No quotes mode set but no escape character is set&quot;);</span>
+        }
+
+        // validate header
+<span class="fc bfc" id="L1401" title="All 2 branches covered.">        if (header != null) {</span>
+<span class="fc" id="L1402">            final Set&lt;String&gt; dupCheck = new HashSet&lt;&gt;();</span>
+<span class="fc bfc" id="L1403" title="All 2 branches covered.">            for (final String hdr : header) {</span>
+<span class="fc bfc" id="L1404" title="All 2 branches covered.">                if (!dupCheck.add(hdr)) {</span>
+<span class="fc" id="L1405">                    throw new IllegalArgumentException(</span>
+                            &quot;The header contains a duplicate entry: '&quot; + hdr + &quot;' in &quot; + Arrays.toString(header));
+                }
+            }
+        }
+<span class="fc" id="L1410">    }</span>
+
+    /**
+     * Returns a new {@code CSVFormat} with the missing column names behavior of the format set to {@code true}
+     *
+     * @return A new CSVFormat that is equal to this but with the specified missing column names behavior.
+     * @see #withAllowMissingColumnNames(boolean)
+     * @since 1.1
+     */
+    public CSVFormat withAllowMissingColumnNames() {
+<span class="fc" id="L1420">        return this.withAllowMissingColumnNames(true);</span>
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the missing column names behavior of the format set to the given value.
+     *
+     * @param allowMissingColumnNames
+     *            the missing column names behavior, {@code true} to allow missing column names in the header line,
+     *            {@code false} to cause an {@link IllegalArgumentException} to be thrown.
+     * @return A new CSVFormat that is equal to this but with the specified missing column names behavior.
+     */
+    public CSVFormat withAllowMissingColumnNames(final boolean allowMissingColumnNames) {
+<span class="fc" id="L1432">        return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span>
+                ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
+                skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter);
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the comment start marker of the format set to the specified character.
+     *
+     * Note that the comment start character is only recognized at the start of a line.
+     *
+     * @param commentMarker
+     *            the comment start marker
+     * @return A new CSVFormat that is equal to this one but with the specified character as the comment start marker
+     * @throws IllegalArgumentException
+     *             thrown if the specified character is a line break
+     */
+    public CSVFormat withCommentMarker(final char commentMarker) {
+<span class="fc" id="L1449">        return withCommentMarker(Character.valueOf(commentMarker));</span>
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the comment start marker of the format set to the specified character.
+     *
+     * Note that the comment start character is only recognized at the start of a line.
+     *
+     * @param commentMarker
+     *            the comment start marker, use {@code null} to disable
+     * @return A new CSVFormat that is equal to this one but with the specified character as the comment start marker
+     * @throws IllegalArgumentException
+     *             thrown if the specified character is a line break
+     */
+    public CSVFormat withCommentMarker(final Character commentMarker) {
+<span class="fc bfc" id="L1464" title="All 2 branches covered.">        if (isLineBreak(commentMarker)) {</span>
+<span class="fc" id="L1465">            throw new IllegalArgumentException(&quot;The comment start marker character cannot be a line break&quot;);</span>
+        }
+<span class="fc" id="L1467">        return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span>
+                ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
+                skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter);
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the delimiter of the format set to the specified character.
+     *
+     * @param delimiter
+     *            the delimiter character
+     * @return A new CSVFormat that is equal to this with the specified character as delimiter
+     * @throws IllegalArgumentException
+     *             thrown if the specified character is a line break
+     */
+    public CSVFormat withDelimiter(final char delimiter) {
+<span class="fc bfc" id="L1482" title="All 2 branches covered.">        if (isLineBreak(delimiter)) {</span>
+<span class="fc" id="L1483">            throw new IllegalArgumentException(&quot;The delimiter cannot be a line break&quot;);</span>
+        }
+<span class="fc" id="L1485">        return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span>
+                ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
+                skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter);
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the escape character of the format set to the specified character.
+     *
+     * @param escape
+     *            the escape character
+     * @return A new CSVFormat that is equal to his but with the specified character as the escape character
+     * @throws IllegalArgumentException
+     *             thrown if the specified character is a line break
+     */
+    public CSVFormat withEscape(final char escape) {
+<span class="fc" id="L1500">        return withEscape(Character.valueOf(escape));</span>
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the escape character of the format set to the specified character.
+     *
+     * @param escape
+     *            the escape character, use {@code null} to disable
+     * @return A new CSVFormat that is equal to this but with the specified character as the escape character
+     * @throws IllegalArgumentException
+     *             thrown if the specified character is a line break
+     */
+    public CSVFormat withEscape(final Character escape) {
+<span class="fc bfc" id="L1513" title="All 2 branches covered.">        if (isLineBreak(escape)) {</span>
+<span class="fc" id="L1514">            throw new IllegalArgumentException(&quot;The escape character cannot be a line break&quot;);</span>
+        }
+<span class="fc" id="L1516">        return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escape, ignoreSurroundingSpaces,</span>
+                ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord,
+                allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter);
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} using the first record as header.
+     *
+     * &lt;p&gt;
+     * Calling this method is equivalent to calling:
+     * &lt;/p&gt;
+     *
+     * &lt;pre&gt;
+     * CSVFormat format = aFormat.withHeader().withSkipHeaderRecord();
+     * &lt;/pre&gt;
+     *
+     * @return A new CSVFormat that is equal to this but using the first record as header.
+     * @see #withSkipHeaderRecord(boolean)
+     * @see #withHeader(String...)
+     * @since 1.3
+     */
+    public CSVFormat withFirstRecordAsHeader() {
+<span class="fc" id="L1538">        return withHeader().withSkipHeaderRecord();</span>
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the header of the format defined by the enum class.
+     *
+     * &lt;p&gt;
+     * Example:
+     * &lt;/p&gt;
+     * &lt;pre&gt;
+     * public enum Header {
+     *     Name, Email, Phone
+     * }
+     *
+     * CSVFormat format = aformat.withHeader(Header.class);
+     * &lt;/pre&gt;
+     * &lt;p&gt;
+     * The header is also used by the {@link CSVPrinter}.
+     * &lt;/p&gt;
+     *
+     * @param headerEnum
+     *            the enum defining the header, {@code null} if disabled, empty if parsed automatically, user specified
+     *            otherwise.
+     *
+     * @return A new CSVFormat that is equal to this but with the specified header
+     * @see #withHeader(String...)
+     * @see #withSkipHeaderRecord(boolean)
+     * @since 1.3
+     */
+    public CSVFormat withHeader(final Class&lt;? extends Enum&lt;?&gt;&gt; headerEnum) {
+<span class="fc" id="L1568">        String[] header = null;</span>
+<span class="pc bpc" id="L1569" title="1 of 2 branches missed.">        if (headerEnum != null) {</span>
+<span class="fc" id="L1570">            final Enum&lt;?&gt;[] enumValues = headerEnum.getEnumConstants();</span>
+<span class="fc" id="L1571">            header = new String[enumValues.length];</span>
+<span class="fc bfc" id="L1572" title="All 2 branches covered.">            for (int i = 0; i &lt; enumValues.length; i++) {</span>
+<span class="fc" id="L1573">                header[i] = enumValues[i].name();</span>
+            }
+        }
+<span class="fc" id="L1576">        return withHeader(header);</span>
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the header of the format set from the result set metadata. The header can
+     * either be parsed automatically from the input file with:
+     *
+     * &lt;pre&gt;
+     * CSVFormat format = aformat.withHeader();
+     * &lt;/pre&gt;
+     *
+     * or specified manually with:
+     *
+     * &lt;pre&gt;
+     * CSVFormat format = aformat.withHeader(resultSet);
+     * &lt;/pre&gt;
+     * &lt;p&gt;
+     * The header is also used by the {@link CSVPrinter}.
+     * &lt;/p&gt;
+     *
+     * @param resultSet
+     *            the resultSet for the header, {@code null} if disabled, empty if parsed automatically, user specified
+     *            otherwise.
+     *
+     * @return A new CSVFormat that is equal to this but with the specified header
+     * @throws SQLException
+     *             SQLException if a database access error occurs or this method is called on a closed result set.
+     * @since 1.1
+     */
+    public CSVFormat withHeader(final ResultSet resultSet) throws SQLException {
+<span class="pc bpc" id="L1606" title="1 of 2 branches missed.">        return withHeader(resultSet != null ? resultSet.getMetaData() : null);</span>
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the header of the format set from the result set metadata. The header can
+     * either be parsed automatically from the input file with:
+     *
+     * &lt;pre&gt;
+     * CSVFormat format = aformat.withHeader();
+     * &lt;/pre&gt;
+     *
+     * or specified manually with:
+     *
+     * &lt;pre&gt;
+     * CSVFormat format = aformat.withHeader(metaData);
+     * &lt;/pre&gt;
+     * &lt;p&gt;
+     * The header is also used by the {@link CSVPrinter}.
+     * &lt;/p&gt;
+     *
+     * @param metaData
+     *            the metaData for the header, {@code null} if disabled, empty if parsed automatically, user specified
+     *            otherwise.
+     *
+     * @return A new CSVFormat that is equal to this but with the specified header
+     * @throws SQLException
+     *             SQLException if a database access error occurs or this method is called on a closed result set.
+     * @since 1.1
+     */
+    public CSVFormat withHeader(final ResultSetMetaData metaData) throws SQLException {
+<span class="fc" id="L1636">        String[] labels = null;</span>
+<span class="pc bpc" id="L1637" title="1 of 2 branches missed.">        if (metaData != null) {</span>
+<span class="fc" id="L1638">            final int columnCount = metaData.getColumnCount();</span>
+<span class="fc" id="L1639">            labels = new String[columnCount];</span>
+<span class="fc bfc" id="L1640" title="All 2 branches covered.">            for (int i = 0; i &lt; columnCount; i++) {</span>
+<span class="fc" id="L1641">                labels[i] = metaData.getColumnLabel(i + 1);</span>
+            }
+        }
+<span class="fc" id="L1644">        return withHeader(labels);</span>
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the header of the format set to the given values. The header can either be
+     * parsed automatically from the input file with:
+     *
+     * &lt;pre&gt;
+     * CSVFormat format = aformat.withHeader();
+     * &lt;/pre&gt;
+     *
+     * or specified manually with:
+     *
+     * &lt;pre&gt;
+     * CSVFormat format = aformat.withHeader(&amp;quot;name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;phone&amp;quot;);
+     * &lt;/pre&gt;
+     * &lt;p&gt;
+     * The header is also used by the {@link CSVPrinter}.
+     * &lt;/p&gt;
+     *
+     * @param header
+     *            the header, {@code null} if disabled, empty if parsed automatically, user specified otherwise.
+     *
+     * @return A new CSVFormat that is equal to this but with the specified header
+     * @see #withSkipHeaderRecord(boolean)
+     */
+    public CSVFormat withHeader(final String... header) {
+<span class="fc" id="L1671">        return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span>
+                ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
+                skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter);
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the header comments of the format set to the given values. The comments will
+     * be printed first, before the headers. This setting is ignored by the parser.
+     *
+     * &lt;pre&gt;
+     * CSVFormat format = aformat.withHeaderComments(&amp;quot;Generated by Apache Commons CSV 1.1.&amp;quot;, new Date());
+     * &lt;/pre&gt;
+     *
+     * @param headerComments
+     *            the headerComments which will be printed by the Printer before the actual CSV data.
+     *
+     * @return A new CSVFormat that is equal to this but with the specified header
+     * @see #withSkipHeaderRecord(boolean)
+     * @since 1.1
+     */
+    public CSVFormat withHeaderComments(final Object... headerComments) {
+<span class="fc" id="L1692">        return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span>
+                ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
+                skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter);
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the empty line skipping behavior of the format set to {@code true}.
+     *
+     * @return A new CSVFormat that is equal to this but with the specified empty line skipping behavior.
+     * @since {@link #withIgnoreEmptyLines(boolean)}
+     * @since 1.1
+     */
+    public CSVFormat withIgnoreEmptyLines() {
+<span class="fc" id="L1705">        return this.withIgnoreEmptyLines(true);</span>
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the empty line skipping behavior of the format set to the given value.
+     *
+     * @param ignoreEmptyLines
+     *            the empty line skipping behavior, {@code true} to ignore the empty lines between the records,
+     *            {@code false} to translate empty lines to empty records.
+     * @return A new CSVFormat that is equal to this but with the specified empty line skipping behavior.
+     */
+    public CSVFormat withIgnoreEmptyLines(final boolean ignoreEmptyLines) {
+<span class="fc" id="L1717">        return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span>
+                ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
+                skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter);
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the header ignore case behavior set to {@code true}.
+     *
+     * @return A new CSVFormat that will ignore case header name.
+     * @see #withIgnoreHeaderCase(boolean)
+     * @since 1.3
+     */
+    public CSVFormat withIgnoreHeaderCase() {
+<span class="fc" id="L1730">        return this.withIgnoreHeaderCase(true);</span>
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with whether header names should be accessed ignoring case.
+     *
+     * @param ignoreHeaderCase
+     *            the case mapping behavior, {@code true} to access name/values, {@code false} to leave the mapping as
+     *            is.
+     * @return A new CSVFormat that will ignore case header name if specified as {@code true}
+     * @since 1.3
+     */
+    public CSVFormat withIgnoreHeaderCase(final boolean ignoreHeaderCase) {
+<span class="fc" id="L1743">        return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span>
+                ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
+                skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter);
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the trimming behavior of the format set to {@code true}.
+     *
+     * @return A new CSVFormat that is equal to this but with the specified trimming behavior.
+     * @see #withIgnoreSurroundingSpaces(boolean)
+     * @since 1.1
+     */
+    public CSVFormat withIgnoreSurroundingSpaces() {
+<span class="fc" id="L1756">        return this.withIgnoreSurroundingSpaces(true);</span>
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the trimming behavior of the format set to the given value.
+     *
+     * @param ignoreSurroundingSpaces
+     *            the trimming behavior, {@code true} to remove the surrounding spaces, {@code false} to leave the
+     *            spaces as is.
+     * @return A new CSVFormat that is equal to this but with the specified trimming behavior.
+     */
+    public CSVFormat withIgnoreSurroundingSpaces(final boolean ignoreSurroundingSpaces) {
+<span class="fc" id="L1768">        return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span>
+                ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
+                skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter);
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with conversions to and from null for strings on input and output.
+     * &lt;ul&gt;
+     * &lt;li&gt;&lt;strong&gt;Reading:&lt;/strong&gt; Converts strings equal to the given {@code nullString} to {@code null} when reading
+     * records.&lt;/li&gt;
+     * &lt;li&gt;&lt;strong&gt;Writing:&lt;/strong&gt; Writes {@code null} as the given {@code nullString} when writing records.&lt;/li&gt;
+     * &lt;/ul&gt;
+     *
+     * @param nullString
+     *            the String to convert to and from {@code null}. No substitution occurs if {@code null}
+     *
+     * @return A new CSVFormat that is equal to this but with the specified null conversion string.
+     */
+    public CSVFormat withNullString(final String nullString) {
+<span class="fc" id="L1787">        return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span>
+                ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
+                skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter);
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the quoteChar of the format set to the specified character.
+     *
+     * @param quoteChar
+     *            the quoteChar character
+     * @return A new CSVFormat that is equal to this but with the specified character as quoteChar
+     * @throws IllegalArgumentException
+     *             thrown if the specified character is a line break
+     */
+    public CSVFormat withQuote(final char quoteChar) {
+<span class="fc" id="L1802">        return withQuote(Character.valueOf(quoteChar));</span>
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the quoteChar of the format set to the specified character.
+     *
+     * @param quoteChar
+     *            the quoteChar character, use {@code null} to disable
+     * @return A new CSVFormat that is equal to this but with the specified character as quoteChar
+     * @throws IllegalArgumentException
+     *             thrown if the specified character is a line break
+     */
+    public CSVFormat withQuote(final Character quoteChar) {
+<span class="fc bfc" id="L1815" title="All 2 branches covered.">        if (isLineBreak(quoteChar)) {</span>
+<span class="fc" id="L1816">            throw new IllegalArgumentException(&quot;The quoteChar cannot be a line break&quot;);</span>
+        }
+<span class="fc" id="L1818">        return new CSVFormat(delimiter, quoteChar, quoteMode, commentMarker, escapeCharacter, ignoreSurroundingSpaces,</span>
+                ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord,
+                allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter);
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the output quote policy of the format set to the specified value.
+     *
+     * @param quoteModePolicy
+     *            the quote policy to use for output.
+     *
+     * @return A new CSVFormat that is equal to this but with the specified quote policy
+     */
+    public CSVFormat withQuoteMode(final QuoteMode quoteModePolicy) {
+<span class="fc" id="L1832">        return new CSVFormat(delimiter, quoteCharacter, quoteModePolicy, commentMarker, escapeCharacter,</span>
+                ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
+                skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter);
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the record separator of the format set to the specified character.
+     *
+     * &lt;p&gt;
+     * &lt;strong&gt;Note:&lt;/strong&gt; This setting is only used during printing and does not affect parsing. Parsing currently
+     * only works for inputs with '\n', '\r' and &quot;\r\n&quot;
+     * &lt;/p&gt;
+     *
+     * @param recordSeparator
+     *            the record separator to use for output.
+     *
+     * @return A new CSVFormat that is equal to this but with the the specified output record separator
+     */
+    public CSVFormat withRecordSeparator(final char recordSeparator) {
+<span class="fc" id="L1851">        return withRecordSeparator(String.valueOf(recordSeparator));</span>
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with the record separator of the format set to the specified String.
+     *
+     * &lt;p&gt;
+     * &lt;strong&gt;Note:&lt;/strong&gt; This setting is only used during printing and does not affect parsing. Parsing currently
+     * only works for inputs with '\n', '\r' and &quot;\r\n&quot;
+     * &lt;/p&gt;
+     *
+     * @param recordSeparator
+     *            the record separator to use for output.
+     *
+     * @return A new CSVFormat that is equal to this but with the the specified output record separator
+     * @throws IllegalArgumentException
+     *             if recordSeparator is none of CR, LF or CRLF
+     */
+    public CSVFormat withRecordSeparator(final String recordSeparator) {
+<span class="fc" id="L1870">        return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span>
+                ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header,
+                skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter);
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with skipping the header record set to {@code true}.
+     *
+     * @return A new CSVFormat that is equal to this but with the the specified skipHeaderRecord setting.
+     * @see #withSkipHeaderRecord(boolean)
+     * @see #withHeader(String...)
+     * @since 1.1
+     */
+    public CSVFormat withSkipHeaderRecord() {
+<span class="fc" id="L1884">        return this.withSkipHeaderRecord(true);</span>
+    }
+
+    /**
+     * Returns a new {@code CSVFormat} with whether to skip the header record.
+     *
+     * @param skipHeaderRecord
+     *            whether to skip the header record.
+     *
+     * @return A new CSVFormat that is equal to this but with the the specified skipHeaderRecord setting.
+     * @see #withHeader(String...)
+     */
+    public CSVFormat withSkipHeaderRecord(final boolean skipHeaderRecord) {
+<span class="fc" id="L1897">        return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span>

[... 57 lines stripped ...]