Examples of ServletOutputStream


Examples of javax.servlet.ServletOutputStream

        if (fbos.size() > 0)
        {
          response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
          response.setHeader("Content-Disposition", "inline; filename=\"file.docx\"");
          response.setContentLength(fbos.size());
          ServletOutputStream ouputStream = response.getOutputStream();
 
          try
          {
            fbos.writeData(ouputStream);
            fbos.dispose();
            ouputStream.flush();
          }
          finally
          {
            if (ouputStream != null)
            {
              try
              {
                ouputStream.close();
              }
              catch (IOException ex)
              {
              }
            }
          }
        }
      }
      catch (JRException e)
      {
        throw new ServletException(e);
      }
      finally
      {
        fbos.close();
        fbos.dispose();
      }
    }
    else
    {
      response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
      response.setHeader("Content-Disposition", "inline; filename=\"file.docx\"");
     
      JRDocxExporter exporter = new JRDocxExporter();
      exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList);
     
      OutputStream ouputStream = response.getOutputStream();
      exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);

      try
      {
        exporter.exportReport();
      }
      catch (JRException e)
      {
        throw new ServletException(e);
      }
      finally
      {
        if (ouputStream != null)
        {
          try
          {
            ouputStream.close();
          }
          catch (IOException ex)
          {
          }
        }
View Full Code Here

Examples of javax.servlet.ServletOutputStream

        if (fbos.size() > 0)
        {
          response.setContentType("application/rtf");
          response.setHeader("Content-Disposition", "inline; filename=\"file.rtf\"");
          response.setContentLength(fbos.size());
          ServletOutputStream ouputStream = response.getOutputStream();
 
          try
          {
            fbos.writeData(ouputStream);
            fbos.dispose();
            ouputStream.flush();
          }
          finally
          {
            if (ouputStream != null)
            {
              try
              {
                ouputStream.close();
              }
              catch (IOException ex)
              {
              }
            }
          }
        }
      }
      catch (JRException e)
      {
        throw new ServletException(e);
      }
      finally
      {
        fbos.close();
        fbos.dispose();
      }
//      else
//      {
//        response.setContentType("text/html");
//        PrintWriter out = response.getWriter();
//        out.println("<html>");
//        out.println("<body bgcolor=\"white\">");
//        out.println("<span class=\"bold\">Empty response.</span>");
//        out.println("</body>");
//        out.println("</html>");
//      }
    }
    else
    {
      response.setContentType("application/rtf");
      response.setHeader("Content-Disposition", "inline; filename=\"file.rtf\"");

      JRRtfExporter exporter = new JRRtfExporter();
      exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList);
     
      OutputStream ouputStream = response.getOutputStream();
      exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);

      try
      {
        exporter.exportReport();
      }
      catch (JRException e)
      {
        throw new ServletException(e);
      }
      finally
      {
        if (ouputStream != null)
        {
          try
          {
            ouputStream.close();
          }
          catch (IOException ex)
          {
          }
        }
View Full Code Here

Examples of javax.servlet.ServletOutputStream

    }

    if (jasperPrint != null)
    {
      response.setContentType("application/octet-stream");
      ServletOutputStream ouputStream = response.getOutputStream();
     
      ObjectOutputStream oos = new ObjectOutputStream(ouputStream);
      oos.writeObject(jasperPrint);
      oos.flush();
      oos.close();

      ouputStream.flush();
      ouputStream.close();
    }
    else
    {
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
View Full Code Here

Examples of javax.servlet.ServletOutputStream

                    (new Timestamp(resourceInfo.date)).toString() + "'");
            response.setHeader("Last-Modified", resourceInfo.httpDate);

        }

        ServletOutputStream ostream = null;
        PrintWriter writer = null;

        if (content) {

            // Trying to retrieve the servlet output stream
View Full Code Here

Examples of javax.servlet.ServletOutputStream

    }
 
    private String directResponse(HttpServletResponse httpResp, String response)
            throws IOException
    {
        ServletOutputStream os = httpResp.getOutputStream();
        os.write(response.getBytes());
        os.close();

        return null;
    }
View Full Code Here

Examples of javax.servlet.ServletOutputStream

                // Setup the headers information
                response.setContentType("application/x-download");
                response.setHeader("Content-Disposition", "attachment; filename=" + filename);

                // Start writing the output.
                ServletOutputStream outputStream = response.getOutputStream();
                fileChannel.downloadFile( filename, outputStream );
            }
        }
    }
View Full Code Here

Examples of javax.servlet.ServletOutputStream

      FileItem item = null;
      FileItemFactory factory = new DiskFileItemFactory();
      Iterator iter = null;
      List items = null;
      ServletFileUpload upload = new ServletFileUpload( factory );
      ServletOutputStream out = null;
      try{
        items = upload.parseRequest( req );
        iter = items.iterator();
        res.setContentType( " text/xml");
        out = res.getOutputStream();
        out.println( " <response> " );
        while( iter.hasNext() ){
          item = ( FileItem )iter.next();
          if( item.isFormField() ){
            out.println( "<field name=\"" + item.getFieldName() + "\"value=\"" + item.getString() + "\" />"  );
          }
          else{
            String wsdlLocationParam = req.getParameter("wsdlLocation");
            //System.out.println("$$$$$$$$$$$$$$$$$$$$$$___________req.getParameter(wsdlLocation) : "+wsdlLocationParam);
            wsdlLocationParam = wsdlLocationParam.replace('\\', File.separatorChar);
            //System.out.println("$$$$$$$$$$$$$$$$$___________req.getParameter(wsdlLocation) : "+wsdlLocationParam);
            String path = getServletContext().getRealPath("/")+wsdlLocationParam;
            path = path.replace('\\', File.separatorChar);
            //System.out.println("$$$$$$$$$$$$$$$$$path : "+path);
            disk = new File( path, item.getName() );
            item.write( disk );
            out.println( "<file name=\"" + item.getName() + "\" size=\""+ item.getSize()+" path=\"" + getInitParameter("uploadPath") + "\" />"  );

          }

        }

        out.println( " </response>" );

        out.close();

      } catch( FileUploadException fue ) {

        fue.printStackTrace();
View Full Code Here

Examples of javax.servlet.ServletOutputStream

     */
    private void copyContent(HttpServletResponse response, InputStream istream)
            throws IOException {

        // Copy resource to output stream
        ServletOutputStream ostream = null;
        try {
            response.setBufferSize(outputBufferSize);
            ostream = response.getOutputStream();

            int len;
            byte buffer[] = new byte[inputBufferSize];
            while ((len = istream.read(buffer)) != -1) {
                ostream.write(buffer, 0, len);
            }
        } finally {
            IOUtilities.close(istream);
        }
        ostream.flush();
    }
View Full Code Here

Examples of javax.servlet.ServletOutputStream

    /**
     * {@inheritDoc}
     */
    public ServletOutputStream getOutputStream() throws IOException {
        return new ServletOutputStream() {

            public void write(int i) throws java.io.IOException {
                webSocketSupport.write(frame, new byte[]{(byte) i});
            }

View Full Code Here

Examples of javax.servlet.ServletOutputStream

 
  responseLength = responseString.length();
 
  resp.setContentType("message/http");
  resp.setContentLength(responseLength);
  ServletOutputStream out = resp.getOutputStream();
  out.print(responseString)
  out.close();
  return;
    }   
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.