All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sfm.csv.impl.cellreader.DateCellValueReader Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

The newest version!
package org.sfm.csv.impl.cellreader;

import org.sfm.csv.CellValueReader;
import org.sfm.csv.impl.ParsingContext;
import org.sfm.csv.impl.ParsingException;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;

public class DateCellValueReader implements CellValueReader {
	
	private int index;

	public DateCellValueReader(int index) {
		this.index = index;
	}
	
	@Override
	public Date read(char[] chars, int offset, int length, ParsingContext parsingContext) {
		if (length == 0) return null;

		String str = StringCellValueReader.readString(chars, offset, length);
		try {
			DateFormat df = parsingContext.getDateFormat(index);
			return df.parse(str);
		} catch (ParseException e) {
			throw new ParsingException(e.getMessage());
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy