use of edu.uci.ics.texera.dataflow.sink.excel.ExcelSinkPredicate in project textdb by TextDB.
the class DownloadFileResource method downloadExcelFile.
@GET
@Path("/result")
public Response downloadExcelFile(@QueryParam("resultID") String resultID) throws JsonParseException, JsonMappingException, IOException {
java.nio.file.Path resultFile = QueryPlanResource.resultDirectory.resolve(resultID + ".json");
if (Files.notExists(resultFile)) {
System.out.println(resultFile + " file does not found");
return Response.status(Status.NOT_FOUND).build();
}
ArrayList<Tuple> result = new ObjectMapper().readValue(Files.readAllBytes(resultFile), TypeFactory.defaultInstance().constructCollectionLikeType(ArrayList.class, Tuple.class));
if (result.size() == 0) {
System.out.println(resultFile + " file is empty");
return Response.status(Status.NOT_FOUND).build();
}
TupleSourceOperator tupleSource = new TupleSourceOperator(result, result.get(0).getSchema());
ExcelSink excelSink = new ExcelSinkPredicate().newOperator();
excelSink.setInputOperator(tupleSource);
excelSink.open();
excelSink.collectAllTuples();
excelSink.close();
StreamingOutput fileStream = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
byte[] data = Files.readAllBytes(excelSink.getFilePath());
output.write(data);
output.flush();
}
};
return Response.ok(fileStream, MediaType.APPLICATION_OCTET_STREAM).header("content-disposition", "attachment; filename=result.xlsx").build();
}
use of edu.uci.ics.texera.dataflow.sink.excel.ExcelSinkPredicate in project textdb by TextDB.
the class PredicateBaseTest method testExcelSink.
@Test
public void testExcelSink() throws Exception {
ExcelSinkPredicate excelSinkPredicate = new ExcelSinkPredicate(10, 10);
testPredicate(excelSinkPredicate);
}
Aggregations