本文整理汇总了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;
}
示例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
}
}
示例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
}
}
}
示例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();
}
示例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());
}
示例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;
}
示例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
}
}
示例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;
}
}
}
示例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");
}
示例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));
}
示例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;
}
示例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));
}
}
}
示例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;
}
}
示例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);
}
}
示例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;
}