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


Java FileStore類代碼示例

本文整理匯總了Java中java.nio.file.FileStore的典型用法代碼示例。如果您正苦於以下問題:Java FileStore類的具體用法?Java FileStore怎麽用?Java FileStore使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FileStore類屬於java.nio.file包,在下文中一共展示了FileStore類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFileStoreType

import java.nio.file.FileStore; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:24,代碼來源:NativeCallsJNAImpl.java

示例2: areOnSameFileStore

import java.nio.file.FileStore; //導入依賴的package包/類
/**
 * 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
  }
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:25,代碼來源:DirectoryHelper.java

示例3: fillFromStorage

import java.nio.file.FileStore; //導入依賴的package包/類
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
        }
    }
}
 
開發者ID:eclipse,項目名稱:packagedrone,代碼行數:21,代碼來源:InformationController.java

示例4: showFileStoreInfo

import java.nio.file.FileStore; //導入依賴的package包/類
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();        
}
 
開發者ID:rlvillacarlos,項目名稱:cosc111,代碼行數:17,代碼來源:NIO2Test.java

示例5: testGetFileStores

import java.nio.file.FileStore; //導入依賴的package包/類
@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());
}
 
開發者ID:gredler,項目名稱:test-fs,代碼行數:18,代碼來源:TestFSTest.java

示例6: getSupportedFileAttributes

import java.nio.file.FileStore; //導入依賴的package包/類
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;
}
 
開發者ID:tinyMediaManager,項目名稱:tinyMediaManager,代碼行數:26,代碼來源:FSTest.java

示例7: 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

示例8: guessFileStore

import java.nio.file.FileStore; //導入依賴的package包/類
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;
        }
    }
}
 
開發者ID:scylladb,項目名稱:scylla-tools-java,代碼行數:19,代碼來源:DatabaseDescriptor.java

示例9: testFileStore

import java.nio.file.FileStore; //導入依賴的package包/類
@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");
}
 
開發者ID:damiencarol,項目名稱:jsr203-hadoop,代碼行數:27,代碼來源:TestFileStore.java

示例10: testFileStoreAttributes

import java.nio.file.FileStore; //導入依賴的package包/類
/**
 * 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));
}
 
開發者ID:damiencarol,項目名稱:jsr203-hadoop,代碼行數:26,代碼來源:TestFileStore.java

示例11: 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

示例12: makeWritable

import java.nio.file.FileStore; //導入依賴的package包/類
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));
    }
  }
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:17,代碼來源:ScopedTemporaryDirectory.java

示例13: addContext

import java.nio.file.FileStore; //導入依賴的package包/類
@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;
    }
}
 
開發者ID:awslabs,項目名稱:swage,代碼行數:16,代碼來源:DiskUsageSensor.java

示例14: 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

示例15: ReadOnlyAdapter

import java.nio.file.FileStore; //導入依賴的package包/類
@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;
}
 
開發者ID:cryptomator,項目名稱:fuse-nio-adapter,代碼行數:9,代碼來源:ReadOnlyAdapter.java


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