本文整理汇总了Java中java.nio.file.FileStore.getTotalSpace方法的典型用法代码示例。如果您正苦于以下问题:Java FileStore.getTotalSpace方法的具体用法?Java FileStore.getTotalSpace怎么用?Java FileStore.getTotalSpace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.FileStore
的用法示例。
在下文中一共展示了FileStore.getTotalSpace方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendDiskEvent
import java.nio.file.FileStore; //导入方法依赖的package包/类
private void sendDiskEvent(Path root) {
try {
FileStore store = Files.getFileStore(root);
long totalSpace = store.getTotalSpace();
long usableSpace = store.getUsableSpace();
long unallocatedSpace = store.getUnallocatedSpace();
OsEventBuilder eventBuilder = OsEventBuilder.createDiskBuilder(this.getEventBuilderData());
eventBuilder.setDiskPath(root.toString());
eventBuilder.setTotalDiskSpace(totalSpace);
eventBuilder.setUsableDiskSpace(usableSpace);
eventBuilder.setUnallocatedDiskSpace(unallocatedSpace);
eventBuilder.setUsedDiskSpace(totalSpace - unallocatedSpace);
this.sendEvent(eventBuilder.toEvent());
} catch (Exception e) {
// ignore
}
}
示例2: addContext
import java.nio.file.FileStore; //导入方法依赖的package包/类
@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;
}
}
示例3: sense
import java.nio.file.FileStore; //导入方法依赖的package包/类
@Override
public void sense(final MetricRecorder.Context 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);
}
}
示例4: Volume
import java.nio.file.FileStore; //导入方法依赖的package包/类
/**
* A constructor to create a Volume object from a FileStore object.
*
* @param root
* @param fileStore
*/
public Volume(String root, FileStore fileStore)
{
label = fileStore.name(); //TODO VolumeLabel;
name = fileStore.name();
type = fileStore.type();
format = fileStore.type(); // TODO DriveFormat
path = root; // ex. C:\
try {
size = fileStore.getTotalSpace();
free = fileStore.getUsableSpace();
}
catch (IOException e) {
e.printStackTrace();
}
}
示例5: get
import java.nio.file.FileStore; //导入方法依赖的package包/类
@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);
}
}
示例6: getTotalSpace
import java.nio.file.FileStore; //导入方法依赖的package包/类
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;
}
示例7: freeSpace
import java.nio.file.FileStore; //导入方法依赖的package包/类
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;
}
}
示例8: getTotalSpace
import java.nio.file.FileStore; //导入方法依赖的package包/类
public long getTotalSpace() {
long result = 0;
for (FileStore store : FileSystems.getDefault().getFileStores()) {
try {
result += store.getTotalSpace();
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
示例9: getFsStat
import java.nio.file.FileStore; //导入方法依赖的package包/类
@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());
}
示例10: calculateUsage
import java.nio.file.FileStore; //导入方法依赖的package包/类
protected double calculateUsage(FileStore store) throws IOException {
return 1.0 - (double) store.getUsableSpace() / (double) store.getTotalSpace();
}
示例11: get_file_store_total_space
import java.nio.file.FileStore; //导入方法依赖的package包/类
@Test
public void get_file_store_total_space () throws IOException {
FileStore store = Files.getFileStore(source);
long totalSpace = store.getTotalSpace();
assertTrue(totalSpace > 0);
}
示例12: get_used_space_nio
import java.nio.file.FileStore; //导入方法依赖的package包/类
@Test
public void get_used_space_nio () throws IOException {
FileStore store = Files.getFileStore(source);
long usedSpace = (store.getTotalSpace() -
store.getUnallocatedSpace()) / 1024;
assertTrue(usedSpace > 0);
}