use of com.orion.ops.handler.sftp.direct.DirectDownloader in project orion-ops by lijiahangmax.
the class FileDownloadServiceImpl method execDownload.
@Override
public void execDownload(String token, HttpServletResponse response) throws IOException {
// 获取token信息
FileDownloadDTO downloadFile = this.getPathByDownloadToken(token);
if (downloadFile == null) {
throw Exceptions.notFound();
}
InputStream inputStream = null;
DirectDownloader downloader = null;
try {
// 获取类型
if (FileDownloadType.of(downloadFile.getType()).isLocal()) {
// 本地文件
File file = Optional.of(downloadFile).map(FileDownloadDTO::getFilePath).filter(Strings::isNotBlank).map(File::new).filter(Files1::isFile).orElseThrow(Exceptions::notFound);
inputStream = Files1.openInputStreamFastSafe(file);
} else {
// 远程文件
downloader = new DirectDownloader(downloadFile.getMachineId());
inputStream = downloader.open().getFile(downloadFile.getFilePath());
}
// 返回
Servlets.transfer(response, inputStream, Strings.bytes(downloadFile.getFileName(), Const.UTF_8));
} finally {
Streams.close(inputStream);
Streams.close(downloader);
}
}
Aggregations