private ArrayList<Path> holeLaufwerkeUnix() { ArrayList<Path> laufwerksRoot = new ArrayList<>(); for (FileStore store : FileSystems.getDefault().getFileStores()) { if (store.name().contains("/dev/sd")) { laufwerksRoot.add( Paths.get(store.toString().substring(0, store.toString().indexOf(' ')))); } } return laufwerksRoot; }
public NodePath(Path path, Environment environment) throws IOException { this.path = path; this.indicesPath = path.resolve(INDICES_FOLDER); this.fileStore = environment.getFileStore(path); if (fileStore.supportsFileAttributeView("lucene")) { this.spins = (Boolean) fileStore.getAttribute("lucene:spins"); } else { this.spins = null; } }
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); }
public NodePath(Path path) throws IOException { this.path = path; this.indicesPath = path.resolve(INDICES_FOLDER); this.fileStore = Environment.getFileStore(path); if (fileStore.supportsFileAttributeView("lucene")) { this.spins = (Boolean) fileStore.getAttribute("lucene:spins"); this.majorDeviceNumber = (int) fileStore.getAttribute("lucene:major_device_number"); this.minorDeviceNumber = (int) fileStore.getAttribute("lucene:minor_device_number"); } else { this.spins = null; this.majorDeviceNumber = -1; this.minorDeviceNumber = -1; } }
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)); }
@Test public void preallocateTooLarge() throws Exception { assumeTrue(Platform.isLinux()); FileIO fio = FileIO.open(file, EnumSet.of(OpenOption.CREATE, OpenOption.MAPPED, OpenOption.PREALLOCATE)); FileStore fs = Files.getFileStore(file.toPath()); assumeTrue("ext4".equals(fs.type()) && !fs.name().contains("docker")); long len = file.getTotalSpace() * 100L; // setLength traps the IOException and prevents resizing / remapping. Not remapping avoids // the SIGBUS issue. fio.setLength(len); assertEquals(0, fio.length()); fio.close(); }
/** 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)); }
private void setupFooter() { try { usedFileStore = Files.getFileStore(ToolSettings.NBITES_DIR_PATH); } catch (Exception e) { e.printStackTrace(); ; throw new Error(e); } Debug.warn("Tool footer using fileStore: %s", usedFileStore.name()); display.diskAvailLabel.setText(Utility.progressString(progressSize, 0.5)); display.jvmAvailLabel.setText(Utility.progressString(progressSize, 0.5)); footerJvmTimer = new Timer( 1000, // ms new ActionListener() { @Override public void actionPerformed(ActionEvent e) { footerJvmAction(); } }); footerJvmTimer.start(); footerDiskTimer = new Timer( 1000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { footerDiskAction(); } }); footerDiskTimer.start(); }