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

com.github.skjolber.unzip.csv.AbstractSesselTjonnaCsvFileEntryStreamHandler Maven / Gradle / Ivy

package com.github.skjolber.unzip.csv;

import java.io.InputStream;
import java.util.concurrent.ThreadPoolExecutor;

import com.github.skjolber.stcsv.CsvReader;
import com.github.skjolber.unzip.FileEntryStreamHandler;

public abstract class AbstractSesselTjonnaCsvFileEntryStreamHandler implements FileEntryStreamHandler {

	protected final String name;
	protected final CsvLineHandlerFactory csvLineHandlerFactory;
	
	public AbstractSesselTjonnaCsvFileEntryStreamHandler(String name, CsvLineHandlerFactory csvLineHandlerFactory) {
		super();
		this.name = name;
		this.csvLineHandlerFactory = csvLineHandlerFactory;
	}

	@Override
	public void handle(InputStream in, ThreadPoolExecutor executor, boolean consume) throws Exception {
		CsvLineHandler handler = csvLineHandlerFactory.getHandler(name, executor);
		if(handler != null) {
			handle(createCsvReader(in), handler, executor);
		}
	}

	protected void handle(CsvReader reader, CsvLineHandler handler, ThreadPoolExecutor executor) throws Exception {
		do {
			T value = reader.next();
			if(value == null) {
				break;
			}
			handler.handleLine(value);
		} while(true);
	}

	protected abstract CsvReader createCsvReader(InputStream in) throws Exception;

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy