Class CsvReader<T>
- java.lang.Object
-
- com.github.timo_reymann.csv_parser.io.CsvReader<T>
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
public class CsvReader<T> extends Object implements AutoCloseable, Flushable, Closeable
Reader for csv files- Since:
- 20.12.17
- Author:
- Timo Reymann
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CsvReader.Builder<T>
Builder for easily creating csv reader
-
Constructor Summary
Constructors Constructor Description CsvReader(File file, Class<T> clazz, boolean hasHeading)
Create CsvReaderCsvReader(InputStream inputStream, Class<T> clazz, boolean hasHeading)
CsvReader(String fileName, Class<T> clazz)
Deprecated.Deprecated due to implicit boolean parameterCsvReader(String fileName, Class<T> clazz, boolean hasHeading)
Create new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
CloseFileReader
andBufferedReader
instancevoid
flush()
Deprecated.Flush will be removed due to support for direct reading from an file stream, where flush is not reliable anymorejava.util.stream.Stream<T>
lines()
Get stream with remaining lines fromBufferedReader
already mapped to beans, if an error occurred during mapping, its element in list is nullT
readLine()
Read line from csv filevoid
setHasHeading(boolean hasHeading)
Set has heading propertyvoid
setSeperator(String seperator)
Set separator for splitting rows
-
-
-
Constructor Detail
-
CsvReader
public CsvReader(File file, Class<T> clazz, boolean hasHeading) throws FileNotFoundException
Create CsvReader- Parameters:
file
- File to readclazz
- Class of bean to readhasHeading
- Has the file headers for column names- Throws:
FileNotFoundException
- File was not found on disk
-
CsvReader
public CsvReader(InputStream inputStream, Class<T> clazz, boolean hasHeading)
-
CsvReader
@Deprecated public CsvReader(String fileName, Class<T> clazz) throws FileNotFoundException
Deprecated.Deprecated due to implicit boolean parameterCreate new instance- Parameters:
fileName
- Name of fileclazz
- Class of bean- Throws:
FileNotFoundException
- File was not found on disk
-
CsvReader
public CsvReader(String fileName, Class<T> clazz, boolean hasHeading) throws FileNotFoundException
Create new instance- Parameters:
fileName
- Name of fileclazz
- Class of beanhasHeading
- File has first line with headings- Throws:
FileNotFoundException
- File was not found on disk
-
-
Method Detail
-
close
public void close() throws IOException
CloseFileReader
andBufferedReader
instance- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- Error while trying to close readers
-
readLine
public T readLine() throws IOException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException
Read line from csv file- Returns:
- Mapped bean
- Throws:
IOException
- Error reading line from csv fileIllegalAccessException
- Error mapping fieldsInstantiationException
- Error creating new bean instance for mappingNoSuchMethodException
InvocationTargetException
-
lines
public java.util.stream.Stream<T> lines()
Get stream with remaining lines fromBufferedReader
already mapped to beans, if an error occurred during mapping, its element in list is null- Returns:
- Stream with mapped bean objects
-
flush
@Deprecated public void flush()
Deprecated.Flush will be removed due to support for direct reading from an file stream, where flush is not reliable anymoreFlushFileReader
andBufferedReader
-
setHasHeading
public void setHasHeading(boolean hasHeading)
Set has heading property- Parameters:
hasHeading
- Has heading (true) or not (false)
-
setSeperator
public void setSeperator(String seperator)
Set separator for splitting rows- Parameters:
seperator
- Seperator
-
-