Package com.caucho.vfs

Examples of com.caucho.vfs.ReadStream


  }

  private void readBlock(byte []block, long count)
    throws Exception
  {
    ReadStream is = _path.openRead();

    try {
      is.skip(count * BlockStore.BLOCK_SIZE);

      is.read(block, 0, block.length);
    } finally {
      is.close();
    }
  }
View Full Code Here


                            long lengthMax)
    throws IOException
  {
    MultipartStream ms = new MultipartStream(rawIs, boundary);
    ms.setEncoding(javaEncoding);
    ReadStream is;

    while ((is = ms.openRead()) != null) {
      String attr = (String) ms.getAttribute("content-disposition");

      if (attr == null || ! attr.startsWith("form-data")) {
        // XXX: is this an error?
        continue;
      }

      String name = getAttribute(attr, "name");
      String filename = getAttribute(attr, "filename");
      String contentType = getAttribute(attr, "content-type");
     
      if (contentType == null)
        contentType = ms.getAttribute("content-type");

      if (name == null) {
        // XXX: is this an error?
        continue;
      }
      else if (filename != null) {
        Path tempDir = CauchoSystem.getWorkPath().lookup("form");
        try {
          tempDir.mkdirs();
        } catch (IOException e) {
        }
        Path tempFile = tempDir.createTempFile("form", ".tmp");
        request.addCloseOnExit(tempFile);

        WriteStream os = tempFile.openWrite();

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

        int totalLength = 0;

        try {
          int len;

          while ((len = is.read(buf, 0, buf.length)) > 0) {
            os.write(buf, 0, len);
            totalLength += len;
          }
        } finally {
          os.close();

          TempBuffer.free(tempBuffer);
          tempBuffer = null;
        }

        if (uploadMax > 0 && uploadMax < tempFile.getLength()) {
          String msg = L.l("multipart form data '{0}' too large",
                           "" + tempFile.getLength());
          request.setAttribute("caucho.multipart.form.error", msg);
          request.setAttribute("caucho.multipart.form.error.size",
                               new Long(tempFile.getLength()));
         
          tempFile.remove();
         
          throw new IOException(msg);
        } else if (fileUploadMax > 0 && fileUploadMax < tempFile.getLength()){
          String msg = L.l("multipart form data part '{0}':'{1}' is greater then the accepted value of '{2}'",
                           name, "" + tempFile.getLength(), fileUploadMax);

          tempFile.remove();

          throw new IllegalStateException(msg);
        }
        else if (tempFile.getLength() != totalLength) {
          String msg = L.l("multipart form upload failed (possibly due to full disk).");

          request.setAttribute("caucho.multipart.form.error", msg);
          request.setAttribute("caucho.multipart.form.error.size",
                               new Long(tempFile.getLength()));
         
          tempFile.remove();
         
          throw new IOException(msg);
        }

        // server/136u, server/136v, #2578
        if (table.get(name + ".filename") == null) {
          table.put(name, new String[] { tempFile.getNativePath() });
          table.put(name + ".file", new String[] { tempFile.getNativePath() });
          table.put(name + ".filename", new String[] { filename });
          table.put(name + ".content-type", new String[] { contentType });
        }
        else {
          addTable(table, name, tempFile.getNativePath());
          addTable(table, name + ".file", tempFile.getNativePath());
          addTable(table, name + ".filename", filename);
          addTable(table, name + ".content-type", contentType);
        }

      if (log.isLoggable(Level.FINE))
          log.fine("mp-file: " + name + "(filename:" + filename + ")");
      } else {
        CharBuffer value = new CharBuffer();
        int ch;
        long totalLength = 0;

        for (ch = is.readChar(); ch >= 0; ch = is.readChar()) {
          value.append((char) ch);
          totalLength++;
         
          if (lengthMax < totalLength) {
            String msg = L.l("multipart form upload failed because field '{0}' exceeds max length {1}",
View Full Code Here

    if (conn instanceof TcpSocketLink)
      _tcpConn = (TcpSocketLink) conn;
    else
      _tcpConn = null;

    _readStream = new ReadStream();
    _readStream.setReuseBuffer(true);

    _bufferedReader = new BufferedReaderAdapter(_readStream);

    _response = createResponse();
View Full Code Here

   * Returns a stream for reading POST data.
   */
  public final ServletInputStream getInputStream()
    throws IOException
  {
    ReadStream stream = getStream(false);

    _is.init(stream);

    return _is;
  }
View Full Code Here

    try {
      thread.setName(_readThreadName);
      thread.setContextClassLoader(_loader);

      TcpSocketLink conn = _conn;
      ReadStream is = _is;
      SocketLinkDuplexListener handler = _listener;

      if (conn == null || is == null || handler == null) {
        return false;
      }

      if (is.getAvailable() > 0) {
        isValid = true;
        handler.onRead(this);
        return true;
      }
      else {
View Full Code Here

  protected void postExtract(boolean isExtract)
    throws IOException
  {
    Path path = getRootDirectory().lookup("META-INF/MANIFEST.MF");
    if (path.canRead()) {
      ReadStream is = path.openRead();
     
      try {
        _manifest = new Manifest(is);
      } catch (IOException e) {
        log.warning(L.l("{0} Manifest file cannot be read for '{1}'.\n  {2}",
                        this, getRootDirectory(), e));

        log.log(Level.FINE, e.toString(), e);
      } finally {
        is.close();
      }
    }
  }
View Full Code Here

   */
  private String readRootHash()
  {
    Path path = _rootDirectory.lookup(APPLICATION_HASH_PATH);
   
    ReadStream is = null;
    try {
      is = path.openRead();
     
      String rootHash = is.readLine();
     
      return rootHash;
    } catch (FileNotFoundException e) {
      log.log(Level.ALL, e.toString(), e);
     
View Full Code Here

    InputStream is = null;
   
    try {
      is = serviceURL.openStream();

      ReadStream in = Vfs.openRead(is);
      String line;
      while ((line = in.readLine()) != null) {
        int p = line.indexOf('#');
        if (p >= 0)
          line = line.substring(p);

        line = line.trim();
View Full Code Here

  private final ReadStream _readStream;
  private final WriteStream _writeStream;

  public AbstractSocketLink()
  {
    _readStream = new ReadStream();
    _readStream.setReuseBuffer(true);
    _writeStream = new WriteStream();
    _writeStream.setReuseBuffer(true);
  }
View Full Code Here

      throw e;
    }

    try {
      ReadWritePair pair = openTCPPair();
      ReadStream rs = pair.getReadStream();
      rs.setEnableReadTime(true);
     
      rs.setAttribute("timeout", new Integer((int) _loadBalanceSocketTimeout));

      _activeCount.incrementAndGet();
     
      _connectCountTotal.incrementAndGet();
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.