Package org.apache.juneau.marshall.csv
Class CsvReader
java.lang.Object
org.apache.juneau.marshall.csv.CsvReader
- All Implemented Interfaces:
Closeable,AutoCloseable
Specialized reader for parsing CSV input.
Parses CSV data according to RFC 4180 with support for:
- Quoted fields (configurable quote character)
- Embedded delimiter characters within quoted fields
- Embedded newlines within quoted fields
- Embedded quote characters escaped by doubling (RFC 4180 style)
- Both CRLF and LF line endings
- Optional whitespace trimming
Notes:
- This class is not intended for external use.
-
Constructor Summary
ConstructorsConstructorDescriptionCsvReader(ParserReader r, char delimiter, char quoteChar, boolean trimStrings) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static CsvReaderfrom(ParserPipe pipe, char delimiter, char quoteChar, boolean trimStrings) Creates aCsvReaderfrom aParserPipe.booleanisEof()Returns whether the end of input has been reached.readRow()Reads a single row of CSV data, returningnull at end of input.
-
Constructor Details
-
CsvReader
Constructor.- Parameters:
r- The parser reader to wrap.
Must not benull .delimiter- The field delimiter character (typically',' ).quoteChar- The quote character (typically'"' ).trimStrings- Iftrue , field values are trimmed of surrounding whitespace.
-
-
Method Details
-
from
public static CsvReader from(ParserPipe pipe, char delimiter, char quoteChar, boolean trimStrings) throws IOException Creates aCsvReaderfrom aParserPipe.- Parameters:
pipe- The parser pipe.
Must not benull .delimiter- The delimiter character.quoteChar- The quote character.trimStrings- Whether to trim strings.- Returns:
- A new
CsvReader, ornull if the pipe has no input. - Throws:
IOException- Thrown by underlying stream.
-
readRow
Reads a single row of CSV data, returningnull at end of input.Each call advances past one record (terminated by LF, CRLF, or end-of-file). Quoted fields may span multiple lines.
- Returns:
- A list of field values for the row, or
null if end of input has been reached. - Throws:
IOException- Thrown by underlying stream.ParseException- If the CSV is malformed (e.g. an unclosed quoted field).
-
isEof
Returns whether the end of input has been reached.- Returns:
true if end of input has been reached.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-