Package com.caucho.vfs

Examples of com.caucho.vfs.Path


   * Loads the table from the file.
   */
  public static Table loadFromFile(Database db, String name)
    throws IOException, SQLException
  {
    Path path = db.getPath().lookup(name + ".db");

    if (! path.exists()) {
      if (log.isLoggable(Level.FINE))
        log.fine(db + " '" + path.getNativePath() + "' is an unknown table");

      return null; //throw new SQLException(L.l("table {0} does not exist", name));
    }

    String version = null;

    ReadStream is = path.openRead();
    try {
      // skip allocation table and fragment table
      is.skip(DATA_START + ROOT_DATA_OFFSET);

      StringBuilder sb = new StringBuilder();
      int ch;

      while ((ch = is.read()) > 0) {
        sb.append((char) ch);
      }

      version = sb.toString();

      if (! version.startsWith("Resin-DB")) {
        throw new SQLException(L.l("table {0} is not a Resin DB.  Version '{1}'",
                                   name, version));
      }
      else if (version.compareTo(MIN_VERSION) < 0 ||
               DB_VERSION.compareTo(version) < 0) {
        throw new SQLException(L.l("table {0} is out of date.  Old version {1}.",
                                   name, version));
      }
    } finally {
      is.close();
    }

    is = path.openRead();
    try {
      // skip allocation table and fragment table
      is.skip(DATA_START + ROOT_DATA_END);

      StringBuilder cb = new StringBuilder();

      int ch;
      while ((ch = is.read()) > 0) {
        cb.append((char) ch);
      }

      String sql = cb.toString();

      if (log.isLoggable(Level.FINER))
        log.finer("Table[" + name + "] " + version + " loading\n" + sql);

      try {
        CreateQuery query = (CreateQuery) Parser.parse(db, sql);

        TableFactory factory = query.getFactory();

        if (! factory.getName().equalsIgnoreCase(name))
          throw new IOException(L.l("factory {0} does not match", name));

        Table table = new Table(db, factory.getName(), factory.getRow(),
                                factory.getConstraints());

        table.init();

        //if (! table.validateIndexesSafe()) {
          table.clearIndexes();
          table.initIndexes();
          table.rebuildIndexes();
        //}

        return table;
      } catch (Exception e) {
        log.log(Level.WARNING, e.toString(), e);

        throw new SQLException(L.l("can't load table {0} in {1}.\n{2}",
                                   name, path.getNativePath(), e.toString()));
      }
    } finally {
      is.close();
    }
  }
View Full Code Here


  public void remove()
    throws SQLException
  {
    try {
      Path path = _path;
      _path = null;

      close();

      if (path != null)
        path.remove();
    } catch (IOException e) {
      throw new SQLExceptionWrapper(e);
    }
  }
View Full Code Here

      if (_mmapFile.get() != null && file.getLength() != _fileSize)
        file = null;
    }

    if (file == null) {
      Path path = _path;

      if (path != null) {
        RandomAccessStream mmapFile = _mmapFile.get();
       
        if (mmapFile != null && mmapFile.getLength() == _fileSize) {
          return new RandomAccessWrapper(mmapFile);
        }
       
        if (_isEnableMmap) {
          long fileSize = _fileSize;
         
          if (fileSize == 0)
            fileSize = FILE_SIZE_INCREMENT;
         
          file = path.openMemoryMappedFile(fileSize);

          if (file != null)
            _fileSize = fileSize;
        }

        if (file != null) {
          _isMmap = true;
          RandomAccessStream oldMmap = _mmapFile.getAndSet(file);
         
          if (oldMmap != null)
            oldMmap.close();
        }
        else {
          _isEnableMmap = false;
          file = path.openRandomAccess();
        }
       
        wrapper = new RandomAccessWrapper(file);
      }
    }
View Full Code Here

      Table table = _tables.get(name);

      if (table != null)
        return table;
     
      Path dir = _dir;
   
      if (dir == null)
        return null;

      try {
        table = Table.loadFromFile(this, name);

        if (table == null)
          return null;

        table.setFlushDirtyBlocksOnCommit(_isFlushDirtyBlocksOnCommit);
        table.init();

        _tables.put(name, table);

        return table;
      } catch (Exception e) {
        if (log.isLoggable(Level.FINER))
          log.log(Level.FINER, e.toString(), e);

        if (_removeOnError) {
          if (log.isLoggable(Level.FINER))
            log.log(Level.FINER, e.toString(), e);
          else
            log.warning(e.toString());

          try {
            dir.lookup(name + ".db").remove();
          } catch (IOException e1) {
            log.log(Level.FINEST, e.toString(), e);
          }
        }
      }
View Full Code Here

    if (args.length == 0) {
      System.out.println("usage: DebugStore store.db");
      return;
    }

    Path path = Vfs.lookup(args[0]);

    WriteStream out = Vfs.openWrite(System.out);
   
    new DebugStore(path).test(out);
View Full Code Here

      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))
View Full Code Here

    Thread thread = Thread.currentThread();
    ClassLoader loader = thread.getContextClassLoader();
    try {
      thread.setContextClassLoader(_classLoader);

      Path errorRoot = new MemoryPath().lookup("/error-root");
      errorRoot.mkdirs();
     
      String id = "error/webapp/" + getHostName()+ "/error";

      UnknownWebAppController webAppController
        = new UnknownWebAppController(id, errorRoot, this);
View Full Code Here

      String []list = _path.list();

      BaseNode []children = new BaseNode[list.length];

      for (int i = 0; i < list.length; i++) {
        Path childPath = _path.lookup(list[i]);

        if (childPath.isDirectory())
          children[i] = new DirectoryNode(_session, childPath);
        else
          children[i] = new FileNode(_session, childPath);
      }
View Full Code Here

      initList.add(_config);
  }

  protected void configureInstanceVariables(I instance)
  {
    Path rootDirectory = getRootDirectory();

    if (rootDirectory == null)
      throw new NullPointerException("Null root directory");

    if (! rootDirectory.isFile()) {
    }
    else if (rootDirectory.getPath().endsWith(".jar") ||
             rootDirectory.getPath().endsWith(".war")) {
      throw new ConfigException(L.l("root-directory `{0}' must specify a directory.  It may not be a .jar or .war.",
                                    rootDirectory.getPath()));
    }
    else
      throw new ConfigException(L.l("root-directory `{0}' may not be a file.  root-directory must specify a directory.",
                                    rootDirectory.getPath()));
    Vfs.setPwd(rootDirectory);

    if (log.isLoggable(Level.FINE))
      log.fine(instance + " root-directory=" + rootDirectory);
View Full Code Here

   
    String classPath = Environment.getLocalClassPath();
   
    for (String pathName : classPath.split("[" + File.pathSeparatorChar + "]")) {
      if (pathName.endsWith(jarFile)) {
        Path path = Vfs.lookup(pathName);
       
        try {
          URL url = new URL(path.getURL());
         
          isMatch = true;
         
          if (! _jarFiles.contains(url))
            _jarFiles.add(url);
View Full Code Here

TOP

Related Classes of com.caucho.vfs.Path

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.