本文整理匯總了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();
}