use of jetbrains.buildServer.serverSide.SBuild in project teamcity-torrent-plugin by JetBrains.
the class DownloadTorrentController method doHandle.
@Override
protected ModelAndView doHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response) throws Exception {
String buildIdParam = request.getParameter("buildId");
String path = request.getParameter("file");
String torrentPath = path + TorrentUtil.TORRENT_FILE_SUFFIX;
File torrentFile = null;
long buildId = Long.parseLong(buildIdParam);
SBuild build = myBuildsManager.findBuildInstanceById(buildId);
if (build != null) {
torrentFile = myTorrentsManager.getTorrentFile(build, torrentPath);
if (!torrentFile.isFile()) {
torrentFile = null;
}
}
if (torrentFile == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else {
response.setContentType(WebUtil.getMimeType(request, torrentFile.getName()));
// force set content-disposition to attachment
WebUtil.setContentDisposition(request, response, torrentFile.getName(), false);
ServletOutputStream output = response.getOutputStream();
FileInputStream fis = null;
try {
fis = new FileInputStream(torrentFile);
StreamUtil.copyStreamContent(fis, output);
} finally {
FileUtil.close(fis);
output.close();
}
}
return null;
}
Aggregations