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.aistor.common.servlet.ValidateCodeServlet.java

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

From source file:com.controlj.green.istat.web.TreeServlet.java

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

    resp.setHeader("Expires", "Wed, 01 Jan 2003 12:00:00 GMT");
    resp.setHeader("Cache-Control", "no-cache");
    ServletOutputStream out = resp.getOutputStream();
    try {/* w ww .  j  a  va 2 s.  com*/
        writeLevel(out, req.getParameter(LOCATION_PARAM), req);
    } catch (Exception e) {
        Logging.LOGGER.println("Error getting tree info");
        e.printStackTrace(Logging.LOGGER);
        throw new ServletException(e);
    }
    out.flush();
    /*
    out.println("[");
    out.println("{ display:'Main Conf Room', id:'mainconf'},");
    out.println("{ display:'Board Room', id:'boardroom'},");
    out.println("{ display:'Room 235', id:'room235'}");
    out.println("]");
    */
}

From source file:com.pavikumbhar.javaheart.controller.FileUploadController.java

@RequestMapping(value = "/download", method = RequestMethod.GET)
public void download(@RequestParam("name") String name, final HttpServletRequest request,
        final HttpServletResponse response) {
    System.out.println("name : {}" + name);

    File file = new File("/app/" + name);
    System.out.println("Write response...");
    try (InputStream fileInputStream = new FileInputStream(file);
            OutputStream output = response.getOutputStream();) {

        response.reset();// www .j  a va  2  s  . co  m

        response.setContentType("application/octet-stream");
        response.setContentLength((int) (file.length()));

        response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"");

        IOUtils.copyLarge(fileInputStream, output);
        output.flush();
    } catch (IOException e) {
        System.out.println(e.getMessage());
    }

}

From source file:com.shadows.liquiblq.webapi.controllers.SongsController.java

@RequestMapping(value = "/play/{id}", method = RequestMethod.GET)
public void doPlayById(@PathVariable("id") UUID id, @RequestParam("sessionKey") UUID Session,
        @RequestParam("UserId") Integer UserId, HttpServletResponse response) {
    try {/*from   ww  w . j  a  va  2  s  . co m*/
        Validator.ValidateRequest(Session, UserId);
        Song song = Context.getSongsSet().GetById(id);
        InputStream File = SongsController.class.getResourceAsStream("/songs/" + song.Filename);
        IOUtils.copy(File, response.getOutputStream());
        response.flushBuffer();
    } catch (Exception Exp) {
        throw new RuntimeException("IOError writing file to output stream");
    }
}

From source file:apm.common.servlet.ValidateCodeServlet.java

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

From source file:com.boazlev.waze.web.WazeServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.info("doPost");
    response.setContentType("text/xml; charset=UTF-8");
    PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF8"), true);
    StringBuilder sb = new StringBuilder();
    Collection<EnhancedBase> enhancedBases = app.get();
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("\n");
    sb.append("<?xml-stylesheet type=\"text/xsl\" href=\"out.xslt\"?>").append("\n");
    sb.append("<catalog>").append("\n");

    if (enhancedBases != null) {
        for (EnhancedBase enhancedBase : enhancedBases) {
            String city = enhancedBase.getCity();
            String neighborhood = enhancedBase.getNeighborhood();
            LOG.info("Parsing - " + city + " / " + neighborhood);
            MyBase myBase = enhancedBase.getMyBase();

            if (myBase != null) {
                PoiMarkerElement[] poimarkers = myBase.getPoimarkers();
                for (PoiMarkerElement poiMarkerElement : poimarkers) {
                    PoiElement[] pois = poiMarkerElement.getPois();
                    if (pois != null) {
                        for (PoiElement poiElement : pois) {
                            String id = poiElement.getId();
                            if ("project".equals(poiElement.getType())) {
                                sb.append("<cd>").append("\n");
                                sb.append(toXmlData("xid", id)).append("\n");
                                Info info = poiElement.getInfo();
                                if (info != null) {
                                    sb.append(toXmlData("city", city)).append("\n");
                                    sb.append(toXmlData("neighborhood", neighborhood)).append("\n");
                                    sb.append(toXmlData("marketing", info.getMarketingstage())).append("\n");
                                    sb.append(toXmlData("buildingStage", info.getBuildingstage())).append("\n");
                                    sb.append(toXmlData("location", info.getLocation())).append("\n");
                                    sb.append(toXmlData("lat", poiElement.getLat().toString())).append("\n");
                                    sb.append(toXmlData("lng", poiElement.getLng().toString())).append("\n");
                                    sb.append(toXmlData("description", info.getDescription())).append("\n");
                                }//from www .j  a va2  s.  c  om
                                sb.append("</cd>").append("\n");
                            }
                        }
                    }
                }
            }
        }
    }
    sb.append("</catalog>");

    out.println(sb.toString());
    out.flush();
    LOG.fine(sb.toString());
    LOG.info("Done");
}

From source file:com.krawler.spring.views.JsonView_ex.java

/**
 * Renders the view by marshalling the model data (set in the controller)
 * into XML and writing the XML to the response output stream.
 *//*from w ww  .  java 2  s  .c  o  m*/
protected void renderMergedOutputModel(Map map, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    //logger.info("Start rendering of " + this.getBeanName());

    // this is the business model data (typically a POJO) that was set and returned by the controller
    String model = (String) map.get("model");
    // write the XML data to the response
    response.getOutputStream().write(model.getBytes());
    response.setContentType("text/html; charset=ISO-8859-1");
}

From source file:com.krawler.spring.crm.views.JsonView_ex.java

/**
 * Renders the view by marshalling the model data (set in the controller)
 * into XML and writing the XML to the response output stream.
 *///from  w w w  .j  a v a 2 s  . c o m
protected void renderMergedOutputModel(Map map, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    //logger.info("Start rendering of " + this.getBeanName());

    // this is the business model data (typically a POJO) that was set and returned by the controller
    String model = (String) map.get("model");
    // write the XML data to the response
    response.getOutputStream().write(model.getBytes());
    response.setContentType("text/html; charset=UTF-8");
}

From source file:de.itsvs.cwtrpc.security.RpcRedirectStrategy.java

protected void writeResponseText(HttpServletRequest request, HttpServletResponse response,
        String characterEncoding, String responseText) throws IOException {
    final byte[] responseBytes;

    responseBytes = responseText.getBytes(characterEncoding);
    response.setContentLength(responseBytes.length);
    response.getOutputStream().write(responseBytes);
}

From source file:de.uni_koeln.spinfo.maalr.webapp.controller.EditorController.java

@RequestMapping("/editor/download/{fileName}.html")
public void export(@PathVariable("fileName") String fileName, HttpServletResponse response) throws IOException {
    File dir = new File("exports");
    File file = new File(dir, fileName);
    ServletOutputStream out = response.getOutputStream();
    if (!file.exists()) {
        OutputStreamWriter writer = new OutputStreamWriter(out);
        writer.write("This link has expired. Please re-export the data and try again.");
        writer.flush();/*from  w  w w .j a va  2s.  c  o m*/
        return;
    }
    response.setContentType("application/zip");
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
    IOUtils.copy(in, out);
    in.close();
    out.close();
    file.delete();
}