Package org.supercsv.io
Class CsvMapWriter
- java.lang.Object
-
- org.supercsv.io.AbstractCsvWriter
-
- org.supercsv.io.CsvMapWriter
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
,ICsvMapWriter
,ICsvWriter
public class CsvMapWriter extends AbstractCsvWriter implements ICsvMapWriter
CsvMapWriter writes Maps of Objects to a CSV file.- Author:
- Kasper B. Graversen, James Bassett
-
-
Constructor Summary
Constructors Constructor Description CsvMapWriter(java.io.Writer writer, CsvPreference preference)
Constructs a new CsvMapWriter with the supplied Writer and CSV preferences.CsvMapWriter(java.io.Writer writer, CsvPreference preference, boolean bufferizeWriter)
Constructs a new CsvMapWriter with the supplied Writer, CSV preferences and option to bufferize the writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
write(java.util.Map<java.lang.String,?> values, java.lang.String... nameMapping)
Writes the values of the Map as columns of a CSV file, using the supplied name mapping to map values to the appropriate columns.void
write(java.util.Map<java.lang.String,?> values, java.lang.String[] nameMapping, CellProcessor[] processors)
Writes the values of the Map as columns of a CSV file, using the supplied name mapping to map values to the appropriate columns.-
Methods inherited from class org.supercsv.io.AbstractCsvWriter
close, flush, getLineNumber, getRowNumber, incrementRowAndLineNo, writeComment, writeHeader, writeRow, writeRow, writeRow
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.supercsv.io.ICsvWriter
getLineNumber, getRowNumber, writeComment, writeHeader
-
-
-
-
Constructor Detail
-
CsvMapWriter
public CsvMapWriter(java.io.Writer writer, CsvPreference preference)
Constructs a new CsvMapWriter with the supplied Writer and CSV preferences. Note that the writer will be wrapped in a BufferedWriter before accessed.- Parameters:
writer
- the writerpreference
- the CSV preferences- Throws:
java.lang.NullPointerException
- if writer or preference are null- Since:
- 1.0
-
CsvMapWriter
public CsvMapWriter(java.io.Writer writer, CsvPreference preference, boolean bufferizeWriter)
Constructs a new CsvMapWriter with the supplied Writer, CSV preferences and option to bufferize the writer.- Parameters:
writer
- the writerpreference
- the CSV preferencesbufferizeWriter
- iftrue
, the writer will be wrapped in a BufferedWriter before accessed.- Throws:
java.lang.NullPointerException
- if writer or preference are null- Since:
- 1.0
-
-
Method Detail
-
write
public void write(java.util.Map<java.lang.String,?> values, java.lang.String... nameMapping) throws java.io.IOException
Writes the values of the Map as columns of a CSV file, using the supplied name mapping to map values to the appropriate columns. toString() will be called on each element prior to writing.- Specified by:
write
in interfaceICsvMapWriter
- Parameters:
values
- the Map containing the values to writenameMapping
- an array of Strings linking the Map keys to their corresponding CSV columns (the array length should match the number of columns). A null entry in the array indicates that the column should be ignored (the column will be empty).- Throws:
java.io.IOException
- if an I/O error occurred
-
write
public void write(java.util.Map<java.lang.String,?> values, java.lang.String[] nameMapping, CellProcessor[] processors) throws java.io.IOException
Writes the values of the Map as columns of a CSV file, using the supplied name mapping to map values to the appropriate columns. toString() will be called on each element prior to writing.- Specified by:
write
in interfaceICsvMapWriter
- Parameters:
values
- the Map containing the values to writenameMapping
- an array of Strings linking the Map keys to their corresponding CSV columns (the array length should match the number of columns). A null entry in the array indicates that the column should be ignored (the column will be empty).processors
- an array of CellProcessors used to further process data before it is written (each element in the processors array corresponds with a CSV column - the number of processors should match the number of columns). A null entry indicates no further processing is required (the value returned by toString() will be written as the column value).- Throws:
java.io.IOException
- if an I/O error occurred
-
-