當前位置: 首頁>>代碼示例>>Java>>正文


Java FileStore.getUsableSpace方法代碼示例

本文整理匯總了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
    }
}
 
開發者ID:Indoqa,項目名稱:logspace,代碼行數:22,代碼來源:DiskAgent.java

示例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;
}
 
開發者ID:mediathekview,項目名稱:MediathekView,代碼行數:21,代碼來源:DialogAddDownload.java

示例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);
    }
}
 
開發者ID:awslabs,項目名稱:swage,代碼行數:16,代碼來源:DiskUsageSensor.java

示例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();
    }
}
 
開發者ID:ciphertechsolutions,項目名稱:IO,代碼行數:23,代碼來源:Volume.java

示例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;
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:14,代碼來源:ServerUtil.java

示例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;
}
 
開發者ID:games647,項目名稱:LagMonitor,代碼行數:12,代碼來源:NativeData.java

示例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;
}
 
開發者ID:disit,項目名稱:sce-backend,代碼行數:12,代碼來源:SchedulerLoggerStatus.java

示例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());
  }
}
 
開發者ID:damiencarol,項目名稱:jsr203-hadoop,代碼行數:16,代碼來源:TestFileSystem.java

示例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 );
}
 
開發者ID:openCage,項目名稱:niotest,代碼行數:14,代碼來源:Tests13FileStore.java

示例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 );
}
 
開發者ID:openCage,項目名稱:niotest,代碼行數:14,代碼來源:Tests13FileStore.java

示例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 );
}
 
開發者ID:openCage,項目名稱:niotest,代碼行數:16,代碼來源:Tests13FileStore.java

示例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());
}
 
開發者ID:kofemann,項目名稱:simple-nfs,代碼行數:8,代碼來源:LocalFileSystem.java

示例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;
}
 
開發者ID:splicemachine,項目名稱:spliceengine,代碼行數:9,代碼來源:FileSystemConfiguration.java

示例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";
}
 
開發者ID:a-r-d,項目名稱:java-1-class-demos,代碼行數:5,代碼來源:FileStoreBasics.java

示例15: calculateUsage

import java.nio.file.FileStore; //導入方法依賴的package包/類
protected double calculateUsage(FileStore store) throws IOException {
   return 1.0 - (double) store.getUsableSpace() / (double) store.getTotalSpace();
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:4,代碼來源:FileStoreMonitor.java


注:本文中的java.nio.file.FileStore.getUsableSpace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。