1 回答
TA贡献1876条经验 获得超7个赞
我建议你使用Java 8。Future API
这是您的资源的更新。
@PostMapping("/toLinPDf")
public ResponseEntity<ByteArrayResource> convertion(
@RequestParam(value = "input", required = false) String in,
@RequestParam(value = "output", required = false) String out) throws IOException, InterruptedException {
ExecutorService executorService = Executors.newSingleThreadExecutor();
Callable<String> callable = () -> {
linearizeService.LinearizePDf(in, out);
return "Task ended";
};
Future<String> future = executorService.submit(callable);
String result = future.get();
executorService.shutdown();
FileSystemResource pdfFile = new FileSystemResource(out);
return ResponseEntity
.ok()
.contentLength(pdfFile.contentLength())
.contentType(
MediaType.parseMediaType("application/pdf"))
.body(new ByteArrayResource(IOUtils.toByteArray(pdfFile.getInputStream())));
}
添加回答
举报