本文整理汇总了Java中java.nio.file.Files.getFileStore方法的典型用法代码示例。如果您正苦于以下问题:Java Files.getFileStore方法的具体用法?Java Files.getFileStore怎么用?Java Files.getFileStore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.Files
的用法示例。
在下文中一共展示了Files.getFileStore方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFileStoreType
import java.nio.file.Files; //导入方法依赖的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: addContext
import java.nio.file.Files; //导入方法依赖的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;
}
}
示例3: sense
import java.nio.file.Files; //导入方法依赖的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);
}
}
示例4: provideRootFileStore
import java.nio.file.Files; //导入方法依赖的package包/类
@Provides
@PerAdapter
protected FileStore provideRootFileStore() {
try {
return Files.getFileStore(root);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例5: getUsableDiscSpaceInGB
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* @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;
}
示例6: get
import java.nio.file.Files; //导入方法依赖的package包/类
@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);
}
}
示例7: MyDefHealthIndicator
import java.nio.file.Files; //导入方法依赖的package包/类
@Autowired
public MyDefHealthIndicator(
@Value("${health.filestore.path:/}") String path,
@Value("${health.filestore.threshold.bytes:10485760}") long thresholdBytes)
throws IOException {
fileStore = Files.getFileStore(Paths.get(path));
this.thresholdBytes = thresholdBytes;
}
示例8: testFileStore
import java.nio.file.Files; //导入方法依赖的package包/类
@Test
public void testFileStore() throws Exception {
Path path = Paths.get(".");
//System.out.println(path.toAbsolutePath());
FileStore fStore = Files.getFileStore(path);
//System.out.println(fStore);
}
示例9: ZipFileStoreAttributes
import java.nio.file.Files; //导入方法依赖的package包/类
public ZipFileStoreAttributes(ZipFileStore fileStore)
throws IOException
{
Path path = FileSystems.getDefault().getPath(fileStore.name());
this.size = Files.size(path);
this.fstore = Files.getFileStore(path);
}
示例10: getFileStores
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public Iterable<FileStore> getFileStores() {
FileStore store;
try {
store = Files.getFileStore(root);
} catch (IOException ioe) {
store = null;
}
return SoleIterable(store);
}
示例11: getMatchingFileStore
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Files.getFileStore(Path) useless here! Don't complain, just try it yourself.
*/
@SuppressForbidden(reason = "works around the bugs")
static FileStore getMatchingFileStore(Path path, FileStore fileStores[]) throws IOException {
if (Constants.WINDOWS) {
return getFileStoreWindows(path, fileStores);
}
final FileStore store;
try {
store = Files.getFileStore(path);
} catch (IOException unexpected) {
// give a better error message if a filestore cannot be retrieved from inside a FreeBSD jail.
if (Constants.FREE_BSD) {
throw new IOException("Unable to retrieve mount point data for " + path +
". If you are running within a jail, set enforce_statfs=1. See jail(8)", unexpected);
} else {
throw unexpected;
}
}
try {
String mount = getMountPointLinux(store);
FileStore sameMountPoint = null;
for (FileStore fs : fileStores) {
if (mount.equals(getMountPointLinux(fs))) {
if (sameMountPoint == null) {
sameMountPoint = fs;
} else {
// more than one filesystem has the same mount point; something is wrong!
// fall back to crappy one we got from Files.getFileStore
return store;
}
}
}
if (sameMountPoint != null) {
// ok, we found only one, use it:
return sameMountPoint;
} else {
// fall back to crappy one we got from Files.getFileStore
return store;
}
} catch (Exception e) {
// ignore
}
// fall back to crappy one we got from Files.getFileStore
return store;
}
示例12: getFileStore
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public FileStore getFileStore(Path file) throws IOException {
triggerEx(file, "getFileStore");
return Files.getFileStore(unwrap(file));
}