Example usage for javax.servlet.http HttpServletResponse flushBuffer

List of usage examples for javax.servlet.http HttpServletResponse flushBuffer

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse flushBuffer.

Prototype

public void flushBuffer() throws IOException;

Source Link

Document

Forces any content in the buffer to be written to the client.

Usage

From source file:org.fenixedu.academic.ui.struts.action.candidate.degree.DegreeCandidacyManagementDispatchAction.java

public ActionForward showSummaryFile(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse response) {
    CandidacySummaryFile file = getCandidacy(request).getSummaryFile();

    response.reset();/*from   w w w .  j av  a2  s  .  c o  m*/
    try {
        response.getOutputStream().write(file.getContent());
        response.setContentLength(file.getContent().length);
        response.setContentType("application/pdf");
        response.flushBuffer();
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }

    return null;
}

From source file:fr.lille1_univ.car_tprest.jetty.web.UpweeController.java

/**
* A call that is used to download the file in the pat corresponding to the filename
*///w w w. j  a  v a 2s  .  c o  m
@CrossOrigin
@RequestMapping(method = {
        RequestMethod.GET }, value = "/api/files/download/**", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public void download(HttpServletRequest request, @RequestParam(value = "file", required = true) String filename,
        HttpServletResponse response) {
    try {
        response.addHeader("Content-disposition", "attachment;filename=" + filename);
        response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
        String decodedfileName = "";
        decodedfileName = java.net.URLDecoder.decode(filename, "UTF-8");
        InputStream stream = this.fileSystemService
                .getFile(getFullFileRequestPath("/api/files/download/**", request, decodedfileName));
        IOUtils.copy(stream, response.getOutputStream());
        response.flushBuffer();
        stream.close();

    } catch (Exception e) {
        l.e("Unable to get file");
        e.printStackTrace();
    }
}

From source file:com.its.web.controllers.ProductsManagerController.java

@RequestMapping(value = "generateProductXmlFile.do", method = RequestMethod.GET)
public void generateLicenseFile(@RequestParam("productName") String productName,
        @RequestParam("selectedFullType") String selectedFullType,
        @RequestParam("selectedTrialType") String selectedTrialType, HttpServletResponse response) {

    log.debug("productName------------->" + productName);
    log.debug("selectedFullType------------->" + selectedFullType);
    log.debug("selectedTrialType------------->" + selectedTrialType);

    InputStream is = productsService.generateXml(productName, selectedFullType, selectedTrialType);

    String fileName = "product.xml";

    response.setContentType("application/force-download");
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);

    try {//from   ww w  .j av  a  2  s  .c  om
        // copy it to response's OutputStream
        IOUtils.copy(is, response.getOutputStream());
        response.flushBuffer();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.ewcms.web.filter.render.ResourceRender.java

/**
 * ?//from ww w  .  j ava2 s. c om
 * 
 * @param response
 * @param uri   ?
 * @return
 * @throws IOException
 */
@Override
protected boolean output(HttpServletResponse response, String uri) throws IOException {
    //TODO windowUnix
    Resource resource = resourceService.getResourceByUri(uri);
    if (resource == null) {
        logger.debug("Resource is not exist,uri is {}", uri);
        return false;
    }
    String realPath = resource.getPath();
    if (StringUtils.endsWith(resource.getThumbUri(), uri)) {
        realPath = resource.getThumbPath();
    }

    try {
        IOUtils.copy(new FileInputStream(realPath), response.getOutputStream());
    } catch (Exception e) {
        logger.warn("Resource is not exit,real path is{}", realPath);
    }
    response.flushBuffer();

    return true;
}

From source file:com.eviware.soapui.impl.wsdl.mock.WsdlMockRunner.java

private void dispatchCommand(String cmd, HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    if ("stop".equals(cmd)) {
        response.setStatus(HttpServletResponse.SC_OK);
        response.flushBuffer();

        SoapUI.getThreadPool().execute(new Runnable() {

            public void run() {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }/*from w ww.j av a 2 s  .  c  o m*/
                stop();
            }
        });
    } else if ("restart".equals(cmd)) {
        response.setStatus(HttpServletResponse.SC_OK);
        response.flushBuffer();

        SoapUI.getThreadPool().execute(new Runnable() {

            public void run() {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                stop();
                //
                // try
                // {
                // Thread.sleep( 500 );
                // }
                // catch( InterruptedException e )
                // {
                // e.printStackTrace();
                // }

                try {
                    mockService.start();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        });
    }
}

From source file:org.kuali.coeus.propdev.impl.budget.subaward.ProposalBudgetSubAwardController.java

@Transactional
@RequestMapping(params = "methodToCall=viewSubAwardPdf")
public void viewPdf(@RequestParam("subAwardNumber") Integer subAwardNumber,
        @ModelAttribute("KualiForm") ProposalBudgetForm form, HttpServletResponse response) {
    BudgetSubAwards subAward = getSubAwardByNumber(subAwardNumber, form);
    try {/*from   www. ja  va2  s  .com*/
        ByteArrayInputStream inputStream = new ByteArrayInputStream(subAward.getSubAwardXfdFileData());
        KRADUtils.addAttachmentToResponse(response, inputStream, "application/pdf",
                subAward.getSubAwardXfdFileName(), subAward.getSubAwardXfdFileData().length);
        response.flushBuffer();
    } catch (Exception e) {
        LOG.error("Error while downloading attachment");
        throw new RuntimeException("IOException occurred while downloading attachment", e);
    }
}

From source file:com.newatlanta.appengine.servlet.GaeVfsServlet.java

/**
 * If a file is specified, return the file; if a folder is specified, then
 * either return a listing of the folder, or <code>FORBIDDEN</code>, based on
 * configuration.//from www  .j ava 2s . co  m
 */
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

    Path path = Paths.get(req.getRequestURI());
    if (path.notExists()) {
        res.sendError(SC_NOT_FOUND);
        return;
    }

    BasicFileAttributes attrs = readBasicFileAttributes(path);
    if (attrs.isDirectory()) {
        if (dirListingAllowed) {
            res.getWriter().write(getListHTML(path));
            res.flushBuffer();
        } else {
            res.sendError(SC_FORBIDDEN, "Directory listing not allowed");
        }
        return;
    }

    // the request is for a file, return it

    long lastModified = attrs.lastModifiedTime().to(SECONDS) * 1000;
    long ifModifiedSince = req.getDateHeader("If-Modified-Since");
    if (lastModified == ifModifiedSince) {
        res.sendError(SC_NOT_MODIFIED);
        return;
    }
    res.setDateHeader("Last-Modified", lastModified);

    // the servlet MIME type is configurable via web.xml
    String contentType = getServletContext().getMimeType(path.getName().toString());
    if (contentType != null) {
        res.setContentType(contentType);
    }

    // IOUtils.copy() buffers the InputStream internally
    InputStream in = path.newInputStream();
    res.setContentLength(copy(in, res.getOutputStream()));
    in.close();
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.candidate.degree.DegreeCandidacyManagementDispatchAction.java

public ActionForward showSummaryFile(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse response) {
    CandidacySummaryFile file = getCandidacy(request).getSummaryFile();

    response.reset();/* w w  w  . jav a  2s  .c om*/
    try {
        response.getOutputStream().write(file.getContents());
        response.setContentLength(file.getContents().length);
        response.setContentType("application/pdf");
        response.flushBuffer();
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }

    return null;
}

From source file:com.almende.eve.transport.http.EveServlet.java

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {

    // If this is a handshake request, handle it.
    if (handleHandShake(req, resp)) {
        return;//from   w w  w . j  av  a  2 s  .  co m
    }

    final String url = req.getRequestURI();
    final String id = getId(url);
    if (id == null || id.equals("") || id.equals(myUrl.toASCIIString())) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Couldn't parse URL, missing 'id'");
        resp.flushBuffer();
        return;
    }
    final HttpTransport transport = HttpService.get(myUrl, id);

    resp.setContentType("text/plain");
    resp.getWriter().println("You've found the servlet for agent:" + id + " ("
            + (transport == null ? "not " : "") + " configured)");
    resp.getWriter().close();
    resp.flushBuffer();
}