use of com.thinkbiganalytics.spark.io.ZipStreamingOutput in project kylo by Teradata.
the class AbstractTransformController method download.
/**
* Downloads the saved results as a ZIP file.
*
* @param id the save id
* @return the zip file response
*/
@GET
@Path("{table}/save/{save}/zip")
@ApiOperation("Downloads the saved results in a ZIP file")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the saved file."), @ApiResponse(code = 404, message = "The save does not exist."), @ApiResponse(code = 500, message = "There was a problem accessing the data.") })
@Nonnull
public Response download(@Nonnull @PathParam("save") final String id) {
// Find job
SaveJob job;
try {
job = transformService.getSaveJob(id, true);
} catch (final IllegalArgumentException e) {
job = null;
}
// Get result
final SaveResult result;
if (job != null && job.isDone()) {
try {
result = job.get();
} catch (final Exception e) {
return error(Response.Status.INTERNAL_SERVER_ERROR, e);
}
} else {
result = null;
}
// Return response
if (result != null && result.getPath() != null) {
return Response.ok(new ZipStreamingOutput(result.getPath(), fileSystem)).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM).header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + id + ".zip\"").build();
} else {
return error(Response.Status.NOT_FOUND, "download.notFound");
}
}
Aggregations