本文整理汇总了Java中java.io.File.getUsableSpace方法的典型用法代码示例。如果您正苦于以下问题:Java File.getUsableSpace方法的具体用法?Java File.getUsableSpace怎么用?Java File.getUsableSpace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.File
的用法示例。
在下文中一共展示了File.getUsableSpace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBundleStorage
import java.io.File; //导入方法依赖的package包/类
private static File createBundleStorage(String bundleName){
if(new File(STORAGE_LOCATION).getUsableSpace()>10*1024*1024){
return new File(STORAGE_LOCATION,bundleName);
}else{
File externalStorageDir = null;
File[] externalStorages = getExternalFilesDirs(RuntimeVariables.androidApplication,"storage");
if(externalStorages!=null && externalStorages.length>0){
for(File tmpDir : externalStorages){
if(tmpDir!=null && getStorageState(tmpDir).equals(Environment.MEDIA_MOUNTED) && tmpDir.getUsableSpace()>20*1024*1024) {
externalStorageDir = tmpDir;
break;
}
}
}
if(externalStorageDir!=null){
return new File(externalStorageDir,bundleName);
}
}
return new File(STORAGE_LOCATION,bundleName);
}
示例2: compareZeroExist
import java.io.File; //导入方法依赖的package包/类
private static void compareZeroExist() {
try {
File f = File.createTempFile("tmp", null, new File("."));
long [] s = { f.getTotalSpace(), f.getFreeSpace(), f.getUsableSpace() };
for (int i = 0; i < s.length; i++) {
if (s[i] == 0L)
fail(f.getName(), s[i], "==", 0L);
else
pass();
}
} catch (IOException x) {
fail("Couldn't create temp file for test");
}
}
示例3: setGoodDirsDiskUtilizationPercentage
import java.io.File; //导入方法依赖的package包/类
private void setGoodDirsDiskUtilizationPercentage() {
long totalSpace = 0;
long usableSpace = 0;
for (String dir : localDirs) {
File f = new File(dir);
if (!f.isDirectory()) {
continue;
}
totalSpace += f.getTotalSpace();
usableSpace += f.getUsableSpace();
}
if (totalSpace != 0) {
long tmp = ((totalSpace - usableSpace) * 100) / totalSpace;
if (Integer.MIN_VALUE < tmp && Integer.MAX_VALUE > tmp) {
goodDirsDiskUtilizationPercentage = (int) tmp;
}
} else {
// got no good dirs
goodDirsDiskUtilizationPercentage = 0;
}
}
示例4: getUsableSpace
import java.io.File; //导入方法依赖的package包/类
/**
* Check how much usable space is available at a given path.
*
* @param path The path to check
* @return The space available in bytes
*/
@TargetApi(VERSION_CODES.GINGERBREAD)
public static long getUsableSpace(File path) {
if (Utils.hasGingerbread()) {
return path.getUsableSpace();
}
final StatFs stats = new StatFs(path.getPath());
return stats.getBlockSizeLong() * stats.getAvailableBlocksLong();
}
示例5: getUsableSpace
import java.io.File; //导入方法依赖的package包/类
public static long getUsableSpace(File path) {
if (path == null) {
return -1;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
return path.getUsableSpace()/1024/1024;
} else {
if (!path.exists()) {
return 0;
} else {
final StatFs stats = new StatFs(path.getPath());
return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks()/1024/1024;
}
}
}
示例6: compare
import java.io.File; //导入方法依赖的package包/类
private static void compare(Space s) {
File f = new File(s.name());
long ts = f.getTotalSpace();
long fs = f.getFreeSpace();
long us = f.getUsableSpace();
out.format("%s:%n", s.name());
String fmt = " %-4s total= %12d free = %12d usable = %12d%n";
out.format(fmt, "df", s.total(), 0, s.free());
out.format(fmt, "getX", ts, fs, us);
// if the file system can dynamically change size, this check will fail
if (ts != s.total())
fail(s.name(), s.total(), "!=", ts);
else
pass();
// unix df returns statvfs.f_bavail
long tsp = (!name.startsWith("Windows") ? us : fs);
if (!s.woomFree(tsp))
fail(s.name(), s.free(), "??", tsp);
else
pass();
if (fs > s.total())
fail(s.name(), s.total(), ">", fs);
else
pass();
if (us > s.total())
fail(s.name(), s.total(), ">", us);
else
pass();
}
示例7: getUsableSpace
import java.io.File; //导入方法依赖的package包/类
/**
* Check how much usable space is available at a given path.
*
* @param path The path to check
* @return The space available in bytes
*/
@TargetApi(VERSION_CODES.GINGERBREAD)
public static long getUsableSpace(File path) {
if (Utils.hasGingerbread()) {
return path.getUsableSpace();
}
final StatFs stats = new StatFs(path.getPath());
return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
}
示例8: getUsableSpace
import java.io.File; //导入方法依赖的package包/类
private long getUsableSpace() {
long usableSpace = 0;
try {
File file = new File(this.path);
usableSpace = file.getUsableSpace();
} catch (Exception e) {
logger.error("E_check {}", type, e);
}
return usableSpace;
}
示例9: getFTPInfo
import java.io.File; //导入方法依赖的package包/类
/**
* 获取FTP信息
*
* @return FTP信息
* @throws FtpException FTP异常
*/
public FTPInfo getFTPInfo() throws FtpException {
User userInfo = um.getUserByName(um.getAdminName());
TransferRateRequest transferRateRequest = (TransferRateRequest) userInfo
.authorize(new TransferRateRequest());
File homeDir = Paths.get(userInfo.getHomeDirectory()).toFile();
long totalSpace = homeDir.getTotalSpace();
long usedSpace = totalSpace - homeDir.getUsableSpace();
return new FTPInfo(host, port, homeDir.getAbsolutePath(),
transferRateRequest.getMaxDownloadRate() / 1024,
transferRateRequest.getMaxUploadRate() / 1024,
usedSpace, totalSpace);
}
示例10: getUsableSpace
import java.io.File; //导入方法依赖的package包/类
/**
* get available space
* @author leibing
* @createTime 2017/3/2
* @lastModify 2017/3/2
* @param path
* @return
*/
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static long getUsableSpace(File path) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
return path.getUsableSpace();
}
final StatFs stats = new StatFs(path.getPath());
return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
}
示例11: isDiskUsageOverPercentageLimit
import java.io.File; //导入方法依赖的package包/类
private boolean isDiskUsageOverPercentageLimit(File dir) {
float freePercentage =
100 * (dir.getUsableSpace() / (float) dir.getTotalSpace());
float usedPercentage = 100.0F - freePercentage;
return (usedPercentage > diskUtilizationPercentageCutoff
|| usedPercentage >= 100.0F);
}
示例12: getStatus
import java.io.File; //导入方法依赖的package包/类
/**
* Method to return status of the firewall.
* Status can be retrieved over REST API.
*
*/
public static String getStatus() {
String s = "";
s += "Jetty Server Status = " + jettyServer.getState() + "\n";
s += "Jetty Date = " + jettyServer.getDateField().toString() + "\n";
s += "Jetty URI = " + jettyServer.getURI().toString() + "\n";
s += "\n";
s += "SCTP Associations\n";
for (Map.Entry<String, Association> a : sctpManagement.getAssociations().entrySet()) {
s += " Name = " + a.getKey() + "\n";
s += " Details = " + a.getValue().toString() + "\n";
s += " isStarted = " + a.getValue().isStarted() + "\n";
s += " isConnected = " + a.getValue().isConnected() + "\n";
}
s += "\n";
s += "SCTP Servers = " + sctpManagement.getServers().toString() + "\n";
s += "\n";
s += "OS statistics\n";
s += " Available processors (cores): " + Runtime.getRuntime().availableProcessors() + "\n";
s += " Free memory (bytes): " + Runtime.getRuntime().freeMemory() + "\n";
long maxMemory = Runtime.getRuntime().maxMemory();
s += " Maximum memory (bytes): " + (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory) + "\n";
s += " Total memory available to JVM (bytes): " + Runtime.getRuntime().totalMemory() + "\n";
File[] roots = File.listRoots();
/* For each filesystem root, print some info */
for (File root : roots) {
s += " File system root: " + root.getAbsolutePath() + "\n";
s += " Total space (bytes): " + root.getTotalSpace() + "\n";
s += " Free space (bytes): " + root.getFreeSpace() + "\n";
s += " Usable space (bytes): " + root.getUsableSpace() + "\n";
}
s += "\n";
s += "Network interfaces\n";
try {
Enumeration<NetworkInterface> nets;
nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(nets)) {
s += " Display name: " + netint.getDisplayName() + "\n";
s += " Name: " + netint.getName() + "\n";
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
for (InetAddress inetAddress : Collections.list(inetAddresses)) {
s += " InetAddress: " + inetAddress + "\n";
}
}
} catch (SocketException ex) {
java.util.logging.Logger.getLogger(DiameterFirewall.class.getName()).log(Level.SEVERE, null, ex);
}
return s;
}
示例13: getUsableSpace
import java.io.File; //导入方法依赖的package包/类
private long getUsableSpace(File path) {
return path.getUsableSpace();
}
示例14: CachedFSUsableSpace
import java.io.File; //导入方法依赖的package包/类
CachedFSUsableSpace(File fs, long interval) {
this.fs = fs;
this.interval = interval;
this.value = new AtomicLong(fs.getUsableSpace());
this.lastRefresh = new AtomicLong(System.currentTimeMillis());
}
示例15: testGetFullDirs
import java.io.File; //导入方法依赖的package包/类
@Test
public void testGetFullDirs() throws Exception {
Configuration conf = new YarnConfiguration();
conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, "077");
FileContext localFs = FileContext.getLocalFSFileContext(conf);
String localDir1 = new File(testDir, "localDir1").getPath();
String localDir2 = new File(testDir, "localDir2").getPath();
String logDir1 = new File(testDir, "logDir1").getPath();
String logDir2 = new File(testDir, "logDir2").getPath();
Path localDir1Path = new Path(localDir1);
Path logDir1Path = new Path(logDir1);
FsPermission dirPermissions = new FsPermission((short) 0410);
localFs.mkdir(localDir1Path, dirPermissions, true);
localFs.mkdir(logDir1Path, dirPermissions, true);
conf.set(YarnConfiguration.NM_LOCAL_DIRS, localDir1 + "," + localDir2);
conf.set(YarnConfiguration.NM_LOG_DIRS, logDir1 + "," + logDir2);
conf.setFloat(YarnConfiguration.NM_MAX_PER_DISK_UTILIZATION_PERCENTAGE,
0.0f);
NodeManagerMetrics nm = NodeManagerMetrics.create();
LocalDirsHandlerService dirSvc = new LocalDirsHandlerService(nm);
dirSvc.init(conf);
Assert.assertEquals(0, dirSvc.getLocalDirs().size());
Assert.assertEquals(0, dirSvc.getLogDirs().size());
Assert.assertEquals(1, dirSvc.getDiskFullLocalDirs().size());
Assert.assertEquals(1, dirSvc.getDiskFullLogDirs().size());
// check the metrics
Assert.assertEquals(2, nm.getBadLocalDirs());
Assert.assertEquals(2, nm.getBadLogDirs());
Assert.assertEquals(0, nm.getGoodLocalDirsDiskUtilizationPerc());
Assert.assertEquals(0, nm.getGoodLogDirsDiskUtilizationPerc());
conf.setFloat(YarnConfiguration.NM_MAX_PER_DISK_UTILIZATION_PERCENTAGE,
100.0f);
nm = NodeManagerMetrics.create();
dirSvc = new LocalDirsHandlerService(nm);
dirSvc.init(conf);
Assert.assertEquals(1, dirSvc.getLocalDirs().size());
Assert.assertEquals(1, dirSvc.getLogDirs().size());
Assert.assertEquals(0, dirSvc.getDiskFullLocalDirs().size());
Assert.assertEquals(0, dirSvc.getDiskFullLogDirs().size());
// check the metrics
File dir = new File(localDir1);
int utilizationPerc =
(int) ((dir.getTotalSpace() - dir.getUsableSpace()) * 100 /
dir.getTotalSpace());
Assert.assertEquals(1, nm.getBadLocalDirs());
Assert.assertEquals(1, nm.getBadLogDirs());
Assert.assertEquals(utilizationPerc,
nm.getGoodLocalDirsDiskUtilizationPerc());
Assert
.assertEquals(utilizationPerc, nm.getGoodLogDirsDiskUtilizationPerc());
FileUtils.deleteDirectory(new File(localDir1));
FileUtils.deleteDirectory(new File(localDir2));
FileUtils.deleteDirectory(new File(logDir1));
FileUtils.deleteDirectory(new File(logDir1));
dirSvc.close();
}