Example usage for javax.servlet.http HttpServletResponse getOutputStream

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

Introduction

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

Prototype

public ServletOutputStream getOutputStream() throws IOException;

Source Link

Document

Returns a ServletOutputStream suitable for writing binary data in the response.

Usage

From source file:org.energyos.espi.datacustodian.web.api.TimeConfigurationRESTController.java

@RequestMapping(value = Routes.ROOT_TIME_CONFIGURATION_COLLECTION, method = RequestMethod.GET, produces = "application/atom+xml")
@ResponseBody//  ww w  . j av  a2 s. c om
public void index(HttpServletResponse response, @RequestParam Map<String, String> params)
        throws IOException, FeedException {

    response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE);
    exportService.exportTimeConfigurations(response.getOutputStream(), new ExportFilter(params));
}

From source file:werecloud.api.view.StringView.java

@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    if (model.containsKey("string")) {
        String data = model.get("string").toString();
        byte[] _data = data.getBytes();
        response.setContentType(getContentType());
        response.setContentLength(_data.length);
        ServletOutputStream out = response.getOutputStream();
        out.write(_data);/*from ww  w. j a v  a2 s . c  o  m*/
        out.flush();
        out.close();
        return;
    }
    throw new Exception("Could not find model.");
}

From source file:com.ccc.webapp.http.mappers.MappingJacksonJsonpView.java

/**
* Prepares the view given the specified model, merging it with static
* attributes and a RequestContext attribute, if necessary.
* Delegates to renderMergedOutputModel for the actual rendering.
* @see #renderMergedOutputModel//w  w  w.  j  a  v  a2s.  c  o m
*/
@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    if ("GET".equals(request.getMethod().toUpperCase())) {
        @SuppressWarnings("unchecked")
        Map<String, String[]> params = request.getParameterMap();

        if (params.containsKey("callback")) {
            response.getOutputStream().write(new String(params.get("callback")[0] + "(").getBytes());
            super.render(model, request, response);
            response.getOutputStream().write(new String(");").getBytes());
            response.setContentType("application/javascript");
        }

        else {
            super.render(model, request, response);
        }
    }

    else {
        super.render(model, request, response);
    }
}

From source file:com.bennavetta.appsite.serve.ResourceServlet.java

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    log.info("Handling request {}", req);
    URI actual = base.relativize(URI.create(req.getRequestURI()));
    try {/*from w  ww . ja v  a2s . co m*/
        processor.handle(new RedirectedRequest(actual, new HttpServletReq(req)), new HttpServletResp(resp),
                req.getInputStream(), resp.getOutputStream());
    } catch (Exception e) {
        log.error("Error handling request", e);
        resp.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value());
    }
}

From source file:com.civilizer.web.handler.ResourceHttpRequestHandler.java

/**
 * Write the actual content out to the given servlet response,
 * streaming the resource's content./*from   ww w .  j  a v  a2  s. co m*/
 * @param response current servlet response
 * @param resource the identified resource (never {@code null})
 * @throws IOException in case of errors while writing the content
 */
protected void writeContent(HttpServletResponse response, Resource resource) throws IOException {
    StreamUtils.copy(resource.getInputStream(), response.getOutputStream());
}

From source file:edu.wustl.bulkoperator.action.BulkHandler.java

/**
 * This method call to write Job message.
 * @param jobMessage jobMessage/*  w w  w .j  a  v  a  2s.  c  o  m*/
 * @param response HttpServletResponse
 * @throws IOException IOException
 * @throws SQLException SQLException
 */
private void writeJobMessage(JobMessage jobMessage, HttpServletResponse response)
        throws IOException, SQLException {
    OutputStream ost = response.getOutputStream();
    ObjectOutputStream objOutputStream = new ObjectOutputStream(ost);

    JobDetails jobDetails = jobMessage.getJobData();
    if (jobDetails != null && jobDetails.getLogFile() != null) {
        Blob blob = jobDetails.getLogFile();
        InputStream inputStream = blob.getBinaryStream();
        int count = 0;

        final byte[] buf = new byte[Long.valueOf(blob.length()).intValue()];
        while (count > -1) {
            count = inputStream.read(buf);
        }
        (jobMessage.getJobData()).setLogFilesBytes(buf);
    }
    objOutputStream.writeObject(jobMessage);

}

From source file:io.lavagna.web.api.ExportImportController.java

@RequestMapping(value = "/api/export", method = RequestMethod.POST)
public void export(HttpServletResponse resp) throws IOException {
    resp.setHeader("Content-Disposition", "attachment; filename=\"lavagna-export-"
            + new SimpleDateFormat("YYYY-MM-dd").format(new Date()) + ".zip\"");
    resp.setContentType("application/octet-stream");
    exportImportService.exportData(resp.getOutputStream());
}

From source file:io.druid.server.AsyncManagementForwardingServlet.java

private void handleBadRequest(HttpServletResponse response, String errorMessage) throws IOException {
    if (!response.isCommitted()) {
        response.resetBuffer();/*www .j ava2 s.  c  o m*/
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        jsonMapper.writeValue(response.getOutputStream(), ImmutableMap.of("error", errorMessage));
    }
    response.flushBuffer();
}

From source file:com.eryansky.common.web.servlet.ValidateCodeServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String validateCode = request.getParameter(SysConstants.SESSION_VALIDATE_CODE); // AJAX??true
    if (StringUtils.isNotBlank(validateCode)) {
        response.getOutputStream().print(validate(request, validateCode) ? "true" : "false");
    } else {/*from   w  w  w  . j a  v  a  2s  .c  om*/
        this.doPost(request, response);
    }
}

From source file:gov.nih.nci.calims2.ui.common.document.DocumentController.java

/**
 * /*  ww  w  .  ja  va2s.c om*/
 * @param response The servlet response.
 * @param id The id of the filledreport to view.
 */
@RequestMapping("/download.do")
public void download(HttpServletResponse response, @RequestParam("id") Long id) {
    try {
        Document document = getMainService().findById(Document.class, id);
        ServletOutputStream servletOutputStream = response.getOutputStream();
        File downloadedFile = storageService.get(document, new File(tempfiledir));
        response.setContentType("application/octet-stream");
        response.setHeader("Content-Disposition", "attachment;filename=" + document.getName());
        FileInputStream fileInputStream = new FileInputStream(downloadedFile);
        IOUtils.copyLarge(fileInputStream, servletOutputStream);
        IOUtils.closeQuietly(fileInputStream);
        servletOutputStream.flush();
        servletOutputStream.close();
        downloadedFile.delete();
    } catch (IOException e1) {
        throw new RuntimeException("IOException in download", e1);
    } catch (StorageServiceException e) {
        throw new RuntimeException("StorageServiceException in download", e);
    }
}