示例#1
0
  /** File store properties examined */
  @Test
  public void testRetrieveFileStoreInforamtion() throws IOException {
    FileSystem fs = FileSystems.getDefault();
    assertNotNull(fs);

    List<FileStore> stores = iterableToList(fs.getFileStores());

    // file store is device such a drive, partition or volume
    // in my system I have 3 partitions
    assertEquals(3, stores.size());

    // for storing triples of basic file store identification
    Set<String> storeNames = new HashSet<>();
    for (FileStore store : stores) {
      storeNames.add(store.name() + ";" + store.type() + ";" + store.isReadOnly());
      long total = store.getTotalSpace();
      long unallocated = store.getUnallocatedSpace();
      long usable = store.getUsableSpace();
      assertTrue(total > 0);
      assertTrue(unallocated > 0 && total >= unallocated);
      assertTrue(usable > 0 && total >= usable);
      // Just for notice of NumberFormat class existence :)
      // System.out.println(NumberFormat.getInstance().format(total));
    }

    // environment dependent
    assertEquals(
        cSET("Windows7_OS;NTFS;false", "Data;NTFS;false", "Documents;NTFS;false"), storeNames);

    // can be used for determine if file store supports such attribute view
    assertTrue(stores.get(0).supportsFileAttributeView(BasicFileAttributeView.class));
    assertFalse(stores.get(0).supportsFileAttributeView(PosixFileAttributeView.class));
  }
示例#2
0
  static void printFileStore(FileStore store) throws IOException {
    String total = format(store.getTotalSpace());
    String used = format(store.getTotalSpace() - store.getUnallocatedSpace());
    String avail = format(store.getUsableSpace());

    String s = store.toString();
    if (s.length() > 20) {
      System.out.println(s);
      s = "";
    }
    System.out.format("%-20s %12s %12s %12s\n", s, total, used, avail);
  }
  private void footerDiskAction() {
    long diskSpace;
    long diskUsed;
    try {
      diskSpace = usedFileStore.getTotalSpace();
      diskUsed = diskSpace - usedFileStore.getUnallocatedSpace();
    } catch (IOException e) {
      e.printStackTrace();
      throw new Error(e);
    }

    double diskFrac = ((double) diskUsed) / ((double) diskSpace);
    display.diskAvailLabel.setText(Utility.progressString(progressSize, diskFrac));
  }