Search in sources :

Example 6 with SBuild

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;
}
Also used : SBuild(jetbrains.buildServer.serverSide.SBuild) ServletOutputStream(javax.servlet.ServletOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

SBuild (jetbrains.buildServer.serverSide.SBuild)6 File (java.io.File)3 ServletOutputStream (javax.servlet.ServletOutputStream)2 BuildPromotion (jetbrains.buildServer.serverSide.BuildPromotion)2 Nullable (org.jetbrains.annotations.Nullable)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Build (jetbrains.buildServer.Build)1 Locator (jetbrains.buildServer.server.rest.data.Locator)1 TestGroupName (jetbrains.buildServer.serverSide.TestGroupName)1 NotNull (org.jetbrains.annotations.NotNull)1