Example usage for org.apache.commons.csv QuoteMode MINIMAL

List of usage examples for org.apache.commons.csv QuoteMode MINIMAL

Introduction

In this page you can find the example usage for org.apache.commons.csv QuoteMode MINIMAL.

Prototype

QuoteMode MINIMAL

To view the source code for org.apache.commons.csv QuoteMode MINIMAL.

Click Source Link

Document

Quotes fields which contain special characters such as a delimiter, quote character or any of the characters in line separator.

Usage

From source file:com.github.jferard.pgloaderutils.sniffer.csv.CSVOptionalHeaderSniffer.java

public static CSVOptionalHeaderSniffer getSniffer(final byte delimiter, final byte quote, final byte escape,
        final Charset charset) {
    CSVFormat csvFormat = CSVFormat.newFormat((char) delimiter).withQuote((char) quote)
            .withQuoteMode(QuoteMode.MINIMAL).withAllowMissingColumnNames();
    if (escape != quote)
        csvFormat = csvFormat.withEscape((char) escape);
    return new CSVOptionalHeaderSniffer(csvFormat, charset);
}

From source file:com.lithium.flow.util.CsvFormats.java

@Nullable
private static QuoteMode getQuoteMode(@Nonnull Config config, @Nonnull String key) {
    switch (config.getString(key, "default")) {
    case "default":
        return null;
    case "all":
        return QuoteMode.ALL;
    case "minimal":
        return QuoteMode.MINIMAL;
    case "non_numeric":
        return QuoteMode.NON_NUMERIC;
    case "none":
        return QuoteMode.NONE;
    default://from  ww  w.ja va 2  s  . c o m
        return null;
    }
}

From source file:com.thinkbiganalytics.discovery.parsers.csv.CSVAutoDetect.java

/**
 * Parses a sample file to allow schema specification when creating a new feed.
 *
 * @param sampleText the sample text//from   ww  w . j  a  v a  2 s  .c  om
 * @return A configured parser
 * @throws IOException If there is an error parsing the sample file
 */
public CSVFormat detectCSVFormat(String sampleText, boolean headerRow, String seperatorStr) throws IOException {
    CSVFormat format = CSVFormat.DEFAULT.withAllowMissingColumnNames();
    Character separatorChar = null;
    if (StringUtils.isNotBlank(seperatorStr)) {
        separatorChar = seperatorStr.charAt(0);
    }
    try (BufferedReader br = new BufferedReader(new StringReader(sampleText))) {
        List<LineStats> lineStats = generateStats(br, separatorChar);
        Character quote = guessQuote(lineStats);
        Character delim = guessDelimiter(lineStats, sampleText, quote, headerRow);
        if (delim == null) {
            throw new IOException("Unrecognized format");
        }
        format = format.withDelimiter(delim);
        format = format.withQuoteMode(QuoteMode.MINIMAL).withQuote(quote);
    }
    return format;
}

From source file:com.thinkbiganalytics.discovery.parsers.csv.CSVFileSchemaParser.java

private CSVFormat createCSVFormat(String sampleData) throws IOException {
    CSVFormat format;//from w  w w  . j  a v  a  2s. c  om
    if (autoDetect) {
        CSVAutoDetect autoDetect = new CSVAutoDetect();
        format = autoDetect.detectCSVFormat(sampleData, this.headerRow, this.separatorChar);
        this.separatorChar = Character.toString(format.getDelimiter());
        this.quoteChar = Character.toString(format.getQuoteCharacter());
    } else {
        format = CSVFormat.DEFAULT.withAllowMissingColumnNames();

        if (StringUtils.isNotEmpty(separatorChar)) {
            format = format.withDelimiter(toChar(separatorChar).charAt(0));
        }
        if (StringUtils.isNotEmpty(escapeChar)) {
            format = format.withEscape(toChar(escapeChar).charAt(0));
        }
        if (StringUtils.isNotEmpty(quoteChar)) {
            format = format.withQuoteMode(QuoteMode.MINIMAL).withQuote(toChar(quoteChar).charAt(0));
        }
    }

    return format;
}