本文整理汇总了Java中java.nio.file.FileStore.getUsableSpace方法的典型用法代码示例。如果您正苦于以下问题:Java FileStore.getUsableSpace方法的具体用法?Java FileStore.getUsableSpace怎么用?Java FileStore.getUsableSpace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.FileStore
的用法示例。
在下文中一共展示了FileStore.getUsableSpace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getFreeDiskSpace
import java.nio.file.FileStore; //导入方法依赖的package包/类
/**
* Get the free disk space for a selected path.
*
* @return Free disk space in bytes.
*/
private long getFreeDiskSpace(final String strPath) {
long usableSpace = 0;
if (!strPath.isEmpty()) {
try {
Path path = Paths.get(strPath);
if (!Files.exists(path)) {
path = path.getParent();
}
final FileStore fileStore = Files.getFileStore(path);
usableSpace = fileStore.getUsableSpace();
} catch (Exception ignore) {
}
}
return usableSpace;
}
示例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: getUsableDiscSpaceInGB
import java.nio.file.FileStore; //导入方法依赖的package包/类
/**
* @return returns available disc space in GB
* @throws IOException
*
*/
public static Long getUsableDiscSpaceInGB() throws IOException {
Path path = Paths.get(System.getProperty("user.dir"));
//Retrieve the mounted file system on which vmidc files are stored
FileStore store = Files.getFileStore(path);
return store.getUsableSpace() / 1024 / 1024 / 1024;
}
示例6: getFreeSpace
import java.nio.file.FileStore; //导入方法依赖的package包/类
public long getFreeSpace() {
long freeSpace = 0;
try {
FileStore fileStore = Files.getFileStore(Paths.get("."));
freeSpace = fileStore.getUsableSpace();
} catch (IOException ioEx) {
logger.log(Level.WARNING, "Cannot calculate free/total disk space", ioEx);
}
return freeSpace;
}
示例7: getUsableSpace
import java.nio.file.FileStore; //导入方法依赖的package包/类
public long getUsableSpace() {
long result = 0;
for (FileStore store : FileSystems.getDefault().getFileStores()) {
try {
result += store.getUsableSpace();
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
示例8: getFileStores
import java.nio.file.FileStore; //导入方法依赖的package包/类
/**
* Simple test to check {@link FileStore} support.
*
* @throws IOException
*/
@Test
public void getFileStores() throws IOException {
Path pathToTest = Paths.get(clusterUri);
Iterable<FileStore> fileStores = pathToTest.getFileSystem().getFileStores();
for (FileStore store : fileStores) {
store.getUsableSpace();
assertNotNull(store.toString());
}
}
示例9: testFileStoreLimitPreventsFileCreation
import java.nio.file.FileStore; //导入方法依赖的package包/类
@Test
@Category( { FileStores.class, SizeLimit.class, Exclusive.class, Writable.class } )
public void testFileStoreLimitPreventsFileCreation() throws IOException {
FileStore store = sizeLimitedRoot().getFileSystem().provider().getFileStore( sizeLimitedRoot() );
while( store.getUsableSpace() > 20000 ) {
Files.write( sizeLimitedRoot().resolve( UUID.randomUUID().toString() ), CONTENT_BIG );
}
assertThatThrownBy( () -> Files.write( sizeLimitedRoot().resolve( UUID.randomUUID().toString() ), CONTENT_BIG ) ).
isInstanceOf( IOException.class );
}
示例10: testFileStoreLimitPreventsFileModification
import java.nio.file.FileStore; //导入方法依赖的package包/类
@Test
@Category( { FileStores.class, SizeLimit.class, Exclusive.class, Writable.class } )
public void testFileStoreLimitPreventsFileModification() throws IOException {
FileStore store = sizeLimitedRoot().getFileSystem().provider().getFileStore( sizeLimitedRoot() );
while( store.getUsableSpace() > 20000 ) {
Files.write( sizeLimitedRoot().resolve( UUID.randomUUID().toString() ), CONTENT_BIG );
}
assertThatThrownBy( () -> Files.write( fileInLimitedPlayground(), CONTENT_BIG, StandardOpenOption.APPEND ) ).
isInstanceOf( IOException.class );
}
示例11: testFileStoreLimitPreventsCopy
import java.nio.file.FileStore; //导入方法依赖的package包/类
@Test
@Category( { FileStores.class, SizeLimit.class, Exclusive.class } )
public void testFileStoreLimitPreventsCopy() throws IOException {
FileStore store = sizeLimitedRoot().getFileSystem().provider().getFileStore( sizeLimitedRoot() );
while( store.getUsableSpace() > 20000 ) {
Files.write( sizeLimitedRoot().resolve( UUID.randomUUID().toString() ), CONTENT_BIG );
}
Path target = sizeLimitedRoot().resolve( "target" );
assertThatThrownBy( () -> Files.copy( fileInLimitedPlayground(), target ) ).
isInstanceOf( IOException.class );
}
示例12: 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());
}
示例13: freeDiskBytes
import java.nio.file.FileStore; //导入方法依赖的package包/类
public long freeDiskBytes() throws IOException {
Iterable<FileStore> fileStores = localFileSystem.getFileStores();
long totalUsableSpace = 0l;
for(FileStore fs:fileStores){
totalUsableSpace+=fs.getUsableSpace();
}
return totalUsableSpace;
}
示例14: freeSpaceFormatted
import java.nio.file.FileStore; //导入方法依赖的package包/类
public static String freeSpaceFormatted(FileStore store) throws Exception {
long mb = store.getUsableSpace() / (1000*1000); // 10^6 converts to megabytes.
return mb + " mb";
}
示例15: calculateUsage
import java.nio.file.FileStore; //导入方法依赖的package包/类
protected double calculateUsage(FileStore store) throws IOException {
return 1.0 - (double) store.getUsableSpace() / (double) store.getTotalSpace();
}