sirius.web.data.LineBasedProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sirius-web Show documentation
Show all versions of sirius-web Show documentation
Provides a modern and scalable web server as SIRIUS module
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - [email protected]
*/
package sirius.web.data;
import sirius.kernel.health.Exceptions;
import java.io.InputStream;
/**
* Processes line based input files like MS Excel or CSV.
*/
public interface LineBasedProcessor {
/**
* Generates an appropriate LineBasedProcessor based on the file extension of the given file.
*
* @param name the name of the file to process
* @param input an input stream containing the data to import
* @return an appropriate processor for the given file
* @throws sirius.kernel.health.HandledException if no processor can handle the given file
*/
static LineBasedProcessor create(String name, InputStream input) {
if (name.toLowerCase().endsWith("xls")) {
return new XLSProcessor(input, false);
}
if (name.toLowerCase().endsWith("xlsx")) {
return new XLSProcessor(input, true);
}
if (name.toLowerCase().endsWith("csv")) {
return new CSVProcessor(input);
}
throw Exceptions.createHandled().withSystemErrorMessage("Cannot process files of type: %s", name).handle();
}
/**
* Starts processing and sends each line to the given rowProcessor.
*
* @param rowProcessor the processor which handles each row of the file
* @throws Exception in case an error occurred while processing.
*/
void run(RowProcessor rowProcessor) throws Exception;
}