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

com.emc.mongoose.api.model.item.CsvFileItemInput Maven / Gradle / Ivy

There is a newer version: 4.0.0-alpha5
Show newest version
package com.emc.mongoose.api.model.item;

import com.github.akurilov.commons.io.file.FileInput;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 Created by kurila on 30.06.15.
 */
public class CsvFileItemInput
extends CsvItemInput
implements FileInput {
	//
	protected final Path itemsFilePath;
	/**
	 @param itemsFilePath the input stream to get the data item records from
	 @param itemFactory the concrete item factory
	 @throws IOException
	 @throws NoSuchMethodException */
	public CsvFileItemInput(final Path itemsFilePath, final ItemFactory itemFactory)
	throws IOException, NoSuchMethodException {
		super(Files.newBufferedReader(itemsFilePath, StandardCharsets.UTF_8), itemFactory);
		this.itemsFilePath = itemsFilePath;
	}
	//
	@Override
	public String toString() {
		return (itemFactory instanceof DataItemFactory ? "Data" : "") +
			"ItemsFromFile(" + itemsFilePath + ")";
	}
	//
	@Override
	public final Path getFilePath() {
		return itemsFilePath;
	}
	//
	@Override
	public void reset()
	throws IOException {
		if(itemsSrc != null) {
			itemsSrc.close();
		}
		setItemsSrc(Files.newBufferedReader(itemsFilePath, StandardCharsets.UTF_8));
	}
}