Package com.caucho.vfs

Examples of com.caucho.vfs.WriteStream


      return;
    }

    if (_path.isFile(pathInfo, req, app)) {
      OutputStream os = _path.openWrite(destPath, req, app);
      WriteStream ws = Vfs.openWrite(os);
      try {
        InputStream is = _path.openRead(pathInfo, req, app);
        try {
          ws.writeStream(is);
        } finally {
          is.close();
        }
      } finally {
        ws.close();
      }
      return;
    }
    else {
      copyRecursive(pathInfo, destPath, depth, req);
View Full Code Here


        }
      }
    }
    else {
      OutputStream os = _path.openWrite(destPath, req, app);
      WriteStream ws = Vfs.openWrite(os);
      try {
        InputStream is = _path.openRead(srcPath, req, app);
        try {
          ws.writeStream(is);
        } finally {
          is.close();
        }
      } finally {
        ws.close();
      }
    }
  }
View Full Code Here

      res.setStatus(204, "No Content");
    }
    else if (_path.isFile(pathInfo, req, app)) {
      HashMap<AttributeName,String> props = getProperties(pathInfo, req, app);
      OutputStream os = _path.openWrite(destPath, req, app);
      WriteStream ws = Vfs.openWrite(os);
     
      try {
        InputStream is = _path.openRead(pathInfo, req, app);
        try {
          ws.writeStream(is);
        } finally {
          is.close();
        }
      } finally {
        ws.close();
      }
      setProperties(props, destPath, req, app);

      _path.remove(pathInfo, req, app);
    }
View Full Code Here

      _path.remove(srcPath, req, app);
    }
    else {
      HashMap<AttributeName,String> props = getProperties(srcPath, req, app);
      OutputStream os = _path.openWrite(destPath, req, app);
      WriteStream rs = Vfs.openWrite(os);
     
      try {
        InputStream is = _path.openRead(srcPath, req, app);
        try {
          rs.writeStream(is);
        } finally {
          is.close();
        }
      } finally {
        rs.close();
        os.close();
      }
     
      setProperties(props, destPath, req, app);
      _path.remove(srcPath, req, app);
View Full Code Here

                                OutputStream out,
                                boolean keepalive)
    throws ServletException, IOException
  {
    ReadStream rs = stream.getInputStream();
    WriteStream ws = stream.getOutputStream();

    writeHeader(ws, FCGI_BEGIN_REQUEST, 8);

    int role = FCGI_RESPONDER;

    ws.write(role >> 8);
    ws.write(role);
    ws.write(keepalive ? FCGI_KEEP_CONN : 0); // flags
    for (int i = 0; i < 5; i++)
      ws.write(0);

    setEnvironment(stream, ws, req);

    InputStream in = req.getInputStream();
    TempBuffer tempBuf = TempBuffer.allocate();
    byte []buf = tempBuf.getBuffer();
    int len = buf.length;
    int sublen;

    writeHeader(ws, FCGI_PARAMS, 0);

    boolean hasStdin = false;
    while ((sublen = in.read(buf, 0, len)) > 0) {
      hasStdin = true;
      writeHeader(ws, FCGI_STDIN, sublen);
      ws.write(buf, 0, sublen);
    }

    TempBuffer.free(tempBuf);
    tempBuf = null;

    /*
    if (hasStdin)
      writeHeader(fcgiSocket, ws, FCGI_STDIN, 0);
    */
    writeHeader(ws, FCGI_STDIN, 0);
   
    ws.flush();

    FastCGIInputStream is = new FastCGIInputStream(stream);

    int ch = parseHeaders(res, is);

View Full Code Here

    response.setContentType("text/html");

    Statement stmt = new SSIParser(_factory).parse(path);

    WriteStream out = Vfs.openWrite(response.getOutputStream());

    try {
      stmt.apply(out, request, response);
      out.close();
    } catch (Exception e) {
      String errmsg = (String) request.getAttribute("caucho.ssi.errmsg");

      if (errmsg != null && ! response.isCommitted()) {
        log.log(Level.FINE, e.toString(), e);

        response.setStatus(500, errmsg);
        response.setContentType("text/html");

        out.clearWrite();
        out.println("<html><head>");
        out.println("<title>" + errmsg + "</title>");
        out.println("</head>");

        out.println("<h1>" + errmsg + "</h1>");
        out.println("</html>");
        out.close();
      }
      else if (e instanceof RuntimeException)
        throw (RuntimeException) e;
      else if (e instanceof IOException)
        throw (IOException) e;
View Full Code Here

                                String uri,
                                ClientSocket stream)
    throws ServletException, IOException
  {
    ReadStream rs = stream.getInputStream();
    WriteStream out = stream.getOutputStream();

    try {
      out.print(req.getMethod());
      out.print(' ');
      out.print(uri);
      out.print(" HTTP/1.1\r\n");

      out.print("Host: ");
      String host = req.getHeader("Host");
      if (host != null)
        out.println(host);
      else
        out.println(req.getServerName() + ":" + req.getServerPort());

      out.print("X-Forwarded-For: ");
      out.println(req.getRemoteAddr());

      Enumeration<String> e = req.getHeaderNames();
      while (e.hasMoreElements()) {
        String name = e.nextElement();

        if (name.equalsIgnoreCase("Connection"))
          continue;

        Enumeration<String> e1 = req.getHeaders(name);
        while (e1.hasMoreElements()) {
          String value = (String) e1.nextElement();

          out.print(name);
          out.print(": ");
          out.println(value);
        }
      }

      int contentLength = req.getContentLength();

      InputStream is = req.getInputStream();

      TempBuffer tempBuffer = TempBuffer.allocate();
      byte []buffer = tempBuffer.getBuffer();

      boolean isFirst = true;

      if (contentLength >= 0) {
        isFirst = false;
        out.print("\r\n");
      }

      int len;
      while ((len = is.read(buffer, 0, buffer.length)) > 0) {
        if (isFirst) {
          out.print("Transfer-Encoding: chunked\r\n");
        }
        isFirst = false;

        if (contentLength < 0) {
          out.print("\r\n");
          out.print(Integer.toHexString(len));
          out.print("\r\n");
        }

        out.write(buffer, 0, len);
      }

      if (isFirst) {
        out.print("Content-Length: 0\r\n");
      }
      else
        out.print("\r\n0\r\n");

      out.print("\r\n");

      TempBuffer.free(tempBuffer);

      out.flush();
     
      return parseResults(rs, req, res);
    } catch (IOException e1) {
      log.log(Level.FINE, e1.toString(), e1);
View Full Code Here

    {
      _request = request;
     
      _tempStream = new TempStream();
      _tempStream.openWrite();
      _out = new WriteStream(_tempStream);

      init(response);
    }
View Full Code Here

      } finally {
        is.close();
      }

      try {
        WriteStream out = Vfs.openWrite(res.getOutputStream());
        stmt.apply(out, req, res);
        out.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
View Full Code Here

  {
    _lineMap = null;
    Properties output = _stylesheet.getOutputProperties();

    com.caucho.vfs.StringWriter sw = new com.caucho.vfs.StringWriter();
    WriteStream ws = sw.openWrite();
   
    XmlPrinter out = new XmlPrinter(ws);

    out.setMethod((String) output.get(OutputKeys.METHOD));
    out.setEncoding("UTF-8");
    out.setMimeType((String) output.get(OutputKeys.MEDIA_TYPE));
    String omit = (String) output.get(OutputKeys.OMIT_XML_DECLARATION);

    if (omit == null || omit.equals("false") || omit.equals("no"))
      out.setPrintDeclaration(true);
    out.setStandalone((String) output.get(OutputKeys.STANDALONE));
    out.setSystemId((String) output.get(OutputKeys.DOCTYPE_SYSTEM));
    out.setPublicId((String) output.get(OutputKeys.DOCTYPE_PUBLIC));
   
    String indent = (String) output.get(OutputKeys.INDENT);
    if (indent != null)
      out.setPretty(indent.equals("true"));
    out.setVersion((String) output.get(OutputKeys.VERSION));
    if (node instanceof CauchoNode) {
      String filename = ((CauchoNode) node).getFilename();
      out.setLineMap(filename != null ? filename : "anonymous.xsl");
    }
    else
      out.setLineMap("anonymous.xsl");
   
      String includeContentType = (String) output.get("include-content-type");
      if (includeContentType != null)
        out.setIncludeContentType(includeContentType.equals("true") ||
                                  includeContentType.equals("yes"));

    try {
      out.startDocument();
      _stylesheet.transform(node, out, this);
      out.endDocument();
      _lineMap = out.getLineMap();
      ws.close();

      return sw.getString();
    } catch (Exception e) {
      throw new IOExceptionWrapper(e);
    }
View Full Code Here

TOP

Related Classes of com.caucho.vfs.WriteStream

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.