public class CSVReader extends TextReader
DataEndpoint.State
EOF, reader
currentRecord, fieldNames, lastRow, startingRow
fieldLineage, recordLineage
lastRecord, PRODUCT, PRODUCT_VERSION, VENDOR, XML_INPUT_FACTORY_KEY
BUFFER_SIZE, captureElapsedTime, DEFAULT_READ_BUFFER_SIZE
id, log, name, TIMESTAMP_FORMAT
Constructor and Description |
---|
CSVReader(File file) |
CSVReader(Reader reader) |
Modifier and Type | Method and Description |
---|---|
DataException |
addExceptionProperties(DataException exception)
Adds this endpoint's current state to a
DataException . |
protected Record |
addLineage(Record record) |
protected boolean |
fillRecord(Record record) |
long |
getColumnNumber() |
String |
getEndingQuote()
Returns the string used to mark the ending of text values that may contain commas and other special characters (defaults to double quote - ").
|
String |
getFieldSeparator() |
String[] |
getLineSeparators()
Returns the strings used to separate records or
null if none were explicitly assigned. |
LineParser |
getParser() |
String |
getQuoteChar()
Returns the starting quote - same as calling getStartingQuote() (defaults to double quote - ").
|
String |
getStartingQuote()
Returns the string used to mark the beginning of text values that may contain commas and other special characters (defaults to double quote - ").
|
boolean |
isAllowMultiLineText()
Indicates if line separators are allowed inside quoted fields.
|
boolean |
isAllowQuoteInField()
Indicates if unescaped quotes are allowed in fields (default to false).
|
boolean |
isLineageSupported() |
boolean |
isTrimFields()
Indicates if space and tab characters at the beginning and ending of non-quoted-values should be removed.
|
static RecordList |
parse(String text,
String fieldSeparator,
String quoteChar,
Boolean allowMultiLineText)
Utility method to quickly parse lines of CSV text.
|
static RecordList |
parse(String text,
String fieldSeparator,
String quoteChar,
Boolean allowMultiLineText,
Boolean trimFields)
Utility method to quickly parse lines of CSV text.
|
static Record |
parseLine(String line,
String fieldSeparator,
String quoteChar,
Boolean allowMultiLineText)
Utility method to quickly parse a line of CSV text.
|
static Record |
parseLine(String line,
String fieldSeparator,
String quoteChar,
Boolean allowMultiLineText,
Boolean trimFields)
Utility method to quickly parse a line of CSV text.
|
CSVReader |
setAllowMultiLineText(boolean allowMultiLineText)
Indicates if line separators are allowed inside quoted fields.
|
CSVReader |
setAllowQuoteInField(boolean allowQuoteInField)
Indicates if unescaped quotes are allowed in fields (default to false).
|
CSVReader |
setEndingQuote(String endingQuote)
Assigns the string used to mark the ending of text values that may contain commas and other special characters (defaults to double quote - ").
|
CSVReader |
setFieldNames(Collection<String> fieldNames) |
CSVReader |
setFieldNames(String... fieldNames) |
CSVReader |
setFieldNamesInFirstRow(boolean fieldNamesInFirstRow) |
CSVReader |
setFieldSeparator(char columnSeparator) |
CSVReader |
setFieldSeparator(String columnSeparator) |
CSVReader |
setLastRow(int lastRow) |
CSVReader |
setLineSeparator(String lineSeparator)
Indicates the string used to separate records.
|
CSVReader |
setLineSeparators(String... lineSeparators)
Indicates the string or strings used to separate records.
|
CSVReader |
setQuoteChar(char quoteChar) |
CSVReader |
setQuoteChar(String quoteChar)
Assigns startingQuote and endingQuote to the same value (defaults to double quote - ").
|
CSVReader |
setSaveLineage(boolean saveLineage) |
CSVReader |
setSkipEmptyRows(boolean skipEmptyRows)
Indicates that rows with only null values should not be returned by the reader (default is false).
|
CSVReader |
setStartingQuote(String startingQuote)
Assigns the string used to mark the beginning of text values that may contain commas and other special characters (defaults to double quote - ").
|
CSVReader |
setStartingRow(int startingRow) |
CSVReader |
setTrimFields(boolean trimFields)
Indicates if space and tab characters at the beginning and ending of non-quoted-values should be removed.
|
available, close, getFile, getLineNumber, open, readImpl
getFieldNames, getLastRow, getStartingRow, isFieldNamesInFirstRow, isSkipEmptyRows, read
getBufferSize, getNestedEndpoint, getNestedReader, getRootEndpoint, getRootReader, isExhausted, isSaveLineage, peek, pop, push, skip
decrementRecordCount, enableJmx, getLastRecord, getRecordCount, getRecordCountAsBigInteger, getRecordCountAsString, incrementRecordCount, isRecordCountBigInteger, resetRecordCount, toString
addElapsedtime, assertClosed, assertNotOpened, assertOpened, finalize, getClosedOn, getDescription, getElapsedTime, getElapsedTimeAsString, getOpenedOn, getOpenElapsedTime, getOpenElapsedTimeAsString, getSelfTime, getSelfTimeAsString, getState, isCaptureElapsedTime, isClosed, isOpen, setCaptureElapsedTime, setDescription
public static Record parseLine(String line, String fieldSeparator, String quoteChar, Boolean allowMultiLineText)
line
- the delimited line of text to parsefieldSeparator
- quoteChar
- allowMultiLineText
- public static Record parseLine(String line, String fieldSeparator, String quoteChar, Boolean allowMultiLineText, Boolean trimFields)
line
- fieldSeparator
- quoteChar
- allowMultiLineText
- trimFields
- public static RecordList parse(String text, String fieldSeparator, String quoteChar, Boolean allowMultiLineText)
text
- the delimited lines of text to parsefieldSeparator
- quoteChar
- allowMultiLineText
- public static RecordList parse(String text, String fieldSeparator, String quoteChar, Boolean allowMultiLineText, Boolean trimFields)
text
- fieldSeparator
- quoteChar
- allowMultiLineText
- trimFields
- public String getFieldSeparator()
public CSVReader setFieldSeparator(char columnSeparator)
public String getQuoteChar()
getStartingQuote()
public CSVReader setQuoteChar(char quoteChar)
public CSVReader setQuoteChar(String quoteChar)
setStartingQuote(String)
setEndingQuote(String)
public String getStartingQuote()
public CSVReader setStartingQuote(String startingQuote)
public String getEndingQuote()
public CSVReader setEndingQuote(String endingQuote)
public String[] getLineSeparators()
null
if none were explicitly assigned.public CSVReader setLineSeparators(String... lineSeparators)
public CSVReader setLineSeparator(String lineSeparator)
public boolean isAllowMultiLineText()
public CSVReader setAllowMultiLineText(boolean allowMultiLineText)
public boolean isAllowQuoteInField()
public CSVReader setAllowQuoteInField(boolean allowQuoteInField)
public boolean isTrimFields()
Character.isWhitespace(int)
will be removed (not only spaces and tabs).
This is helpful when CSV files may contain spaces between the commas (field separators) and values.true
.public CSVReader setTrimFields(boolean trimFields)
Character.isWhitespace(int)
will be removed (not only spaces and tabs).
This is helpful when CSV files may contain spaces between the commas (field separators) and values.true
.public LineParser getParser()
public long getColumnNumber()
public boolean isLineageSupported()
isLineageSupported
in class DataReader
protected Record addLineage(Record record)
addLineage
in class TextReader
public DataException addExceptionProperties(DataException exception)
Endpoint
DataException
. Since this method is called whenever an
exception is thrown, subclasses should override it to add their specific information.addExceptionProperties
in class TextReader
protected boolean fillRecord(Record record) throws Throwable
fillRecord
in class AbstractReader
Throwable
public CSVReader setSkipEmptyRows(boolean skipEmptyRows)
AbstractReader
setSkipEmptyRows
in class AbstractReader
public CSVReader setFieldNames(String... fieldNames)
setFieldNames
in class AbstractReader
public CSVReader setFieldNames(Collection<String> fieldNames)
setFieldNames
in class AbstractReader
public CSVReader setFieldNamesInFirstRow(boolean fieldNamesInFirstRow)
setFieldNamesInFirstRow
in class AbstractReader
public CSVReader setStartingRow(int startingRow)
setStartingRow
in class AbstractReader
public CSVReader setLastRow(int lastRow)
setLastRow
in class AbstractReader
public CSVReader setSaveLineage(boolean saveLineage)
setSaveLineage
in class DataReader
Copyright (c) 2006-2024 North Concepts Inc. All Rights Reserved.