Search in sources :

Example 6 with HttpOutput

use of org.eclipse.jetty.server.HttpOutput in project ignite by apache.

the class ResourceHandler method handleRequest.

/**
 * @param response Http response.
 * @param type Type.
 * @param path Path to file.
 * @throws IOException If failed.
 */
private static void handleRequest(HttpServletResponse response, String type, String path) throws IOException {
    Path path0 = Paths.get(path);
    response.setContentType(type);
    response.setHeader("Content-Disposition", "attachment; filename=\"" + path0.getFileName() + "\"");
    try (HttpOutput out = (HttpOutput) response.getOutputStream()) {
        out.sendContent(FileChannel.open(path0, StandardOpenOption.READ));
    }
}
Also used : Path(java.nio.file.Path) HttpOutput(org.eclipse.jetty.server.HttpOutput)

Example 7 with HttpOutput

use of org.eclipse.jetty.server.HttpOutput in project ignite by apache.

the class ResourceHandler method handleRequest.

/**
 * @param response Http response.
 * @param type Type.
 * @param stream Stream.
 * @param attachmentName Attachment name.
 * @throws IOException If failed.
 */
private static void handleRequest(HttpServletResponse response, String type, InputStream stream, String attachmentName) throws IOException {
    response.setContentType(type);
    response.setHeader("Content-Disposition", "attachment; filename=\"" + attachmentName + "\"");
    try (HttpOutput out = (HttpOutput) response.getOutputStream()) {
        out.sendContent(stream);
    }
}
Also used : HttpOutput(org.eclipse.jetty.server.HttpOutput)

Aggregations

HttpOutput (org.eclipse.jetty.server.HttpOutput)7 ServletOutputStream (javax.servlet.ServletOutputStream)3 File (java.io.File)2 ByteBuffer (java.nio.ByteBuffer)2 AsyncContext (javax.servlet.AsyncContext)2 ServletContext (javax.servlet.ServletContext)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InterruptedIOException (java.io.InterruptedIOException)1 RandomAccessFile (java.io.RandomAccessFile)1 Charset (java.nio.charset.Charset)1 Path (java.nio.file.Path)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ServletException (javax.servlet.ServletException)1 WriteListener (javax.servlet.WriteListener)1 HttpServlet (javax.servlet.http.HttpServlet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpField (org.eclipse.jetty.http.HttpField)1 HttpFields (org.eclipse.jetty.http.HttpFields)1