Example usage for org.apache.commons.csv CSVFormat withSkipHeaderRecord

List of usage examples for org.apache.commons.csv CSVFormat withSkipHeaderRecord

Introduction

In this page you can find the example usage for org.apache.commons.csv CSVFormat withSkipHeaderRecord.

Prototype

public CSVFormat withSkipHeaderRecord() 

Source Link

Document

Sets skipping the header record to true .

Usage

From source file:org.apache.nifi.csv.CSVRecordReader.java

public CSVRecordReader(final InputStream in, final ComponentLog logger, final RecordSchema schema,
        final CSVFormat csvFormat, final boolean hasHeader, final boolean ignoreHeader, final String dateFormat,
        final String timeFormat, final String timestampFormat, final String encoding) throws IOException {

    this.schema = schema;
    final DateFormat df = dateFormat == null ? null : DataTypeUtils.getDateFormat(dateFormat);
    final DateFormat tf = timeFormat == null ? null : DataTypeUtils.getDateFormat(timeFormat);
    final DateFormat tsf = timestampFormat == null ? null : DataTypeUtils.getDateFormat(timestampFormat);

    LAZY_DATE_FORMAT = () -> df;// w  w w .  ja  v a2 s.  c o  m
    LAZY_TIME_FORMAT = () -> tf;
    LAZY_TIMESTAMP_FORMAT = () -> tsf;

    final Reader reader = new InputStreamReader(new BOMInputStream(in), encoding);

    CSVFormat withHeader;
    if (hasHeader) {
        withHeader = csvFormat.withSkipHeaderRecord();

        if (ignoreHeader) {
            withHeader = withHeader.withHeader(schema.getFieldNames().toArray(new String[0]));
        }
    } else {
        withHeader = csvFormat.withHeader(schema.getFieldNames().toArray(new String[0]));
    }

    csvParser = new CSVParser(reader, withHeader);
}