@GET
@Path("download")
@Consumes(MediaType.APPLICATION_JSON)
public Response downloadData(@PathParam("jobId") JobId jobId)
throws IOException, JobResourceNotFoundException, JobNotFoundException {
final Job job = jobsService.getJob(jobId);
final JobInfo jobInfo = job.getJobAttempt().getInfo();
if (jobInfo.getQueryType() == QueryType.UI_EXPORT) {
final DownloadDataResponse downloadDataResponse = datasetService.downloadData(jobInfo.getDownloadInfo(), securityContext.getUserPrincipal().getName());
final StreamingOutput streamingOutput = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
IOUtils.copyBytes(downloadDataResponse.getInput(), output, 4096, true);
}
};
return Response.ok(streamingOutput, MediaType.APPLICATION_OCTET_STREAM)
.header("Content-Disposition", "attachment; filename=\"" + downloadDataResponse.getFileName() + "\"").build();
} else {
throw new JobResourceNotFoundException(jobId, format("Job %s has no data that can not be downloaded, invalid type %s", jobId, jobInfo.getQueryType()));
}
}
JobResource.java 文件源码
java
阅读 33
收藏 0
点赞 0
评论 0
项目:dremio-oss
作者:
评论列表
文章目录