Search in sources :

Example 1 with XLSXOutputWriter

use of org.finos.legend.pure.m3.execution.XLSXOutputWriter in project legend-pure by finos.

the class ExecutionManager method execute.

private void execute(CoreInstance function, ListIterable<CoreInstance> parameters, HttpResponseWriter response, HttpInformation httpInformation, boolean canStreamOutput, OutputFormat format) {
    long start = System.currentTimeMillis();
    try {
        CanStreamState.setCanStream(canStreamOutput);
        response.setIsStreamingResponse(canStreamOutput);
        this.addContentTypeAndDispositionHeaders(response, httpInformation);
        response.setHeader("Trailer", "X-Streaming-Error");
        // Do not open outputStream in try-with-resources
        OutputStream outputStream = response.getOutputStream();
        try {
            OutputWriter writer = this.functionExecution.newOutputWriter();
            if (format == OutputFormat.XLSX) {
                writer = new XLSXOutputWriter(writer);
            }
            this.functionExecution.start(function, parameters, outputStream, writer);
        } catch (PureExecutionStreamingException ex) {
        }
        // outputStream must NOT be closed in case of an uncaught exception
        // so the call to close must not be in a finally block or implicit in a try-with-resources
        outputStream.close();
    } catch (Throwable t) {
        if (t instanceof RuntimeException) {
            throw (RuntimeException) t;
        }
        if (t instanceof Error) {
            throw (Error) t;
        }
        throw new RuntimeException(t);
    } finally {
        // Reset
        CanStreamState.resetCanStream();
    }
}
Also used : OutputStream(java.io.OutputStream) PureExecutionStreamingException(org.finos.legend.pure.m3.exception.PureExecutionStreamingException) OutputWriter(org.finos.legend.pure.m3.execution.OutputWriter) XLSXOutputWriter(org.finos.legend.pure.m3.execution.XLSXOutputWriter) XLSXOutputWriter(org.finos.legend.pure.m3.execution.XLSXOutputWriter)

Aggregations

OutputStream (java.io.OutputStream)1 PureExecutionStreamingException (org.finos.legend.pure.m3.exception.PureExecutionStreamingException)1 OutputWriter (org.finos.legend.pure.m3.execution.OutputWriter)1 XLSXOutputWriter (org.finos.legend.pure.m3.execution.XLSXOutputWriter)1