Package javax.servlet

Examples of javax.servlet.ServletOutputStream


        response.setContentType("message/http");
        response.setCharacterEncoding(charset);
        response.setContentLength(responseLength);

        ServletOutputStream out = response.getOutputStream();
        out.write(rawResponse);
    }
View Full Code Here


            InputStream fileInput = resourceURL.openStream();
            try
            {
                byte[] buffer = new byte[1024];
                int read = 0;
                ServletOutputStream output = response.getOutputStream();
                try
                {
                    while((read = fileInput.read(buffer)) != -1)
                    {
                        output.write(buffer, 0, read);
                    }
                }
                finally
                {
                    output.close();
                }
            }
            finally
            {
                fileInput.close();
View Full Code Here

                // set various response headers, unless the request is included
                setHeaders(resource, response);
            }

            ServletOutputStream out = response.getOutputStream();

            if (ranges == FULL) {

                // return full resource
                setContentLength(response,
                    resource.getResourceMetadata().getContentLength());
                byte[] buf = new byte[IO_BUFFER_SIZE];
                int rd;
                while ((rd = stream.read(buf)) >= 0) {
                    out.write(buf, 0, rd);
                }

            } else {

                // return ranges of the resource
View Full Code Here

    // ---------- SlingHttpServletResponse interface

    @Override
    public ServletOutputStream getOutputStream() throws IOException {
        if (this.out == null) {
            ServletOutputStream sos = super.getOutputStream();
            this.out = new LoggerResponseOutputStream(sos);
        }
        return this.out;
    }
View Full Code Here

    }

    public void outputAsByte(byte[] msg) throws IOException {
        //httpServletResponse.setContentType("application/json; charset=UTF-8");
        httpServletResponse.setStatus(status);
        ServletOutputStream outputStream = httpServletResponse.getOutputStream();
        outputStream.write(msg);
        outputStream.flush();
        outputStream.close();
    }
View Full Code Here

      IOException {
    String propertyName = request.getParameter("property");
    if ("".equals(propertyName) || propertyName == null)
      throw new ResourceNotFoundException("No property specified.");

    ServletOutputStream out = response.getOutputStream();
    Resource resource = request.getResource();
    Node currentNode = resource.adaptTo(Node.class);
    javax.jcr.Property property = null;
    try {
      property = currentNode.getProperty(propertyName);
    } catch (PathNotFoundException e) {
      response.sendError(HttpServletResponse.SC_NOT_FOUND, "Not found.");
      throw new ResourceNotFoundException("Not found.");
    } catch (RepositoryException e) {
      response.sendError(HttpServletResponse.SC_NOT_FOUND, "Not found.");
      throw new ResourceNotFoundException("Not found.");
    }
    InputStream stream = null;
    try {
      if (property == null || property.getType() != PropertyType.BINARY) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "Not found.");
        throw new ResourceNotFoundException("Not found.");
      }
      long length = property.getLength();
      if (length > 0) {
        if (length < Integer.MAX_VALUE) {
          response.setContentLength((int) length);
        } else {
          response.setHeader("Content-Length", String.valueOf(length));
        }
      }
      stream = property.getStream();
      byte[] buf = new byte[2048];
      int rd;
      while ((rd = stream.read(buf)) >= 0) {
        out.write(buf, 0, rd);
      }
    } catch (ValueFormatException e) {
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Error downloading the property content.");
      log.debug("error reading the property " + property + " of path "
View Full Code Here

public class HelloServlet extends HttpServlet {

  @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        ServletOutputStream out = resp.getOutputStream();
       
        out.write("Hello Heroku".getBytes());
        out.flush();
        out.close();
    }
View Full Code Here

    response.setCharacterEncoding("utf-8");
    response.setHeader("Content-disposition", "attachment; filename="
        + filename + "." + mime.name().toLowerCase());
    response.setHeader("Content-type", mime.getType());
    // set encoding before writing to out, check this
    ServletOutputStream out = response.getOutputStream();
    // Send content to Browser
    out.write(stream.toByteArray());
    out.flush();
  }
View Full Code Here

  public static void writeToResponse(HttpServletResponse response, ByteArrayOutputStream baos, String title,
      String contentType) throws IOException {
    response.setContentType(contentType);
    response.setHeader("Content-Disposition", "attachment; filename=\"" + title + "\"");

    ServletOutputStream out = response.getOutputStream();
    baos.writeTo(out);
    out.flush();
  }
View Full Code Here

    response.setCharacterEncoding("utf-8");
    response.setHeader("Content-disposition", "attachment; filename="
        + filename + "." + mime.name().toLowerCase());
    response.setHeader("Content-type", mime.getType());
    // set encoding before writing to out, check this
    ServletOutputStream out = response.getOutputStream();
    // Send content to Browser
    out.write(stream.toByteArray());
    out.flush();
  }
View Full Code Here

TOP

Related Classes of javax.servlet.ServletOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.