Package com.caucho.vfs

Examples of com.caucho.vfs.ReadStream


    throws IOException
  {
    int length = 0;
    int ch;

    ReadStream is = _next;

    // skip whitespace
    for (ch = is.read();
         ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n';
         ch = is.read()) {
    }

    // XXX: This doesn't properly handle the case when when the browser
    // sends headers at the end of the data.  See the HTTP/1.1 spec.
    for (; ch > 0 && ch != '\r' && ch != '\n'; ch = is.read()) {
      if ('0' <= ch && ch <= '9')
        length = 16 * length + ch - '0';
      else if ('a' <= ch && ch <= 'f')
        length = 16 * length + ch - 'a' + 10;
      else if ('A' <= ch && ch <= 'F')
        length = 16 * length + ch - 'A' + 10;
      else if (ch == ' ' || ch == '\t') {
        //if (dbg.canWrite())
        //  dbg.println("unexpected chunk whitespace.");
      }
      else {
        StringBuilder sb = new StringBuilder();

        sb.append((char) ch);
        for (int ch1 = is.read();
             ch1 >= 0 && ch1 != '\r' && ch1 != '\n';
             ch1 = is.read()) {
          sb.append((char) ch1);
        }

        throw new IOException("HTTP/1.1 protocol error: bad chunk at"
                              + " '" + sb + "'"
                              + " 0x" + Integer.toHexString(ch)
                              + " length=" + length);
      }
    }

    if (ch == '\r')
      ch = is.read();

    return length;
  }
View Full Code Here


   * Parses the XTP file as either an XML document or an HTML document.
   */
  private CauchoDocument parseXtp()
    throws IOException, ServletException
  {
    ReadStream is = _sourcePath.openRead();
    try {
      XmlParser parser;
     
      if (_strictXml) {
        parser = new Xml();
        parser.setEntitiesAsText(_entitiesAsText);
      }
      else {
        parser = new Html();
        parser.setAutodetectXml(true);
        parser.setEntitiesAsText(true);
        // parser.setXmlEntitiesAsText(entitiesAsText);
        parser.setToLower(_toLower);
      }

      parser.setResinInclude(true);
      parser.setJsp(true);

      return (CauchoDocument) parser.parseDocument(is);
    } catch (Exception e) {
      JspParseException jspE = JspParseException.create(e);
     
      jspE.setErrorPage(_errorPage);
     
      throw jspE;
    } finally {
      is.close();
    }
  }
View Full Code Here

    Path tempDir = _rootDir.getParent().lookup(".temp");
    Path dependPath = _rootDir.lookup("META-INF/resin-rar.timestamp");

      // XXX: change to a hash
    if (dependPath.canRead()) {
      ReadStream is = null;
      ObjectInputStream ois = null;
      try {
        is = dependPath.openRead();
        ois = new ObjectInputStream(is);

        long lastModified = ois.readLong();
        long length = ois.readLong();

        if (lastModified == rar.getLastModified() &&
            length == rar.getLength())
          return;
      } catch (IOException e) {
      } finally {
        try {
          if (ois != null)
            ois.close();
        } catch (IOException e) {
        }

        if (is != null)
          is.close();
      }
    }

    try {
      if (log.isLoggable(Level.INFO))
        log.info("expanding rar " + rar + " to " + tempDir);

     
      if (! tempDir.equals(expandDir)) {
        tempDir.removeAll();
      }
      tempDir.mkdirs();

      ReadStream rs = rar.openRead();
      ZipInputStream zis = new ZipInputStream(rs);

      try {
        ZipEntry entry;

        byte []buffer = new byte[1024];
     
        while ((entry = zis.getNextEntry()) != null) {
          String name = entry.getName();
          Path path = tempDir.lookup(name);

          if (entry.isDirectory())
            path.mkdirs();
          else {
            long length = entry.getSize();
            long lastModified = entry.getTime();
            path.getParent().mkdirs();

            WriteStream os = path.openWrite();
            try {
              int len;
              while ((len = zis.read(buffer, 0, buffer.length)) > 0)
                os.write(buffer, 0, len);
            } catch (IOException e) {
              log.log(Level.FINE, e.toString(), e);
            } finally {
              os.close();
            }

            if (lastModified > 0)
              path.setLastModified(lastModified);
          }
        }
      } finally {
        try {
          zis.close();
        } catch (IOException e) {
        }

        rs.close();
      }

      if (! tempDir.equals(expandDir)) {
        if (log.isLoggable(Level.INFO))
          log.info("moving rar " + rar + " to " + expandDir);
View Full Code Here

      HttpBufferStore httpBuffer = server.allocateHttpBuffer();

      startRequest(httpBuffer);
      startInvocation();

      ReadStream is = getRawRead();
      WriteStream os = getRawWrite();

      _filter.init(is, os);
      _writeStream.init(_filter);
      // _writeStream.setWritePrefix(3);
View Full Code Here

      int sublen = _pendingData;
      if (length < sublen)
        sublen = length;

      ReadStream is = _request.getRawRead();

      is.readAll(buf, offset, sublen);

      _pendingData -= sublen;

      if (_pendingData == 0) {
        if (_pad > 0)
          is.skip(_pad);

        _pad = 0;

        int version = is.read();
        int code = is.read();
        int id = (is.read() << 8) + is.read();
        _pendingData = (is.read() << 8) + is.read();
        _pad = is.read();
        int reserved = is.read();

        if (reserved < 0 || code != FCGI_STDIN)
          _pendingData = 0;
      }
View Full Code Here

  }

  private boolean checkFileDescriptor()
  {
    try {
      ReadStream is = _resin.getResinConf().openRead();
      is.close();

      return true;
    } catch (IOException e) {
      log.severe(L.l("Restarting due to file descriptor failure:\n{0}",
                     e));
View Full Code Here

    char []cBuf = buf.getBuffer();
    int len;

    PrintWriter out = response.getWriter();
   
    ReadStream rs = _cacheEntry.openRead();
    rs.setEncoding("UTF-8");
    try {
      while ((len = rs.read(cBuf, 0, cBuf.length)) > 0) {
        out.write(cBuf, 0, len);
      }
    } finally {
      rs.close();
    }

    TempCharBuffer.free(buf);
  }
View Full Code Here

  }

  static ArrayList<Depend> parseDepend(Path dependPath)
    throws IOException
  {
    ReadStream is = dependPath.openRead();
    try {
      ArrayList<Depend> dependList = new ArrayList<Depend>();
     
      String name;

      while ((name = parseName(is)) != null) {
        long digest = Long.parseLong(parseName(is));

        Depend depend = new Depend(dependPath.lookup(name), digest);

        dependList.add(depend);
      }

      return dependList;
    } finally {
      is.close();
    }
  }
View Full Code Here

    String string = arg.toString();

    Global resin = Global.getGlobalProto();
    ESBase context = eval.getFunctionContext();
    Script script = null;
    ReadStream is = null;
    try {
      Parser parser = new Parser();
      is = Vfs.openString(string);
      script = parser.parseEval(is, "eval", 1);
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (is != null)
        is.close();
    }

    ESCallable jsClass = script.initClass(resin, eval.getGlobal());
   
    return jsClass.call(2, eval.caller, 0);
View Full Code Here

    Global resin = Global.getGlobalProto();
    Script script = null;
    try {
      Parser parser = new Parser();
      ReadStream is = Vfs.openString(sbuf.toString());
      script = parser.parse(is, "anonymous", 1);
      is.close();
    } catch (IOException e) {
      e.printStackTrace();
    }

    ESCallable jsClass = script.initClass(resin, eval.getGlobal());
View Full Code Here

TOP

Related Classes of com.caucho.vfs.ReadStream

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.