Java 类java.nio.file.FileStore 实例源码

项目:monarch    文件:NativeCallsJNAImpl.java   
/**
 * Get the file store type of a path. for example, /dev/sdd1(store name) /w2-gst-dev40d(mount
 * point) ext4(type)
 * 
 * @param path
 * @return file store type
 */
public String getFileStoreType(final String path) {
  File diskFile = new File(path);
  if (!diskFile.exists()) {
    diskFile = diskFile.getParentFile();
  }
  Path currentPath = diskFile.toPath();
  if (currentPath.isAbsolute() && Files.exists(currentPath)) {
    try {
      FileStore store = Files.getFileStore(currentPath);
      return store.type();
    } catch (IOException e) {
      return null;
    }
  }
  return null;
}
项目:IO    文件:Volume.java   
/**
 * 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();
    }
}
项目:Elasticsearch    文件:ESFileStore.java   
@SuppressForbidden(reason = "tries to determine if disk is spinning")
// TODO: move PathUtils to be package-private here instead of 
// public+forbidden api!
ESFileStore(FileStore in) {
    this.in = in;
    Boolean spins;
    // Lucene's IOUtils.spins only works on Linux today:
    if (Constants.LINUX) {
        try {
            spins = IOUtils.spins(PathUtils.get(getMountPointLinux(in)));
        } catch (Exception e) {
            spins = null;
        }
    } else {
        spins = null;
    }
    this.spins = spins;
}
项目:java-1-class-demos    文件:FileStoreBasics.java   
public static void main(String[] args) throws Exception {

        /**
         * 
         * A FileSystem object encapsulates the fi le storage system on your computer. What this
            storage system consists of and how it is organized depends on the operating system you are using.
         */
        FileSystem fileSystem = FileSystems.getDefault();
        Iterable<FileStore> stores = fileSystem.getFileStores();

        for(FileStore store : stores) {
            System.out.println(store.name() + ": " + store.type());
            System.out.println("    -> free space: " + freeSpaceFormatted(store));
        }

    }
项目:harahachibu    文件:SolrDiskSpaceCheckerTest.java   
@Test
public void returnsResultFromThreshold() throws Exception {
    final long freeSpace = 128L;
    final long maxSpace = 1024L;

    FileStore fs = mock(FileStore.class);
    when(fs.getUsableSpace()).thenReturn(freeSpace);
    when(fs.getTotalSpace()).thenReturn(maxSpace);
    checker.setFileStore(fs);

    when(threshold.withinThreshold(freeSpace, maxSpace)).thenReturn(false);

    boolean result = checker.isSpaceAvailable();
    assertThat(result).isFalse();

    verify(fs).getUsableSpace();
    verify(fs).getTotalSpace();
    verify(threshold).withinThreshold(freeSpace, maxSpace);
}
项目:nexus-public    文件:DirectoryHelper.java   
/**
 * Return {@code true} if paths {@code from} and {@code to} are located on same FileStore (volume or
 * partition). The {@code from} must exists, while {@code to} does not have to.
 */
private static boolean areOnSameFileStore(final Path from, final Path to) {
  try {
    final FileStore fromStore = Files.getFileStore(from); // from must exist
    Path toExistingParent = to.normalize(); // to usually does not exists, is about to be created as part of move
    while (toExistingParent != null && !Files.exists(toExistingParent)) {
      toExistingParent = toExistingParent.getParent();
    }
    if (toExistingParent != null) {
      final FileStore toStore = Files.getFileStore(toExistingParent);
      return fromStore.equals(toStore);
    }
    else {
      log.warn("No ultimate parent path found for '{}'", to, new RuntimeException("marker")); // record the stack trace?
      return false; // no ultimate parent? be on safe side
    }
  }
  catch (IOException e) {
    return false; // be on safe side
  }
}
项目:packagedrone    文件:InformationController.java   
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
        }
    }
}
项目:cosc111    文件:NIO2Test.java   
private static void showFileStoreInfo() throws IOException{
    Iterable<FileStore> fs = fsys.getFileStores();
    System.out.println("Available File Stores");        
    for(FileStore f:fs){            
        System.out.println("\t" + f);
        System.out.println("\t\tType: " + f.type());
        System.out.println("\t\tRead-only: " + f.isReadOnly());
        System.out.println("\t\tTotal Space: " + 
                                (f.getTotalSpace()) + " bytes");
        System.out.println("\t\tUsable Space: " + 
                                f.getUsableSpace() + " bytes");
        System.out.println("\t\tUnallocated Space: " + 
                                f.getUnallocatedSpace() + " bytes");                      
    }
    System.out.println();        
}
项目:test-fs    文件:TestFSTest.java   
@Test
public void testGetFileStores() {

    FileSystem fs = new TestFS().create();

    Iterator< FileStore > defaultStores = DEFAULT_FS.getFileStores().iterator();
    Iterator< FileStore > testStores = fs.getFileStores().iterator();

    while (defaultStores.hasNext() && testStores.hasNext()) {
        FileStore defaultStore = defaultStores.next();
        FileStore testStore = testStores.next();
        assertEquals(defaultStore.name(), testStore.name());
    }

    assertFalse(defaultStores.hasNext());
    assertFalse(testStores.hasNext());
}
项目:tinyMediaManager    文件:FSTest.java   
private Set<String> getSupportedFileAttributes(FileStore fs) {
  Set<String> attrs = new HashSet<String>();
  if (fs.supportsFileAttributeView(AclFileAttributeView.class)) {
    attrs.add("acl");
  }
  if (fs.supportsFileAttributeView(BasicFileAttributeView.class)) {
    attrs.add("basic");
  }
  if (fs.supportsFileAttributeView(FileOwnerAttributeView.class)) {
    attrs.add("owner");
  }
  if (fs.supportsFileAttributeView(UserDefinedFileAttributeView.class)) {
    attrs.add("user");
  }
  if (fs.supportsFileAttributeView(DosFileAttributeView.class)) {
    attrs.add("dos");
  }
  if (fs.supportsFileAttributeView(PosixFileAttributeView.class)) {
    attrs.add("posix");
  }
  if (fs.supportsFileAttributeView(FileAttributeView.class)) {
    attrs.add("file");
  }
  return attrs;
}
项目:logspace    文件:DiskAgent.java   
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
    }
}
项目:scylla-tools-java    文件:DatabaseDescriptor.java   
private static FileStore guessFileStore(String dir) throws IOException
{
    Path path = Paths.get(dir);
    while (true)
    {
        try
        {
            return Files.getFileStore(path);
        }
        catch (IOException e)
        {
            if (e instanceof NoSuchFileException)
                path = path.getParent();
            else
                throw e;
        }
    }
}
项目:package-drone    文件:InformationController.java   
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
        }
    }
}
项目:jsr203-hadoop    文件:TestFileStore.java   
@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");
}
项目:jsr203-hadoop    文件:TestFileStore.java   
/**
 * Test: File and FileStore attributes
 */
@Test
public void testFileStoreAttributes() 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 store1 = Files.getFileStore(path);
  assertNotNull(store1);
  assertTrue(store1.supportsFileAttributeView("basic"));
  assertTrue(store1.supportsFileAttributeView(BasicFileAttributeView.class));
  assertTrue(store1.supportsFileAttributeView("posix") == store1
      .supportsFileAttributeView(PosixFileAttributeView.class));
  assertTrue(store1.supportsFileAttributeView("dos") == store1
      .supportsFileAttributeView(DosFileAttributeView.class));
  assertTrue(store1.supportsFileAttributeView("acl") == store1
      .supportsFileAttributeView(AclFileAttributeView.class));
  assertTrue(store1.supportsFileAttributeView("user") == store1
      .supportsFileAttributeView(UserDefinedFileAttributeView.class));
}
项目:MediathekView    文件:DialogAddDownload.java   
/**
 * 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;
}
项目:bazel    文件:ScopedTemporaryDirectory.java   
private void makeWritable(Path file) throws IOException {
  FileStore fileStore = Files.getFileStore(file);
  if (IS_WINDOWS && fileStore.supportsFileAttributeView(DosFileAttributeView.class)) {
    DosFileAttributeView dosAttribs =
        Files.getFileAttributeView(file, DosFileAttributeView.class);
    if (dosAttribs != null) {
      dosAttribs.setReadOnly(false);
    }
  } else if (fileStore.supportsFileAttributeView(PosixFileAttributeView.class)) {
    PosixFileAttributeView posixAttribs =
        Files.getFileAttributeView(file, PosixFileAttributeView.class);
    if (posixAttribs != null) {
      posixAttribs.setPermissions(EnumSet.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE));
    }
  }
}
项目:swage    文件:DiskUsageSensor.java   
@Override
public TypedMap addContext(final TypedMap existing)
{
    try {
        // Determine the file store for the directory the JVM was started in
        FileStore fileStore = Files.getFileStore(Paths.get(System.getProperty("user.dir")));

        long size = fileStore.getTotalSpace();
        long gb_size = size/(K*K*K);
        return ImmutableTypedMap.Builder.from(existing).add(DISK_SIZE, Long.valueOf(gb_size)).build();
    } catch (IOException e) {
        // log?
        return existing;
    }
}
项目:swage    文件:DiskUsageSensor.java   
@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);
    }
}
项目:fuse-nio-adapter    文件:ReadOnlyAdapter.java   
@Inject
public ReadOnlyAdapter(@Named("root") Path root, FileStore fileStore, ReadOnlyDirectoryHandler dirHandler, ReadOnlyFileHandler fileHandler, FileAttributesUtil attrUtil) {
    this.root = root;
    this.fileStore = fileStore;
    this.dirHandler = dirHandler;
    this.fileHandler = fileHandler;
    this.attrUtil = attrUtil;
}
项目:fuse-nio-adapter    文件:ReadWriteAdapter.java   
@Inject
public ReadWriteAdapter(@Named("root") Path root, FileStore fileStore, ReadWriteDirectoryHandler dirHandler, ReadWriteFileHandler fileHandler, FileAttributesUtil attrUtil, BitMaskEnumUtil bitMaskUtil) {
    super(root, fileStore, dirHandler, fileHandler, attrUtil);
    this.fileHandler = fileHandler;
    this.attrUtil = attrUtil;
    this.bitMaskUtil = bitMaskUtil;
}
项目:fuse-nio-adapter    文件:FuseNioAdapterModule.java   
@Provides
@PerAdapter
protected FileStore provideRootFileStore() {
    try {
        return Files.getFileStore(root);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:elasticsearch_my    文件:ESFileStore.java   
private static String getMountPointLinux(FileStore store) {
    String desc = store.toString();
    int index = desc.lastIndexOf(" (");
    if (index != -1) {
        return desc.substring(0, index);
    } else {
        return desc;
    }
}
项目:elasticsearch_my    文件:ESFileStoreTests.java   
public void testNegativeSpace() throws Exception {
    FileStore mocked = mock(FileStore.class);
    when(mocked.getUsableSpace()).thenReturn(-1L);
    when(mocked.getTotalSpace()).thenReturn(-1L);
    when(mocked.getUnallocatedSpace()).thenReturn(-1L);
    assertEquals(-1, mocked.getUsableSpace());
    FileStore store = new ESFileStore(mocked);
    assertEquals(Long.MAX_VALUE, store.getUsableSpace());
    assertEquals(Long.MAX_VALUE, store.getTotalSpace());
    assertEquals(Long.MAX_VALUE, store.getUnallocatedSpace());
}
项目:elasticsearch_my    文件:NewPathForShardTests.java   
@Override
public FileStore getFileStore(Path path) throws IOException {
    if (path.toString().contains(aPathPart)) {
        return aFileStore;
    } else {
        return bFileStore;
    }
}
项目:osc-core    文件:ServerUtil.java   
/**
 * @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;
}
项目:cyberduck    文件:LocalQuotaFeature.java   
@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);
    }
}
项目:rs-aggregator    文件:PathFinderTest.java   
@Test
public void testFileStore() throws Exception {
  Path path = Paths.get(".");
  //System.out.println(path.toAbsolutePath());
  FileStore fStore = Files.getFileStore(path);
  //System.out.println(fStore);
}
项目:Elasticsearch    文件:ESFileStore.java   
private static String getMountPointLinux(FileStore store) {
    String desc = store.toString();
    int index = desc.lastIndexOf(" (");
    if (index != -1) {
        return desc.substring(0, index);
    } else {
        return desc;
    }
}
项目:jdk8u-jdk    文件:FaultyFileSystem.java   
@Override
public Iterable<FileStore> getFileStores() {
    FileStore store;
    try {
        store = Files.getFileStore(root);
    } catch (IOException ioe) {
        store = null;
    }
    return SoleIterable(store);
}
项目:openjdk-jdk10    文件:Basic.java   
static void checkFileStores(FileSystem fs) throws IOException {
    // sanity check method
    if (FileUtils.areFileSystemsAccessible()) {
        System.out.println("\n--- Begin FileStores ---");
        for (FileStore store: fs.getFileStores()) {
            System.out.println(store);
        }
        System.out.println("--- EndFileStores ---\n");
    } else {
        System.err.println
            ("Skipping FileStore check due to file system access failure");
    }
}
项目:openjdk-jdk10    文件:FaultyFileSystem.java   
@Override
public Iterable<FileStore> getFileStores() {
    FileStore store;
    try {
        store = Files.getFileStore(root);
    } catch (IOException ioe) {
        store = null;
    }
    return SoleIterable(store);
}
项目:openjdk9    文件:FaultyFileSystem.java   
@Override
public Iterable<FileStore> getFileStores() {
    FileStore store;
    try {
        store = Files.getFileStore(root);
    } catch (IOException ioe) {
        store = null;
    }
    return SoleIterable(store);
}
项目:filesystem    文件:AbstractPath.java   
public final FileStore getFileStore()
        throws IOException
{
    // each ZipFileSystem only has one root (as requested for now)
    if( exists() ) {
        return fs.createFileStore( (P) this );
    }
    throw new NoSuchFileException( String.valueOf( path ) );
}
项目:filesystem    文件:AbstractFileSystem.java   
@Override
public Iterable<FileStore> getFileStores()
{
    ArrayList<FileStore> list = new ArrayList<>( 1 );
    list.add( createFileStore( createPath( new char[]{
        '/'
    } ) ) );
    return list;
}
项目:awsdownload    文件:Utilities.java   
private static boolean isPosixFileSystem() {
    if (supportsPosix == null) {
        supportsPosix = Boolean.FALSE;
        FileSystem fileSystem = FileSystems.getDefault();
        Iterable<FileStore> fileStores = fileSystem.getFileStores();
        for (FileStore fs : fileStores) {
            supportsPosix = fs.supportsFileAttributeView(PosixFileAttributeView.class);
            if (supportsPosix) {
                break;
            }
        }
    }
    return supportsPosix;
}
项目:mycore    文件:MCRIView2Tools.java   
public static String getFilePath(String derID, String derPath) throws IOException {
    MCRPath mcrPath = MCRPath.getPath(derID, derPath);
    Path physicalPath = mcrPath.toPhysicalPath();
    for (FileStore fs : mcrPath.getFileSystem().getFileStores()) {
        if (fs instanceof MCRAbstractFileStore) {
            Path basePath = ((MCRAbstractFileStore) fs).getBaseDirectory();
            if (physicalPath.startsWith(basePath)) {
                return basePath.relativize(physicalPath).toString();
            }
        }
    }
    return physicalPath.toString();
}
项目:mycore    文件:MCRPath.java   
public Path toPhysicalPath() throws IOException {
    if (isAbsolute()) {
        for (FileStore fs : getFileSystem().getFileStores()) {
            if (fs instanceof MCRAbstractFileStore) {
                Path physicalPath = ((MCRAbstractFileStore) fs).getPhysicalPath(this);
                if (physicalPath != null) {
                    return physicalPath;
                }
            }
        }
        return null;
    }
    throw new IOException("Cannot get real path from relative path.");
}
项目:mycore    文件:MCRIFSFileSystem.java   
@Override
public Iterable<FileStore> getFileStores() {
    return MCRContentStoreFactory
        .getAvailableStores()
        .keySet()
        .stream()
        .map(MCRIFSFileSystem::getFileStore)::iterator;
}
项目:mycore    文件:MCRIFSFileSystem.java   
private static FileStore getFileStore(String id) {
    try {
        return MCRFileStore.getInstance(id);
    } catch (IOException e) {
        throw new MCRException(e);
    }
}