
com.github.nicosensei.textbatch.ResultFileBatchWorker Maven / Gradle / Ivy
/**
*
*/
package com.github.nicosensei.textbatch;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.LinkedList;
import java.util.List;
import com.github.nicosensei.textbatch.input.AbstractInputFileReader;
import com.github.nicosensei.textbatch.input.InputLine;
/**
* @author ngiraud
*
*/
public abstract class ResultFileBatchWorker extends Worker {
private List outputBuffer = new LinkedList();
/**
* @param input
* @param state
*/
protected ResultFileBatchWorker(
AbstractInputFileReader input, BatchState state) {
super(input, state);
}
@Override
protected void sectionComplete() throws BatchException {
if (outputBuffer.isEmpty()) {
return;
}
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
for (String line : outputBuffer) {
pw.println(line);
}
((ResultFileBatchState) getBatchState()).logResult(sw.toString());
pw.close();
outputBuffer.clear();
}
protected void addResult(String res) {
outputBuffer.add(res);
}
@Override
protected abstract void processLine(L line) throws BatchException;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy