Example usage for javax.servlet ServletOutputStream flush

List of usage examples for javax.servlet ServletOutputStream flush

Introduction

In this page you can find the example usage for javax.servlet ServletOutputStream flush.

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes this output stream and forces any buffered output bytes to be written out.

Usage

From source file:org.shimlib.web.servlet.view.filedownload.FileDownloadView.java

@Override
protected void writeToResponse(HttpServletResponse response, ByteArrayOutputStream baos) throws IOException {
    response.setContentLength(baos.size());

    // Flush byte array to servlet output stream.
    ServletOutputStream out = response.getOutputStream();
    baos.writeTo(out);//from w w w  .j  a v a2  s . c o m
    out.flush();
}

From source file:be.fedict.eid.dss.sp.servlet.DownloadServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    LOG.debug("doGet");
    HttpSession httpSession = request.getSession();
    byte[] document = (byte[]) httpSession.getAttribute("document");

    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=-1"); // http 1.1
    if (!request.getScheme().equals("https")) {
        // else the download fails in IE
        response.setHeader("Pragma", "no-cache"); // http 1.0
    } else {/* ww w.java2 s. co m*/
        response.setHeader("Pragma", "public");
    }
    response.setDateHeader("Expires", -1);
    response.setContentLength(document.length);

    String contentType = (String) httpSession.getAttribute("ContentType");
    LOG.debug("content-type: " + contentType);
    response.setContentType(contentType);
    response.setContentLength(document.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(document);
    out.flush();
}

From source file:com.fanya.p2p.front.user.jcaptcha.JCaptchaFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {

    response.setDateHeader("Expires", 0L);
    response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    response.addHeader("Cache-Control", "post-check=0, pre-check=0");
    response.setHeader("Pragma", "no-cache");
    response.setContentType("image/jpeg");

    String id = request.getRequestedSessionId();
    BufferedImage bi = JCaptcha.captchaService.getImageChallengeForID(id);

    ServletOutputStream out = response.getOutputStream();

    ImageIO.write(bi, "jpg", out);
    try {//from  w w  w .  j av  a2  s. c  om
        out.flush();
    } finally {
        out.close();
    }
}

From source file:OutSimplePdf.java

public void makePdf(HttpServletRequest request, HttpServletResponse response, String methodGetPost)
        throws ServletException, IOException {
    try {//from  w w w  . j  a va2 s  . c  o m

        String msg = "your message";

        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);
        document.open();
        document.add(new Paragraph(msg));
        document.add(Chunk.NEWLINE);
        document.add(new Paragraph("a paragraph"));
        document.close();

        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Pragma", "public");

        response.setContentType("application/pdf");

        response.setContentLength(baos.size());

        ServletOutputStream out = response.getOutputStream();
        baos.writeTo(out);
        out.flush();

    } catch (Exception e2) {
        System.out.println("Error in " + getClass().getName() + "\n" + e2);
    }
}

From source file:be.fedict.eid.dss.portal.DownloadServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.debug("doGet");
    HttpSession httpSession = request.getSession();
    byte[] document = (byte[]) httpSession.getAttribute(this.documentSessionAttribute);

    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=-1"); // http 1.1
    if (false == request.getScheme().equals("https")) {
        // else the download fails in IE
        response.setHeader("Pragma", "no-cache"); // http 1.0
    } else {/*w ww.ja  v  a2s .  c  o  m*/
        response.setHeader("Pragma", "public");
    }
    response.setDateHeader("Expires", -1);
    response.setContentLength(document.length);

    String contentType = (String) httpSession.getAttribute(this.contentTypeSessionAttribute);
    LOG.debug("content-type: " + contentType);
    response.setContentType(contentType);
    response.setContentLength(document.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(document);
    out.flush();
}

From source file:org.inbio.common.web.controller.XMLResponseMultiActionController.java

/**
 * //ww  w.  j  a  v a 2  s . co m
 * @param request
 * @param response
 * @param doc
 * @return
 * @throws Exception
 */
public ModelAndView writeXMLDocumentOnResponse(HttpServletRequest request, HttpServletResponse response,
        Document doc) throws Exception {

    // return response XML
    XMLOutputter xmlOutputter = new XMLOutputter();

    response.setCharacterEncoding(urlCharset);
    response.setContentType("text/xml;charset=" + urlCharset);
    ServletOutputStream out = response.getOutputStream(); // binary output

    xmlOutputter.output(doc, out);
    out.flush();
    out.close();

    return null;
}

From source file:be.fedict.eid.applet.service.PdfServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.debug("doGet");

    HttpSession httpSession = request.getSession();
    EIdData eIdData = (EIdData) httpSession.getAttribute("eid");

    byte[] document;
    try {//from w w w .  ja  v a 2s .  c o  m
        document = this.pdfGenerator.generatePdf(eIdData);
    } catch (DocumentException e) {
        throw new ServletException("PDF generator error: " + e.getMessage(), e);
    }

    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Pragma", "public");

    response.setContentType("application/pdf");
    response.setContentLength(document.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(document);
    out.flush();
}

From source file:be.fedict.eid.applet.service.VcardServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.debug("doGet");

    HttpSession httpSession = request.getSession();
    EIdData eIdData = (EIdData) httpSession.getAttribute("eid");

    byte[] document;
    try {//w w  w. jav  a 2s.  c o  m
        document = this.vcardGenerator.generateVcard(eIdData);
    } catch (IOException e) {
        throw new ServletException("vCard generator error: " + e.getMessage(), e);
    }

    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Pragma", "public");

    response.setContentType(VcardLight.MIME_TYPE);
    response.setContentLength(document.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(document);
    out.flush();
}

From source file:org.apache.blur.gui.LogServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String filename = request.getParameter("file");
    response.setContentType("text/plain");
    response.setHeader("Content-disposition", "attachment; filename=" + filename);
    if (filename.contains("/")) {
        throw new IOException("Filename [" + filename + "] with '/' is not allowed.");
    }//from  www  . j  av  a 2 s .  c om
    File file = new File(new File(_dir), filename);
    if (!file.exists()) {
        throw new IOException("Filename [" + filename + "] doe snot exist.");
    }
    FileInputStream input = new FileInputStream(file);
    ServletOutputStream outputStream = response.getOutputStream();
    IOUtils.copy(input, outputStream);
    input.close();
    outputStream.flush();
}

From source file:be.fedict.eid.applet.service.KmlServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.debug("doGet");

    HttpSession httpSession = request.getSession();
    EIdData eIdData = (EIdData) httpSession.getAttribute("eid");

    byte[] document;
    try {//from  w  w w  .  j av  a  2s.  co  m
        document = this.kmlGenerator.generateKml(eIdData);
    } catch (IOException e) {
        throw new ServletException("KML generator error: " + e.getMessage(), e);
    }

    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=-1"); // http 1.1
    if (false == request.getScheme().equals("https")) {
        // else the download fails in IE
        response.setHeader("Pragma", "no-cache"); // http 1.0
    } else {
        response.setHeader("Pragma", "public");
    }
    response.setDateHeader("Expires", -1);
    response.setHeader("Content-disposition", "attachment");
    response.setContentLength(document.length);

    response.setContentType(KmlLight.MIME_TYPE);
    response.setContentLength(document.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(document);
    out.flush();
}