Class CsvWriter<T>
- java.lang.Object
-
- com.github.timo_reymann.csv_parser.io.CsvWriter<T>
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
public class CsvWriter<T> extends Object implements AutoCloseable, Closeable, Flushable
Write csv files- Since:
- 20.12.17
- Author:
- Timo Reymann
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CsvWriter.Builder<T>
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close underylingBufferedWriter
andFileWriter
void
flush()
Flush underlyingBufferedWriter
andFileWriter
void
writeFileHeading()
Write only file headings to file without any datavoid
writeLine(List<T> beans)
Write beans to filevoid
writeLine(T bean)
Write bean to file
-
-
-
Constructor Detail
-
CsvWriter
public CsvWriter(Class<T> clazz, File file, boolean append, boolean hasHeadings, String seperator) throws IOException
Create new csv writer- Parameters:
clazz
- Class for beanfile
- File to writeappend
- Append to outputhasHeadings
- Has the file headings, if this is a new file headers are automatically generatedseperator
- Seperator for csv file- Throws:
IOException
- Error opening file streams
-
-
Method Detail
-
writeFileHeading
public void writeFileHeading() throws IllegalAccessException, InstantiationException, IOException
Write only file headings to file without any data- Throws:
IllegalAccessException
- Error getting fields of entityInstantiationException
- Error creating new instance of entityIOException
- Error writing to file
-
writeLine
public void writeLine(T bean) throws IllegalAccessException, IOException
Write bean to file- Parameters:
bean
- Bean to write- Throws:
IllegalAccessException
- Error getting value from objectIOException
- Error writing to file
-
writeLine
public void writeLine(List<T> beans) throws IOException, IllegalAccessException
Write beans to file- Parameters:
beans
- Beans to write- Throws:
IllegalAccessException
- Error getting value from objectIOException
- Error writing to file
-
flush
public void flush() throws IOException
Flush underlyingBufferedWriter
andFileWriter
- Specified by:
flush
in interfaceFlushable
- Throws:
IOException
- Error flushing
-
close
public void close() throws IOException
Close underylingBufferedWriter
andFileWriter
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- Error close writers
-
-