Java Code Examples for java.nio.file.Files#getFileStore()

The following examples show how to use java.nio.file.Files#getFileStore() . 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: TestFileStore.java    From jsr203-hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testFileStore() throws URISyntaxException, IOException {
  URI uri = clusterUri.resolve("/tmp/testFileStore");
  Path path = Paths.get(uri);
  if (Files.exists(path))
    Files.delete(path);
  assertFalse(Files.exists(path));
  Files.createFile(path);
  assertTrue(Files.exists(path));
  FileStore st = Files.getFileStore(path);
  assertNotNull(st);
  Assert.assertNotNull(st.name());
  Assert.assertNotNull(st.type());

  Assert.assertFalse(st.isReadOnly());

  Assert.assertNotEquals(0, st.getTotalSpace());
  Assert.assertNotEquals(0, st.getUnallocatedSpace());
  Assert.assertNotEquals(0, st.getUsableSpace());

  Assert
      .assertTrue(st.supportsFileAttributeView(BasicFileAttributeView.class));
  Assert.assertTrue(st.supportsFileAttributeView("basic"));

  st.getAttribute("test");
}
 
Example 2
Source File: InformationController.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
private void fillFromStorage ( final Map<String, Object> model )
{
    if ( this.manager != null )
    {
        final Path base = this.manager.getContext ().getBasePath ();
        try
        {
            final FileStore store = Files.getFileStore ( base );
            model.put ( "storageTotal", store.getTotalSpace () );
            model.put ( "storageFree", store.getUsableSpace () );
            model.put ( "storageUsed", store.getTotalSpace () - store.getUsableSpace () );
            model.put ( "storageName", store.name () );
        }
        catch ( final Exception e )
        {
            logger.warn ( "Failed to check storage space", e );
            // ignore
        }
    }
}
 
Example 3
Source File: RuntimeInfo.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private String sizeOfDir(String directory) {
  try {
    Path path = Paths.get(directory);
    FileStore store = Files.getFileStore(path.getRoot());
    return Utils.format("(total {}, unallocated {}, root {})", FileUtils.byteCountToDisplaySize(store.getTotalSpace()), FileUtils.byteCountToDisplaySize(store.getUnallocatedSpace()), path.getRoot());
  } catch (Exception e) {
    return "";
  }
}
 
Example 4
Source File: FaultyFileSystem.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Iterable<FileStore> getFileStores() {
    FileStore store;
    try {
        store = Files.getFileStore(root);
    } catch (IOException ioe) {
        store = null;
    }
    return SoleIterable(store);
}
 
Example 5
Source File: ZipFileStore.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public ZipFileStoreAttributes(ZipFileStore fileStore)
    throws IOException
{
    Path path = FileSystems.getDefault().getPath(fileStore.name());
    this.size = Files.size(path);
    this.fstore = Files.getFileStore(path);
}
 
Example 6
Source File: ZipFileStore.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public ZipFileStoreAttributes(ZipFileStore fileStore)
    throws IOException
{
    Path path = FileSystems.getDefault().getPath(fileStore.name());
    this.size = Files.size(path);
    this.fstore = Files.getFileStore(path);
}
 
Example 7
Source File: FaultyFileSystem.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Iterable<FileStore> getFileStores() {
    FileStore store;
    try {
        store = Files.getFileStore(root);
    } catch (IOException ioe) {
        store = null;
    }
    return SoleIterable(store);
}
 
Example 8
Source File: ZipFileStore.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public ZipFileStoreAttributes(ZipFileStore fileStore)
    throws IOException
{
    Path path = FileSystems.getDefault().getPath(fileStore.name());
    this.size = Files.size(path);
    this.fstore = Files.getFileStore(path);
}
 
Example 9
Source File: ConsensusTracker.java    From nyzoVerifier with The Unlicense 5 votes vote down vote up
private static long getUsableSpace() {

        // Ensure that the directory exists.
        rootDirectory.mkdirs();

        // Get the usable space.
        long freeSpace = 0L;
        Path path = Paths.get(rootDirectory.getAbsolutePath());
        try {
            FileStore store = Files.getFileStore(path);
            freeSpace = store.getUsableSpace();
        } catch (Exception ignored) { }

        return freeSpace;
    }
 
Example 10
Source File: IndexFetcher.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private static Long getUsableSpace(String dir) {
  try {
    File file = new File(dir);
    if (!file.exists()) {
      file = file.getParentFile();
      if (!file.exists()) {//this is not a disk directory . so just pretend that there is enough space
        return Long.MAX_VALUE;
      }
    }
    FileStore fileStore = Files.getFileStore(file.toPath());
    return fileStore.getUsableSpace();
  } catch (IOException e) {
    throw new SolrException(ErrorCode.SERVER_ERROR, "Could not free disk space", e);
  }
}
 
Example 11
Source File: MCRMediaSourceProvider.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
private static String getContentPath(String derivateId, String path) {
    try {
        MCRPath mcrPath = MCRPath.getPath(derivateId, path);
        MCRAbstractFileStore fileStore = (MCRAbstractFileStore) Files.getFileStore(mcrPath);
        java.nio.file.Path absolutePath = fileStore.getPhysicalPath(mcrPath);
        java.nio.file.Path relativePath = fileStore.getBaseDirectory().relativize(absolutePath);
        LogManager.getLogger().info("{} -> {} -> {}", mcrPath, absolutePath, relativePath);
        return relativePath.toString();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 12
Source File: NativeManager.java    From LagMonitor with MIT License 5 votes vote down vote up
public long getTotalSpace() {
    long totalSpace = 0;
    try {
        FileStore fileStore = Files.getFileStore(Paths.get("."));
        totalSpace = fileStore.getTotalSpace();
    } catch (IOException ioEx) {
        logger.log(Level.WARNING, "Cannot calculate free disk space", ioEx);
    }

    return totalSpace;
}
 
Example 13
Source File: TestFileStore.java    From jsr203-hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testHadoopFileStoreAttributeView() throws IOException {
  URI uri = clusterUri.resolve("/tmp/testFileStore");
  Path path = Paths.get(uri);
  if (Files.exists(path))
    Files.delete(path);
  assertFalse(Files.exists(path));
  Files.createFile(path);
  assertTrue(Files.exists(path));
  FileStore store1 = Files.getFileStore(path);
  assertNotNull(store1);

  Assert.assertNull(
      store1.getFileStoreAttributeView(FakeFileStoreAttributeView.class));
}
 
Example 14
Source File: TestFileSystem.java    From jsr203-hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testFileStore() throws URISyntaxException, IOException {
  URI uri = clusterUri.resolve("/tmp/testFileStore");
  Path path = Paths.get(uri);
  if (Files.exists(path))
    Files.delete(path);
  assertFalse(Files.exists(path));
  Files.createFile(path);
  assertTrue(Files.exists(path));
  FileStore st = Files.getFileStore(path);
  assertNotNull(st);
}
 
Example 15
Source File: FaultyFileSystem.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public FileStore getFileStore(Path file) throws IOException {
    triggerEx(file, "getFileStore");
    return Files.getFileStore(unwrap(file));
}
 
Example 16
Source File: FaultyFileSystem.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public FileStore getFileStore(Path file) throws IOException {
    triggerEx(file, "getFileStore");
    return Files.getFileStore(unwrap(file));
}
 
Example 17
Source File: FaultyFileSystem.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public FileStore getFileStore(Path file) throws IOException {
    triggerEx(file, "getFileStore");
    return Files.getFileStore(unwrap(file));
}
 
Example 18
Source File: Environment.java    From crate with Apache License 2.0 4 votes vote down vote up
public static FileStore getFileStore(final Path path) throws IOException {
    return new ESFileStore(Files.getFileStore(path));
}
 
Example 19
Source File: FaultyFileSystem.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public FileStore getFileStore(Path file) throws IOException {
    triggerEx(file, "getFileStore");
    return Files.getFileStore(unwrap(file));
}
 
Example 20
Source File: GetAvailableSpace.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void get_available_space_nio () throws IOException {

	FileStore store = Files.getFileStore(source);

	long availableSpace = store.getUsableSpace() / 1024;
	
	assertTrue(availableSpace > 0);
}