Search in sources :

Example 1 with HttpDownloadProcessor

use of jetbrains.buildServer.controllers.HttpDownloadProcessor in project teamcity-rest by JetBrains.

the class FilesSubResource method processCoreDownload.

private void processCoreDownload(@NotNull final Element element, @NotNull final HttpServletRequest request, @NotNull final HttpServletResponse response) {
    setCacheControl(request, response);
    boolean setContentDisposition = getSetContentDisposition(element, request, response);
    try {
        myBeanContext.getSingletonService(HttpDownloadProcessor.class).processDownload(new HttpDownloadProcessor.FileInfo() {

            @Override
            public long getLastModified() {
                return FilesSubResource.getLastModified(element);
            }

            @Override
            public long getFileSize() {
                return element.getSize();
            }

            @Override
            @NotNull
            public String getFileName() {
                return element.getName();
            }

            @Override
            @NotNull
            public String getFileDigest() {
                // note: "aggregated" build artifacts are still not handled in due way here
                return getETag(element, myUrlPrefix);
            }

            @Override
            @NotNull
            public InputStream getInputStream() throws IOException {
                // todo: see this method in HttpDownloadProcessor
                return element.getInputStream();
            }
        }, setContentDisposition, /*header is forced to attachment above*/
        request, response);
    } catch (IOException e) {
        // todo add better processing
        throw new OperationException("Error while processing file '" + element.getFullName() + "': " + e.toString(), e);
    }
}
Also used : HttpDownloadProcessor(jetbrains.buildServer.controllers.HttpDownloadProcessor) InputStream(java.io.InputStream) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull) OperationException(jetbrains.buildServer.server.rest.errors.OperationException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpDownloadProcessor (jetbrains.buildServer.controllers.HttpDownloadProcessor)1 OperationException (jetbrains.buildServer.server.rest.errors.OperationException)1 NotNull (org.jetbrains.annotations.NotNull)1