Package java.nio.file

Examples of java.nio.file.FileStore


      }

      @Override
      public long getAvailableSpace() {
        try {
          final FileStore fileStore = Files.getFileStore(root);
          return fileStore.getUsableSpace();
        }
        catch (IOException e) {
          throw new BlobStoreException(e, null);
        }
      }
View Full Code Here


    assertThat(fs.provider()).isInstanceOf(JimfsFileSystemProvider.class);
  }

  @Test
  public void testFileStore() throws IOException {
    FileStore fileStore = Iterables.getOnlyElement(fs.getFileStores());
    assertThat(fileStore.name()).isEqualTo("jimfs");
    assertThat(fileStore.type()).isEqualTo("jimfs");
    assertThat(fileStore.isReadOnly()).isFalse();

    long totalSpace = 1024 * 1024 * 1024; // 1 GB
    assertThat(fileStore.getTotalSpace()).isEqualTo(totalSpace);
    assertThat(fileStore.getUnallocatedSpace()).isEqualTo(totalSpace);
    assertThat(fileStore.getUsableSpace()).isEqualTo(totalSpace);

    Files.write(fs.getPath("/foo"), new byte[10000]);

    assertThat(fileStore.getTotalSpace()).isEqualTo(totalSpace);

    // We wrote 10000 bytes, but since the file system allocates fixed size blocks, more than 10k
    // bytes may have been allocated. As such, the unallocated space after the write can be at most
    // maxUnallocatedSpace.
    assertThat(fileStore.getUnallocatedSpace() <= totalSpace - 10000).isTrue();

    // Usable space is at most unallocated space. (In this case, it's currently exactly unallocated
    // space, but that's not required.)
    assertThat(fileStore.getUsableSpace() <= fileStore.getUnallocatedSpace()).isTrue();

    Files.delete(fs.getPath("/foo"));
    assertThat(fileStore.getTotalSpace()).isEqualTo(totalSpace);
    assertThat(fileStore.getUnallocatedSpace()).isEqualTo(totalSpace);
    assertThat(fileStore.getUsableSpace()).isEqualTo(totalSpace);
  }
View Full Code Here

  private BlockingAction<FileSystemProps> fsPropsInternal(String path, Handler<AsyncResult<FileSystemProps>> handler) {
    Path target = vertx.resolveFile(path).toPath();
    return new BlockingAction<FileSystemProps>(handler) {
      public FileSystemProps perform() {
        try {
          FileStore fs = Files.getFileStore(target);
          return new FileSystemPropsImpl(fs.getTotalSpace(), fs.getUnallocatedSpace(), fs.getUsableSpace());
        } catch (IOException e) {
          throw new FileSystemException(e);
        }
      }
    };
View Full Code Here

        db.commit();
    }

    public boolean enoughDiskSpace() {
        try {
            FileStore fs = Files.getFileStore(dbFile.toPath());
            // we want 20% of the partition free
            return ((double) fs.getTotalSpace() / (double) fs.getUsableSpace()) > 1.25;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return false;
        }
    }
View Full Code Here

TOP

Related Classes of java.nio.file.FileStore

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.