Example usage for java.nio.file FileStore getTotalSpace

List of usage examples for java.nio.file FileStore getTotalSpace

Introduction

In this page you can find the example usage for java.nio.file FileStore getTotalSpace.

Prototype

public abstract long getTotalSpace() throws IOException;

Source Link

Document

Returns the size, in bytes, of the file store.

Usage

From source file:Main.java

public static void main(String[] args) throws IOException {
    FileSystem fileSystem = FileSystems.getDefault();

    for (FileStore store : fileSystem.getFileStores()) {
        long total = store.getTotalSpace() / 1024;
        System.out.println(total);
    }//from  w w w.  j  a v a 2 s. c om
}

From source file:Test.java

public static void main(String[] args) throws Exception {
    FileSystem fileSystem = FileSystems.getDefault();

    for (FileStore fileStore : fileSystem.getFileStores()) {
        long totalSpace = fileStore.getTotalSpace() / kiloByte;
        long usedSpace = (fileStore.getTotalSpace() - fileStore.getUnallocatedSpace()) / kiloByte;
        long usableSpace = fileStore.getUsableSpace() / kiloByte;
        String name = fileStore.name();
        String type = fileStore.type();
        boolean readOnly = fileStore.isReadOnly();
    }//from   ww w . j av a  2s  . c  o  m
}

From source file:Main.java

public static void printDetails(FileStore store) {
    try {/*w w w  .  j  a  v a  2 s.  c  om*/
        String desc = store.toString();
        String type = store.type();
        long totalSpace = store.getTotalSpace();
        long unallocatedSpace = store.getUnallocatedSpace();
        long availableSpace = store.getUsableSpace();
        System.out.println(desc + ", Total: " + totalSpace + ",  Unallocated: " + unallocatedSpace
                + ",  Available: " + availableSpace);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:fr.ortolang.diffusion.store.binary.BinaryStoreServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<BinaryStoreContent> systemBrowse(String name, String prefix) throws BinaryStoreServiceException {
    if (name == null || name.length() == 0) {
        List<BinaryStoreContent> vinfos = new ArrayList<BinaryStoreContent>();
        List<String> vnames = new ArrayList<String>();
        vnames.addAll(BinaryStoreVolumeMapper.listVolumes());
        vnames.add(WORK);/* w w  w .jav  a 2  s. c  o m*/
        for (String vname : vnames) {
            try {
                BinaryStoreContent volume = new BinaryStoreContent();
                Path vpath = Paths.get(base.toString(), vname);
                FileStore vstore = Files.getFileStore(vpath);
                volume.setPath(vname);
                volume.setType(Type.VOLUME);
                volume.setFsName(vstore.name());
                volume.setFsType(vstore.type());
                volume.setFsTotalSize(vstore.getTotalSpace());
                volume.setFsFreeSize(vstore.getUsableSpace());
                volume.setSize(Files.size(vpath));
                volume.setLastModificationDate(Files.getLastModifiedTime(vpath).toMillis());
                vinfos.add(volume);
            } catch (IOException e) {
                LOGGER.log(Level.WARNING,
                        "Unable to retrieve binary store volume information for volume: " + vname);
            }
        }
        return vinfos;
    } else {
        try {
            if (prefix == null) {
                prefix = "";
            }
            Path vpath = Paths.get(base.toString(), name, prefix);
            if (!Files.exists(vpath)) {
                throw new BinaryStoreServiceException(
                        "volume name does not point to an existing file or a directory");
            }
            return Files.list(vpath).map(this::pathToContent).collect(Collectors.toList());
        } catch (IOException e) {
            throw new BinaryStoreServiceException(e);
        }
    }
}

From source file:de.blizzy.backup.backup.BackupRun.java

private void checkDiskSpaceAndRemoveOldBackups() {
    try {//from  w  ww  . j  a  v  a 2  s  .c  o  m
        FileStore store = Files.getFileStore(new File(settings.getOutputFolder()).toPath());
        long total = store.getTotalSpace();
        if (total > 0) {
            for (;;) {
                long available = store.getUsableSpace();
                if (available <= 0) {
                    break;
                }

                double avail = available * 100d / total;
                if (avail >= (100d - settings.getMaxDiskFillRate())) {
                    break;
                }

                if (!removeOldestBackup()) {
                    break;
                }

                removeUnusedFiles();
            }
        }
    } catch (IOException e) {
        // ignore
    } catch (DataAccessException e) {
        BackupPlugin.getDefault().logError("error removing oldest backup", e); //$NON-NLS-1$
        fireBackupErrorOccurred(e, BackupErrorEvent.Severity.WARNING);
    }
}