本文整理匯總了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));
}