Package com.caucho.vfs

Examples of com.caucho.vfs.RandomAccessStream


  {
    RandomAccessWrapper wrapper = openRowFile(true);
    boolean isPriority = true;

    try {
      RandomAccessStream file = wrapper.getFile();

      _fileSize = file.getLength();
    } finally {
      closeRowFile(wrapper, isPriority);
    }
  }
View Full Code Here


  {
    boolean isPriority = false;
    RandomAccessWrapper wrapper = openRowFile(isPriority);

    try {
      RandomAccessStream is = wrapper.getFile();

      long blockAddress = blockId & BlockStore.BLOCK_MASK;

      if (blockAddress < 0 || _fileSize < blockAddress + length) {
        throw new IllegalStateException(L.l("block at 0x{0} is invalid for file {1} (length 0x{2})",
                                            Long.toHexString(blockAddress),
                                            _path,
                                            Long.toHexString(_fileSize)));
      }

      // System.out.println("READ: " + Long.toHexString(blockAddress));
      int readLen = is.read(blockAddress, buffer, offset, length);

      if (readLen < 0) {
        throw new IllegalStateException("Error reading " + is + " for block " + Long.toHexString(blockAddress) + " result=" + readLen);
      }
View Full Code Here

    }

    wrapper = openRowFile(isPriority);

    try {
      RandomAccessStream os = wrapper.getFile();
      /*
      if (blockAddress > 2 * 0x2000000) {
      System.out.println("BLOCK: " + Long.toHexString(blockAddress) + " " + offset);
      Thread.dumpStack();
      }
      */
      if (buffer == null || offset < 0 || length < 0 || buffer.length < offset + length)
        System.out.println("BUFFER: " + buffer + " " + offset + " " + length);

      os.write(blockAddress, buffer, offset, length);
      freeRowFile(wrapper, isPriority);
      wrapper = null;

      _blockManager.addBlockWrite();
    } finally {
View Full Code Here

   * Opens the underlying file to the database.
   */
  private RandomAccessWrapper openRowFileImpl()
    throws IOException
  {
    RandomAccessStream file = null;
    RandomAccessWrapper wrapper = null;

    // SoftReference<RandomAccessWrapper> ref = _cachedRowFile.allocate();
    wrapper = _cachedRowFile.allocate();

    /*
    if (ref != null) {
      wrapper = ref.get();
    }
    */

    if (wrapper != null) {
      file = wrapper.getFile();
     
      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();
        }
View Full Code Here

   */
  void close()
  {
    _path = null;

    RandomAccessStream mmap = _mmapFile.getAndSet(null);
   
    if (mmap != null) {
      try {
        mmap.close();
      } catch (Exception e) {
        log.log(Level.FINER, e.toString(), e);
      }
    }
    RandomAccessWrapper wrapper = null;
View Full Code Here

    }

    void close()
      throws IOException
    {
      RandomAccessStream file = _file;
      _file = null;

      if (file != null)
        file.close();
    }
View Full Code Here

   * Implements the EnvCleanup interface.
   */
  public void cleanup()
  {
    try {
      RandomAccessStream ras = _stream;
      _stream = null;

      if (ras != null) {
        ras.close();

        if (_temporary)
          _path.remove();
      }
    } catch (IOException e) {
View Full Code Here

    RandomAccessWrapper wrapper;

    wrapper = openRowFile(isPriority);

    try {
      RandomAccessStream os = wrapper.getFile();
      /*
      if (blockAddress > 2 * 0x2000000) {
      System.out.println("BLOCK: " + Long.toHexString(blockAddress) + " " + offset);
      Thread.dumpStack();
      }
      */
      if (buffer == null || offset < 0 || length < 0 || buffer.length < offset + length)
        System.out.println("BUFFER: " + buffer + " " + offset + " " + length);

      os.write(blockAddress, buffer, offset, length);

      freeRowFile(wrapper, isPriority);
      wrapper = null;

      synchronized (_fileLock) {
View Full Code Here

   * Opens the underlying file to the database.
   */
  private RandomAccessWrapper openRowFileImpl()
    throws IOException
  {
    RandomAccessStream file = null;
    RandomAccessWrapper wrapper = null;

    // SoftReference<RandomAccessWrapper> ref = _cachedRowFile.allocate();
    wrapper = _cachedRowFile.allocate();

View Full Code Here

    }

    void close()
      throws IOException
    {
      RandomAccessStream file = _file;
      _file = null;

      if (file != null)
        file.close();
    }
View Full Code Here

TOP

Related Classes of com.caucho.vfs.RandomAccessStream

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.