org.csveed.api.CsvReaderImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of csveed Show documentation
Show all versions of csveed Show documentation
Java toolkit for mapping CSV-to-Bean mapping and vice versa. Redirection to Introduction in 5 seconds!
package org.csveed.api;
import org.csveed.bean.*;
import org.csveed.bean.conversion.Converter;
import org.csveed.report.GeneralError;
import org.csveed.row.HeaderImpl;
import org.csveed.row.RowReaderImpl;
import org.csveed.report.CsvException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Reader;
import java.util.List;
import java.util.Locale;
public class CsvReaderImpl implements CsvReader {
public static final Logger LOG = LoggerFactory.getLogger(CsvReaderImpl.class);
private BeanReaderImpl beanReader;
private RowReaderImpl rowReader;
public CsvReaderImpl(Reader reader) {
this.rowReader = new RowReaderImpl(reader);
}
public CsvReaderImpl(Reader reader, Class beanClass) {
this(reader, new BeanParser().getBeanInstructions(beanClass));
}
public CsvReaderImpl(Reader reader, BeanReaderInstructions beanReaderInstructions) {
this.beanReader = new BeanReaderImpl(reader, beanReaderInstructions);
this.rowReader = (RowReaderImpl)getBeanReader().getRowReader();
}
@Override
public List readBeans() {
return getBeanReader().readBeans();
}
@Override
public T readBean() {
return getBeanReader().readBean();
}
@Override
public List readRows() {
return getRowReader().readRows();
}
@Override
public Row readRow() {
return getRowReader().readRow();
}
@Override
public HeaderImpl readHeader() {
return getRowReader().readHeader();
}
@Override
public int getCurrentLine() {
return getRowReader().getCurrentLine();
}
@Override
public boolean isFinished() {
return getRowReader().isFinished();
}
@Override
public CsvReader setUseHeader(boolean useHeader) {
getRowReader().getRowReaderInstructions().setUseHeader(useHeader);
return this;
}
@Override
public CsvReader setStartRow(int startRow) {
getRowReader().getRowReaderInstructions().setStartRow(startRow);
return this;
}
@Override
public CsvReader setEscape(char symbol) {
getRowReader().getRowReaderInstructions().setEscape(symbol);
return this;
}
@Override
public CsvReader setQuote(char symbol) {
getRowReader().getRowReaderInstructions().setQuote(symbol);
return this;
}
@Override
public CsvReader setSeparator(char symbol) {
getRowReader().getRowReaderInstructions().setSeparator(symbol);
return this;
}
@Override
public CsvReader setComment(char symbol) {
getRowReader().getRowReaderInstructions().setComment(symbol);
return this;
}
@Override
public CsvReader setEndOfLine(char[] symbols) {
getRowReader().getRowReaderInstructions().setEndOfLine(symbols);
return this;
}
@Override
public CsvReader skipEmptyLines(boolean skip) {
getRowReader().getRowReaderInstructions().skipEmptyLines(skip);
return this;
}
@Override
public CsvReader skipCommentLines(boolean skip) {
getRowReader().getRowReaderInstructions().skipCommentLines(skip);
return this;
}
@Override
public CsvReader setMapper(Class extends AbstractMapper> mapper) {
getBeanReader().getBeanReaderInstructions().setMapper(mapper);
return this;
}
@Override
public CsvReader setDate(String propertyName, String dateFormat) {
getBeanReader().getBeanReaderInstructions().setDate(propertyName, dateFormat);
return this;
}
@Override
public CsvReader setLocalizedNumber(String propertyName, Locale locale) {
getBeanReader().getBeanReaderInstructions().setLocalizedNumber(propertyName, locale);
return this;
}
@Override
public CsvReader setRequired(String propertyName, boolean required) {
getBeanReader().getBeanReaderInstructions().setRequired(propertyName, required);
return this;
}
@Override
public CsvReader setConverter(String propertyName, Converter converter) {
getBeanReader().getBeanReaderInstructions().setConverter(propertyName, converter);
return this;
}
@Override
public CsvReader ignoreProperty(String propertyName) {
getBeanReader().getBeanReaderInstructions().ignoreProperty(propertyName);
return this;
}
@Override
public CsvReader mapColumnIndexToProperty(int columnIndex, String propertyName) {
getBeanReader().getBeanReaderInstructions().mapColumnIndexToProperty(columnIndex, propertyName);
return this;
}
@Override
public CsvReader mapColumnNameToProperty(String columnName, String propertyName) {
getBeanReader().getBeanReaderInstructions().mapColumnNameToProperty(columnName, propertyName);
return this;
}
private BeanReaderImpl getBeanReader() {
if (this.beanReader == null) {
throw new CsvException(new GeneralError(
"BeanReader has not been initialized. Make sure to pass BeanReaderInstructions or the bean class to CsvReader."
));
}
return this.beanReader;
}
private RowReaderImpl getRowReader() {
return this.rowReader;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy