예제 #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));
  }