Search in sources :

Example 1 with NonCloseableInputStream

use of org.apache.nifi.stream.io.NonCloseableInputStream in project nifi by apache.

the class CSVReader method createRecordReader.

@Override
public RecordReader createRecordReader(final Map<String, String> variables, final InputStream in, final ComponentLog logger) throws IOException, SchemaNotFoundException {
    // Use Mark/Reset of a BufferedInputStream in case we read from the Input Stream for the header.
    final BufferedInputStream bufferedIn = new BufferedInputStream(in);
    bufferedIn.mark(1024 * 1024);
    final RecordSchema schema = getSchema(variables, new NonCloseableInputStream(bufferedIn), null);
    bufferedIn.reset();
    if (APACHE_COMMONS_CSV.getValue().equals(csvParser)) {
        return new CSVRecordReader(bufferedIn, logger, schema, csvFormat, firstLineIsHeader, ignoreHeader, dateFormat, timeFormat, timestampFormat, charSet);
    } else if (JACKSON_CSV.getValue().equals(csvParser)) {
        return new JacksonCSVRecordReader(bufferedIn, logger, schema, csvFormat, firstLineIsHeader, ignoreHeader, dateFormat, timeFormat, timestampFormat, charSet);
    } else {
        throw new IOException("Parser not supported");
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) NonCloseableInputStream(org.apache.nifi.stream.io.NonCloseableInputStream) IOException(java.io.IOException) RecordSchema(org.apache.nifi.serialization.record.RecordSchema)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 RecordSchema (org.apache.nifi.serialization.record.RecordSchema)1 NonCloseableInputStream (org.apache.nifi.stream.io.NonCloseableInputStream)1