FileParserAppComponent

Required to implement a file-parser component. File parsers parses an input stream of a file and returns structured data as a result. This can be used to parse all sorts of images such as applying machine learning to a file and return the results - or parsing a CSV file and producing the rows as structured output.

Source: Github

Example:

package my.org.components; import io.dexi.service.AppContext; import io.dexi.service.components.AppComponent; import io.dexi.service.components.FileParserAppComponent; import io.dexi.service.exceptions.UserErrorException; import io.dexi.service.utils.ResultStream; import org.apache.commons.io.IOUtils; import javax.servlet.http.HttpServletRequest; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; @AppComponent("parse-file-with-my-app") public class MyAppFileParserAppComponent implements FileParserAppComponent<MyAppConfig, MyComponentConfig> { @Override public Class<MyComponentConfig> getComponentConfigClass() { return MyComponentConfig.class; } @Override public void parse(AppContext<MyAppConfig, MyComponentConfig> ctxt, HttpServletRequest request, ResultStream resultStream) { try (InputStream in = request.getInputStream()) { //Implement parsing of input stream here resultStream.append(myResult); } catch (IOException e) { throw new UserErrorException("Failed to parse data from input stream" , e); } } }
components: - name: parse-file-with-my-app type: file-parser title: Parse file using my app specification: endpoint: # Will invoke MyAppFileParserAppComponent::parse url: "${baseUrl}/dexi/file/parse" method: POST outputs: rowIndex: title: Row Index type: number rowValue: title: Row Value type: string