Java Code Examples for java.nio.file.FileStore#getUnallocatedSpace()

The following examples show how to use java.nio.file.FileStore#getUnallocatedSpace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalQuotaFeature.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@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);
    }
}
 
Example 2
Source File: ConfigController.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
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;
    }
}
 
Example 3
Source File: FileSystemConfiguration.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
public long unallocatedBytes() throws IOException {
    Iterable<FileStore> fileStores = localFileSystem.getFileStores();
    long totalUsableSpace = 0l;
    for(FileStore fs:fileStores){
        totalUsableSpace+=fs.getUnallocatedSpace();
    }
    return totalUsableSpace;
}
 
Example 4
Source File: GetUsedSpace.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void get_used_space_nio () throws IOException {

	FileStore store = Files.getFileStore(source);

	long usedSpace = (store.getTotalSpace() -
             store.getUnallocatedSpace()) / 1024;
	
	assertTrue(usedSpace > 0);
}