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:com.oak_yoga_studio.controller.ProductController.java

/**
 * Image display/*  w  w  w. j a va 2s.c o  m*/
 */
@RequestMapping(value = "/productImage/{id}", method = RequestMethod.GET)
public void getProductImage(Model model, @PathVariable int id, HttpServletResponse response) {
    try {
        Product p = productService.getProduct(id);
        if (p != null) {
            OutputStream out = response.getOutputStream();
            out.write(p.getImage());
            response.flushBuffer();
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:gumga.framework.presentation.api.AbstractReportAPI.java

public void generateAndExportReport(String reportName, List data, Map<String, Object> params,
        HttpServletRequest request, HttpServletResponse response, ReportType type)
        throws JRException, IOException {
    InputStream is = getResourceAsInputStream(request, reportName);
    setContentType(response, reportName, type);
    reportService.exportReport(is, response.getOutputStream(), data, params, type);
}

From source file:com.sample.JavaHTTPResource.java

public void execute(HttpHost host, HttpUriRequest req, HttpServletResponse resultResponse)
        throws IOException, IllegalStateException, SAXException {
    HttpResponse RSSResponse = client.execute(host, req);
    ServletOutputStream os = resultResponse.getOutputStream();
    if (RSSResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        resultResponse.addHeader("Content-Type", "application/json");
        //String json = IOUtils.toString(RSSResponse.getEntity().getContent());
        InputStream in = RSSResponse.getEntity().getContent();
        StringBuilder sb = new StringBuilder();
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String read;/*from ww  w.ja  va2s. c  om*/

        while ((read = br.readLine()) != null) {
            //System.out.println(read);
            sb.append(read);
        }

        br.close();
        os.write(sb.toString().getBytes(Charset.forName("UTF-8")));

    } else {
        resultResponse.setStatus(RSSResponse.getStatusLine().getStatusCode());
        RSSResponse.getEntity().getContent().close();
        os.write(RSSResponse.getStatusLine().getReasonPhrase().getBytes());
    }
    os.flush();
    os.close();
}

From source file:GZIPFilter.java

public GZIPResponseStream(HttpServletResponse response) throws IOException {
    super();/*from   www  .  j a  va 2 s  .  c o  m*/
    closed = false;
    this.response = response;
    this.output = response.getOutputStream();
    baos = new ByteArrayOutputStream();
    gzipstream = new GZIPOutputStream(baos);
}

From source file:controllers.ColorController.java

@RequestMapping("/getXls")
public void getXls(Map<String, Object> model, HttpServletResponse response) throws Exception {
    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment; filename=Color.xls");
    colorService.getXls().write(response.getOutputStream());
}

From source file:com.oak_yoga_studio.controller.FacultyController.java

@RequestMapping(value = "/facultyProfileImage/{id}", method = RequestMethod.GET)
public void getProfileImage(Model model, @PathVariable int id, HttpServletResponse response) {
    try {/*w w w.  j  av  a2  s  . c  o m*/
        Faculty f = facultyService.getFacultyById(id);
        if (f != null) {
            OutputStream out = response.getOutputStream();
            out.write(f.getProfilePicture());
            response.flushBuffer();
        }
    } catch (IOException ex) {
        // Logger.getLogger(CustomerController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:controllers.CarPropertyController.java

@RequestMapping("/getXls")
public void getXls(Map<String, Object> model, HttpServletResponse response) throws Exception {
    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment; filename=PROPERTY.xls");
    carPropertyService.getXls().write(response.getOutputStream());
}

From source file:io.apiman.test.integration.deployment.servlet.EchoServlet.java

/**
 * Responds with a comprehensive echo.  This means bundling up all the
 * information about the inbound request into a java bean and responding
 * with that data as a JSON response./*  w w w  .  java2s  . c  o m*/
 * @param req
 * @param resp
 * @param withBody
 */
protected void doEchoResponse(HttpServletRequest req, HttpServletResponse resp, boolean withBody) {
    EchoResponse response = EchoResponse.from(req, withBody);

    resp.setContentType("application/json"); //$NON-NLS-1$
    try {
        mapper.writeValue(resp.getOutputStream(), response);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.fusesource.restygwt.server.complex.DTOInterfaceServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    DTOImplementation impl = new DTOImplementation();
    impl.setName("interface");

    resp.setContentType("application/json");
    ObjectMapper om = new ObjectMapper();
    try {//from w  w  w  . j ava  2  s  .  c o m
        om.writeValue(resp.getOutputStream(), impl);
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:com.hzc.framework.ssh.controller.WebUtil.java

/**
 * ?response?//from   www. ja  v a2  s.c o  m
 *
 * @param attachFile
 * @throws IOException
 */
public static void write(byte[] attachFile) throws RuntimeException {
    try {
        HttpServletResponse resp = ActionContext.getResp();
        ServletOutputStream outputStream = resp.getOutputStream();
        outputStream.write(attachFile);
        outputStream.flush();
        //            outputStream.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}