List of usage examples for java.io File getFreeSpace
public long getFreeSpace()
From source file:eu.stratosphere.nephele.instance.local.LocalInstanceManager.java
/** * Creates a default instance type based on the hardware characteristics of the machine that calls this method. The * default instance type contains the machine's number of CPU cores and size of physical memory. The disc capacity * is calculated from the free space in the directory for temporary files. * /* ww w . jav a 2 s. co m*/ * @return the default instance type used for the local machine */ public static final InstanceType createDefaultInstanceType() { final HardwareDescription hardwareDescription = HardwareDescriptionFactory.extractFromSystem(); int diskCapacityInGB = 0; final String[] tempDirs = GlobalConfiguration .getString(ConfigConstants.TASK_MANAGER_TMP_DIR_KEY, ConfigConstants.DEFAULT_TASK_MANAGER_TMP_PATH) .split(File.pathSeparator); for (final String tempDir : tempDirs) { if (tempDir != null) { File f = new File(tempDir); diskCapacityInGB = Math.max(diskCapacityInGB, (int) (f.getFreeSpace() / (1024L * 1024L * 1024L))); } } final int physicalMemory = (int) (hardwareDescription.getSizeOfPhysicalMemory() / (1024L * 1024L)); return InstanceTypeFactory.construct("default", hardwareDescription.getNumberOfCPUCores(), hardwareDescription.getNumberOfCPUCores(), physicalMemory, diskCapacityInGB, 0); }
From source file:org.benetech.secureapp.generator.BuildingApkController.java
private static void LogMemoryCheck(HttpSession session, String description, File baseBuildDir) { long totalSpace = getMegaBytes(baseBuildDir.getTotalSpace()); long freeSpace = getMegaBytes(baseBuildDir.getFreeSpace()); long usableSpace = getMegaBytes(baseBuildDir.getUsableSpace()); int processors = Runtime.getRuntime().availableProcessors(); long freeMemory = getMegaBytes(Runtime.getRuntime().freeMemory()); long maxMemory = Runtime.getRuntime().maxMemory(); String jvmMemory = (maxMemory == Long.MAX_VALUE ? "no limit" : String.valueOf(getMegaBytes(maxMemory))); long totalMemory = getMegaBytes(Runtime.getRuntime().totalMemory()); StringBuilder memoryUsed = new StringBuilder(); memoryUsed.append("MEMORY CHECK: "); memoryUsed.append(description);/*from w ww. jav a2s.co m*/ memoryUsed.append(": Processors = "); memoryUsed.append(processors); memoryUsed.append(", Total Memory = "); memoryUsed.append(totalMemory); memoryUsed.append(" MB, JVM Memory = "); memoryUsed.append(jvmMemory); memoryUsed.append(" MB, Free Memory = "); memoryUsed.append(freeMemory); memoryUsed.append(" MB -- Disk Total Space = "); memoryUsed.append(totalSpace); memoryUsed.append(" MB, Disk Usable Space = "); memoryUsed.append(usableSpace); memoryUsed.append(" MB, Disk Free Space = "); memoryUsed.append(freeSpace); memoryUsed.append(" MB."); SagLogger.logInfo(session, memoryUsed.toString()); }
From source file:com.glaf.core.util.FileUtils.java
/** * ??// w w w . ja v a2 s. c o m */ public static double getDiskPartitionSpaceUsedPercent(final String path) { if (null == path || path.isEmpty()) return -1; try { File file = new File(path); if (!file.exists()) { boolean result = file.mkdirs(); if (!result) { } } long totalSpace = file.getTotalSpace(); long freeSpace = file.getFreeSpace(); long usedSpace = totalSpace - freeSpace; if (totalSpace > 0) { return usedSpace / (double) totalSpace; } } catch (Exception e) { return -1; } return -1; }
From source file:org.deegree.tools.rendering.dem.builder.DEMDatasetGenerator.java
private static void init(CommandLine line) throws ParseException, IOException, SQLException { String t = line.getOptionValue(OPT_OUTPUT_LEVELS, "-1"); int levels = Integer.parseInt(t); t = line.getOptionValue(OPT_OUTPUT_ROWS, "128"); int rows = Integer.parseInt(t); t = line.getOptionValue(OPT_MAX_HEIGHT); float maxZ = Float.NaN; if (t != null) { maxZ = Float.parseFloat(t); }//from w w w.j a va 2 s . c o m RasterIOOptions rasterIOOptions = RasterOptionsParser.parseRasterIOOptions(line); AbstractCoverage raster = RasterOptionsParser.loadCoverage(line, rasterIOOptions); if (!(raster instanceof AbstractRaster)) { throw new IllegalArgumentException( "Given raster location is a multiresolution raster, this is not supported."); } DEMDatasetGenerator builder = new DEMDatasetGenerator((AbstractRaster) raster, rasterIOOptions, levels, rows, maxZ); t = line.getOptionValue(OPT_OUTPUT_DIR); File outputDir = new File(t); if (outputDir.getFreeSpace() < builder.fileSize) { System.err.println("Not enough space (" + outputDir.getFreeSpace() + " bytes ca: " + (Math.round((outputDir.getFreeSpace() / (1024 * 1024d)) * 100d) / 100d) + " Mb.) free in the directory: " + outputDir + " please specify a location where at least: " + builder.fileSize + " bytes (ca. " + (Math.round((builder.fileSize / (1024 * 1024d)) * 100d) / 100d) + " Mb) are available."); System.exit(2); } Blob patchesBlob = new FileBlob(new File(outputDir, MultiresolutionMesh.FRAGMENTS_FILE_NAME)); PatchManager triangleManager = new PatchManager(builder.getLevels(), patchesBlob); System.out.println(triangleManager); // generate macro triangle blob double sampleSizeX = Math.abs(builder.sampleSizeX); double sampleSizeY = Math.abs(builder.sampleSizeY); float outputExtentX = (float) (builder.outputX * sampleSizeX); float outputExtentY = (float) (builder.outputY * sampleSizeY); PatchManager manager = builder.generateMacroTriangles(triangleManager, 0, 0, outputExtentX, outputExtentY); // write mrindex blob Blob mrIndexBlob = new FileBlob(new File(outputDir, MultiresolutionMesh.INDEX_FILE_NAME)); DAGBuilder dagBuilder = new DAGBuilder(manager.getLevels(), manager); dagBuilder.writeBlob(mrIndexBlob, (short) 0, (short) rows); dagBuilder.printStats(); mrIndexBlob.free(); }
From source file:org.springframework.boot.actuate.health.DiskSpaceHealthIndicator.java
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { File path = this.properties.getPath(); long diskFreeInBytes = path.getFreeSpace(); if (diskFreeInBytes >= this.properties.getThreshold()) { builder.up();/*from w w w . j a v a2 s . com*/ } else { logger.warn( String.format("Free disk space below threshold. " + "Available: %d bytes (threshold: %d bytes)", diskFreeInBytes, this.properties.getThreshold())); builder.down(); } builder.withDetail("total", path.getTotalSpace()).withDetail("free", diskFreeInBytes) .withDetail("threshold", this.properties.getThreshold()); }
From source file:fr.gael.dhus.datastore.eviction.EvictionManager.java
/** * Computes free space on disk where the eviction works. * * @return number of available bytes on disk partition. */// www. j av a 2 s . c om public long getFreeSpace() { String path = getPath(); File fpath = new File(path); return fpath.getFreeSpace(); }
From source file:serposcope.lifecycle.DBSizeUtils.java
public long getDiskFree() { File file = getDbFile(); if (file == null) { file = new File(System.getProperty("user.dir")); if (!file.exists()) { return -1l; }/* w ww.j a v a2 s. c o m*/ } return file.getFreeSpace(); }
From source file:ctmetrics.CTmetrics.java
public CTmetrics(String[] args) { if (!parseArgs(args)) return;//w w w . j a va 2s.c om System.err.println("CTmetrics monitor: " + monitorFolder + ", output to: " + metricsSource); CTinfo.setDebug(debug); long mtimePerBlock = (long) (timePerBlock * 1000.); if (timePerSample >= timePerBlock || timePerSample == 0) timePerSample = timePerBlock; long mtimePerSample = (long) (timePerSample * 1000.); try { CTwriter ctw = new CTwriter(metricsSource, timePerLoop); ctw.setBlockMode(true, zipmode); ctw.autoSegment(blocksPerSegment); // blocks/segment ctw.autoFlush(mtimePerBlock); CTreader ctr = new CTreader(monitorFolder); File f = new File(metricsSource); // pre-make output folder to use as getSpace ref f.mkdirs(); while (true) { long freeSpace = f.getFreeSpace(); // long totalSpace = f.getTotalSpace(); ctw.setTime(System.currentTimeMillis()); // common time all samples/block // ctw.putData("UsedSpace", (totalSpace - freeSpace)); ctw.putData("FreeSpace", freeSpace); if (individualSources) { ArrayList<String> sources = ctr.listSources(); // update list every iteration if (sources.size() == 0) System.err.println("Warning: no sources found in monitorFolder: " + monitorFolder); for (String source : sources) { // {Loop by Source} String sourcePath = monitorFolder + File.separator + source; long diskSize = CTinfo.diskUsage(sourcePath, diskBlockSize); long dataSize = CTinfo.dataUsage(sourcePath); String src = source.replace(File.separator, "_"); // can't have multi-level channel name! ctw.putData(src + "_DiskUsage", diskSize); ctw.putData(src + "_DataUsage", dataSize); // System.err.println("metrics source: "+sourcePath); } } else { long diskSize = CTinfo.diskUsage(monitorFolder, diskBlockSize); long dataSize = CTinfo.dataUsage(monitorFolder); ctw.putData("DiskSpace", diskSize); ctw.putData("DataSpace", dataSize); } Thread.sleep(mtimePerSample); // one or more samples per block } } catch (Exception e) { System.err.println("CTmetrics Exception: " + e); } }
From source file:cprasmu.rascam.camera.FileSystemModel.java
public long calculateUsage() { File f = new File(initialPath); return (long) (((double) (f.getTotalSpace() - f.getFreeSpace()) / (double) f.getTotalSpace()) * 100d); }
From source file:org.luwrain.app.commander.InfoAndProperties.java
void fillLocalVolumeInfo(File file, MutableLines lines) { NullCheck.notNull(file, "file"); NullCheck.notNull(lines, "lines"); lines.addLine(": " + file.getAbsolutePath()); lines.addLine(": " + formatSize(file.getFreeSpace())); }