Package com.groiss.fileimport.csv
Class CSVReader
java.lang.Object
com.groiss.fileimport.csv.CSVReader
- All Implemented Interfaces:
StructuredFileReader
,AutoCloseable
a utility class which reads RFC4180 (CSV http://tools.ietf.org/html/rfc4180)
compliant records from an inputstream
many setter-methods for changing the behavior are available
there's also a way for reading fixed length records
-
Constructor Summary
ConstructorDescriptionCSVReader
(CSVSettings settings) CSVReader
(InputStream input) CSVReader
(InputStream input, CSVSettings settings) CSVReader
(InputStream input, Charset charset) CSVReader
(Reader input, CSVSettings settings) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
closes the underlying IO-structures and releases any resources.get
(int index) returns the field with the given index of the current recordreturns the field with the given name of the current record is only working if headers are setint
returns the current amount of successfully read rowsreturns the settings applied to this readergets the current record's values mapped to the column names if the column names aren't unique, the values may be overwrittenboolean
reads the next record data will be available thruget(int)
andget(String)
void
skips one recordvoid
skipRecords
(int count) skips count records
-
Constructor Details
-
CSVReader
public CSVReader() -
CSVReader
- Parameters:
settings
- to use
-
CSVReader
public CSVReader(Element config) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException -
CSVReader
- Parameters:
input
- the stream to read from
-
CSVReader
- Parameters:
input
- the stream to read fromcharset
- the charset to use
-
CSVReader
- Parameters:
input
- the stream to read fromsettings
- the settings to use
-
CSVReader
- Parameters:
input
- the reader to read from
-
CSVReader
- Parameters:
input
- the reader to read fromsettings
- the settings to use
-
-
Method Details
-
get
returns the field with the given index of the current record- Parameters:
index
-- Returns:
-
get
returns the field with the given name of the current record is only working if headers are set- Parameters:
columnName
-- Returns:
-
getRowCount
public int getRowCount()Description copied from interface:StructuredFileReader
returns the current amount of successfully read rows- Specified by:
getRowCount
in interfaceStructuredFileReader
- Returns:
- the rowCount
-
getSettings
Description copied from interface:StructuredFileReader
returns the settings applied to this reader- Specified by:
getSettings
in interfaceStructuredFileReader
- Returns:
-
getValueMap
Description copied from interface:StructuredFileReader
gets the current record's values mapped to the column names if the column names aren't unique, the values may be overwritten- Specified by:
getValueMap
in interfaceStructuredFileReader
- Returns:
-
readRecord
reads the next record data will be available thruget(int)
andget(String)
- Specified by:
readRecord
in interfaceStructuredFileReader
- Returns:
- Throws:
IOException
-
skipRecord
skips one record- Throws:
IOException
-
skipRecords
skips count records- Parameters:
count
-- Throws:
IOException
-
close
Description copied from interface:StructuredFileReader
closes the underlying IO-structures and releases any resources. no further reading may be possible- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceStructuredFileReader
- Throws:
IOException
-
getRowComment
-