CARVIEW |
Select Language
HTTP/2 200
server: GitHub.com
content-type: text/html; charset=utf-8
last-modified: Thu, 29 Oct 2015 19:20:12 GMT
access-control-allow-origin: *
etag: W/"5632716c-7d0f"
expires: Wed, 23 Jul 2025 07:04:27 GMT
cache-control: max-age=600
content-encoding: gzip
x-proxy-cache: MISS
x-github-request-id: 6200:3B88AB:5CC7F:71134:68808723
accept-ranges: bytes
age: 0
date: Wed, 23 Jul 2025 06:54:27 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210025-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753253668.686273,VS0,VE233
vary: Accept-Encoding
x-fastly-request-id: 8af6f7e54aeefb127742d8e69ceea762a172d98c
content-length: 4519
CsvBeanReader (Super CSV 2.4.0 API)
org.supercsv.io
Class CsvBeanReader
- java.lang.Object
-
- org.supercsv.io.AbstractCsvReader
-
- org.supercsv.io.CsvBeanReader
-
- All Implemented Interfaces:
- Closeable, AutoCloseable, ICsvBeanReader, ICsvReader
public class CsvBeanReader extends AbstractCsvReader implements ICsvBeanReader
CsvBeanReader reads a CSV file by instantiating a bean for every row and mapping each column to a field on the bean (using the supplied name mapping). The bean to populate can be either a class or interface. If a class is used, it must be a valid Javabean, i.e. it must have a default no-argument constructor and getter/setter methods. An interface may also be used if it defines getters/setters - a proxy object will be created that implements the interface.- Author:
- Kasper B. Graversen, James Bassett
-
-
Constructor Summary
Constructors Constructor and Description CsvBeanReader(ITokenizer tokenizer, CsvPreference preferences)
Constructs a new CsvBeanReader with the supplied (custom) Tokenizer and CSV preferences.CsvBeanReader(Reader reader, CsvPreference preferences)
Constructs a new CsvBeanReader with the supplied Reader and CSV preferences.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description <T> T
read(Class<T> clazz, String... nameMapping)
Reads a row of a CSV file and populates an instance of the specified class, using the supplied name mapping to map column values to the appropriate fields.<T> T
read(Class<T> clazz, String[] nameMapping, CellProcessor... processors)
Reads a row of a CSV file and populates an instance of the specified class, using the supplied name mapping to map column values to the appropriate fields.<T> T
read(T bean, String... nameMapping)
Reads a row of a CSV file and populates the bean, using the supplied name mapping to map column values to the appropriate fields.<T> T
read(T bean, String[] nameMapping, CellProcessor... processors)
Reads a row of a CSV file and populates the bean, using the supplied name mapping to map column values to the appropriate fields.-
Methods inherited from class org.supercsv.io.AbstractCsvReader
close, executeProcessors, get, getColumns, getHeader, getLineNumber, getPreferences, getRowNumber, getUntokenizedRow, length, readRow
-
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.ICsvReader
get, getHeader, getLineNumber, getRowNumber, getUntokenizedRow, length
-
-
-
-
Constructor Detail
-
CsvBeanReader
public CsvBeanReader(Reader reader, CsvPreference preferences)
Constructs a new CsvBeanReader with the supplied Reader and CSV preferences. Note that the reader will be wrapped in a BufferedReader before accessed.- Parameters:
reader
- the readerpreferences
- the CSV preferences- Throws:
NullPointerException
- if reader or preferences are null
-
CsvBeanReader
public CsvBeanReader(ITokenizer tokenizer, CsvPreference preferences)
Constructs a new CsvBeanReader with the supplied (custom) Tokenizer and CSV preferences. The tokenizer should be set up with the Reader (CSV input) and CsvPreference beforehand.- Parameters:
tokenizer
- the tokenizerpreferences
- the CSV preferences- Throws:
NullPointerException
- if tokenizer or preferences are null
-
-
Method Detail
-
read
public <T> T read(Class<T> clazz, String... nameMapping) throws IOException
Reads a row of a CSV file and populates an instance of the specified class, using the supplied name mapping to map column values to the appropriate fields.- Specified by:
read
in interfaceICsvBeanReader
- Type Parameters:
T
- the bean type- Parameters:
clazz
- the type to instantiate. If the type is a class then a new instance will be created using the default no-args constructor. If the type is an interface, a proxy object which implements the interface will be created instead.nameMapping
- an array of Strings linking the CSV columns to their corresponding field in the bean (the array length should match the number of columns). A null entry in the array indicates that the column should be ignored (the field in the bean will be null - or its default value).- Returns:
- a populated bean or null if EOF
- Throws:
IOException
- if an I/O error occurred
-
read
public <T> T read(Class<T> clazz, String[] nameMapping, CellProcessor... processors) throws IOException
Reads a row of a CSV file and populates an instance of the specified class, using the supplied name mapping to map column values to the appropriate fields. Before population the data can be further processed by cell processors (as with the nameMapping array, each element in the processors array corresponds with a CSV column). A null entry in the processors array indicates no further processing is required (the unprocessed String value will be set on the bean's field).- Specified by:
read
in interfaceICsvBeanReader
- Type Parameters:
T
- the bean type- Parameters:
clazz
- the type to instantiate. If the type is a class then a new instance will be created using the default no-args constructor. If the type is an interface, a proxy object which implements the interface will be created instead.nameMapping
- an array of Strings linking the CSV columns to their corresponding field in the bean (the array length should match the number of columns). A null entry in the array indicates that the column should be ignored (the field in the bean will be null - or its default value).processors
- an array of CellProcessors used to further process data before it is populated on the bean (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 unprocessed String value will be set on the bean's field).- Returns:
- a populated bean or null if EOF
- Throws:
IOException
- if an I/O error occurred
-
read
public <T> T read(T bean, String... nameMapping) throws IOException
Reads a row of a CSV file and populates the bean, using the supplied name mapping to map column values to the appropriate fields.- Specified by:
read
in interfaceICsvBeanReader
- Type Parameters:
T
- the bean type- Parameters:
bean
- the bean to populatenameMapping
- an array of Strings linking the CSV columns to their corresponding field in the bean (the array length should match the number of columns). A null entry in the array indicates that the column should be ignored (the field in the bean will be null - or its default value).- Returns:
- a populated bean or null if EOF
- Throws:
IOException
- if an I/O error occurred
-
read
public <T> T read(T bean, String[] nameMapping, CellProcessor... processors) throws IOException
Reads a row of a CSV file and populates the bean, using the supplied name mapping to map column values to the appropriate fields. Before population the data can be further processed by cell processors (as with the nameMapping array, each element in the processors array corresponds with a CSV column). A null entry in the processors array indicates no further processing is required (the unprocessed String value will be set on the bean's field).- Specified by:
read
in interfaceICsvBeanReader
- Type Parameters:
T
- the bean type- Parameters:
bean
- the bean to populatenameMapping
- an array of Strings linking the CSV columns to their corresponding field in the bean (the array length should match the number of columns). A null entry in the array indicates that the column should be ignored (the field in the bean will be null - or its default value).processors
- an array of CellProcessors used to further process data before it is populated on the bean (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 unprocessed String value will be set on the bean's field).- Returns:
- a populated bean or null if EOF
- Throws:
IOException
- if an I/O error occurred
-
-
Copyright © 2007–2015 Super CSV. All rights reserved.