Java Code Examples for java.nio.file.FileStore#getTotalSpace()
The following examples show how to use
java.nio.file.FileStore#getTotalSpace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddDVDActionHandler.java From Quelea with GNU General Public License v3.0 | 6 votes |
/** * Get the location of the DVD, or null if no DVD can be found. * <p> * @return the DVD location. */ private String getLocation() { FileSystem fs = FileSystems.getDefault(); for(Path rootPath : fs.getRootDirectories()) { try { FileStore store = Files.getFileStore(rootPath); if(store.type().toLowerCase().contains("udf")) { if(store.getTotalSpace()>10000000000L) { //Blu-ray return "bluray:///" + rootPath.toString(); } else { return "dvdsimple:///" + rootPath.toString(); //DVD } } } catch(IOException ex) { //Never mind } } return null; }
Example 2
Source File: FileSingleStreamSpillerFactory.java From presto with Apache License 2.0 | 5 votes |
private boolean hasEnoughDiskSpace(Path path) { try { FileStore fileStore = getFileStore(path); return fileStore.getUsableSpace() > fileStore.getTotalSpace() * (1.0 - maxUsedSpaceThreshold); } catch (IOException e) { throw new PrestoException(OUT_OF_SPILL_SPACE, "Cannot determine free space for spill", e); } }
Example 3
Source File: DiskUsageSensor.java From swage with Apache License 2.0 | 5 votes |
@Override public TypedMap addContext(final TypedMap existing) { try { // Determine the file store for the directory the JVM was started in FileStore fileStore = Files.getFileStore(Paths.get(System.getProperty("user.dir"))); long size = fileStore.getTotalSpace(); long gb_size = size/(K*K*K); return ImmutableTypedMap.Builder.from(existing).add(DISK_SIZE, Long.valueOf(gb_size)).build(); } catch (IOException e) { // log? return existing; } }
Example 4
Source File: DiskUsageSensor.java From swage with Apache License 2.0 | 5 votes |
@Override public void sense(final MetricContext metricContext) throws SenseException { try { // Determine the file store for the directory the JVM was started in FileStore fileStore = Files.getFileStore(Paths.get(System.getProperty("user.dir"))); long total = fileStore.getTotalSpace(); long free = fileStore.getUsableSpace(); double percent_free = 100.0 * ((double)(total-free)/(double)total); metricContext.record(DISK_USED, percent_free, Unit.PERCENT); } catch (IOException e) { throw new SenseException("Problem reading disk space", e); } }
Example 5
Source File: LocalQuotaFeature.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Override public Space get() throws BackgroundException { final Path home = new DefaultHomeFinderService(session).find(); try { final FileStore store = Files.getFileStore(session.toPath(home)); return new Space(store.getTotalSpace() - store.getUnallocatedSpace(), store.getUnallocatedSpace()); } catch(IOException e) { throw new LocalExceptionMappingService().map("Failure to read attributes of {0}", e, home); } }
Example 6
Source File: NativeManager.java From LagMonitor with MIT License | 5 votes |
public long getTotalSpace() { long totalSpace = 0; try { FileStore fileStore = Files.getFileStore(Paths.get(".")); totalSpace = fileStore.getTotalSpace(); } catch (IOException ioEx) { logger.log(Level.WARNING, "Cannot calculate free disk space", ioEx); } return totalSpace; }
Example 7
Source File: ConfigController.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
private Double freeSpace () { try { final String base = System.getProperty ( SYSPROP_STORAGE_BASE ); final Path p = Paths.get ( base ); final FileStore store = Files.getFileStore ( p ); return (double)store.getUnallocatedSpace () / (double)store.getTotalSpace (); } catch ( final Exception e ) { return null; } }
Example 8
Source File: FileStoreMonitor.java From activemq-artemis with Apache License 2.0 | 5 votes |
private long getTotalSpace(FileStore store) throws IOException { long totalSpace = store.getTotalSpace(); if (totalSpace < 0) { totalSpace = Long.MAX_VALUE; } return totalSpace; }
Example 9
Source File: NativeManager.java From LagMonitor with MIT License | 5 votes |
public long getTotalSpace() { long totalSpace = 0; try { FileStore fileStore = Files.getFileStore(Paths.get(".")); totalSpace = fileStore.getTotalSpace(); } catch (IOException ioEx) { logger.log(Level.WARNING, "Cannot calculate free disk space", ioEx); } return totalSpace; }
Example 10
Source File: LocalFileSystem.java From simple-nfs with Apache License 2.0 | 5 votes |
@Override public FsStat getFsStat() throws IOException { FileStore store = Files.getFileStore(_root); long total = store.getTotalSpace(); long free = store.getUsableSpace(); return new FsStat(total, Long.MAX_VALUE, total-free, pathToInode.size()); }
Example 11
Source File: BugReportGenerator.java From Nukkit with GNU General Public License v3.0 | 4 votes |
private String generate() throws IOException { File reports = new File(Nukkit.DATA_PATH, "logs/bug_reports"); if (!reports.isDirectory()) { reports.mkdirs(); } SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmSS"); String date = simpleDateFormat.format(new Date()); StringBuilder model = new StringBuilder(); long totalDiskSpace = 0; int diskNum = 0; for (Path root : FileSystems.getDefault().getRootDirectories()) { try { FileStore store = Files.getFileStore(root); model.append("Disk ").append(diskNum++).append(":(avail=").append(getCount(store.getUsableSpace(), true)) .append(", total=").append(getCount(store.getTotalSpace(), true)) .append(") "); totalDiskSpace += store.getTotalSpace(); } catch (IOException e) { // } } StringWriter stringWriter = new StringWriter(); throwable.printStackTrace(new PrintWriter(stringWriter)); StackTraceElement[] stackTrace = throwable.getStackTrace(); boolean pluginError = false; if (stackTrace.length > 0) { pluginError = !throwable.getStackTrace()[0].getClassName().startsWith("cn.nukkit"); } File mdReport = new File(reports, date + "_" + throwable.getClass().getSimpleName() + ".md"); mdReport.createNewFile(); String content = Utils.readFile(this.getClass().getClassLoader().getResourceAsStream("report_template.md")); String cpuType = System.getenv("PROCESSOR_IDENTIFIER"); OperatingSystemMXBean osMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); content = content.replace("${NUKKIT_VERSION}", Nukkit.VERSION); content = content.replace("${JAVA_VERSION}", System.getProperty("java.vm.name") + " (" + System.getProperty("java.runtime.version") + ")"); content = content.replace("${HOSTOS}", osMXBean.getName() + "-" + osMXBean.getArch() + " [" + osMXBean.getVersion() + "]"); content = content.replace("${MEMORY}", getCount(osMXBean.getTotalPhysicalMemorySize(), true)); content = content.replace("${STORAGE_SIZE}", getCount(totalDiskSpace, true)); content = content.replace("${CPU_TYPE}", cpuType == null ? "UNKNOWN" : cpuType); content = content.replace("${AVAILABLE_CORE}", String.valueOf(osMXBean.getAvailableProcessors())); content = content.replace("${STACKTRACE}", stringWriter.toString()); content = content.replace("${PLUGIN_ERROR}", Boolean.toString(pluginError).toUpperCase()); content = content.replace("${STORAGE_TYPE}", model.toString()); Utils.writeFile(mdReport, content); return mdReport.getAbsolutePath(); }
Example 12
Source File: GetTotalSpace.java From levelup-java-examples with Apache License 2.0 | 3 votes |
@Test public void get_file_store_total_space () throws IOException { FileStore store = Files.getFileStore(source); long totalSpace = store.getTotalSpace(); assertTrue(totalSpace > 0); }
Example 13
Source File: GetUsedSpace.java From levelup-java-examples with Apache License 2.0 | 3 votes |
@Test public void get_used_space_nio () throws IOException { FileStore store = Files.getFileStore(source); long usedSpace = (store.getTotalSpace() - store.getUnallocatedSpace()) / 1024; assertTrue(usedSpace > 0); }