本文整理汇总了Java中oshi.software.os.OSFileStore.getTotalSpace方法的典型用法代码示例。如果您正苦于以下问题:Java OSFileStore.getTotalSpace方法的具体用法?Java OSFileStore.getTotalSpace怎么用?Java OSFileStore.getTotalSpace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oshi.software.os.OSFileStore
的用法示例。
在下文中一共展示了OSFileStore.getTotalSpace方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printFileSystem
import oshi.software.os.OSFileStore; //导入方法依赖的package包/类
/**
* Prints the file system.
*
* @param fileSystem the file system
*/
private static void printFileSystem(FileSystem fileSystem) {
oshi.add("File System:");
oshi.add(String.format(" File Descriptors: %d/%d%n", fileSystem.getOpenFileDescriptors(),
fileSystem.getMaxFileDescriptors()));
OSFileStore[] fsArray = fileSystem.getFileStores();
for (OSFileStore fs : fsArray) {
long usable = fs.getUsableSpace();
long total = fs.getTotalSpace();
oshi.add(String.format(" %s (%s) [%s] %s of %s free (%.1f%%) is %s and is mounted at %s%n",
fs.getName(), fs.getDescription().isEmpty() ? "file system" : fs.getDescription(),
fs.getType(), FormatUtil.formatBytes(usable), FormatUtil.formatBytes(fs.getTotalSpace()),
100d * usable / total, fs.getVolume(), fs.getMount()));
}
}
示例2: getFileStores
import oshi.software.os.OSFileStore; //导入方法依赖的package包/类
@Test
public void getFileStores() {
OshiPlatformCache oshi = newOshiPlatformCache();
Map<String, OSFileStore> filestores = oshi.getFileStores();
Assert.assertNotNull(filestores);
int i = 0;
for (OSFileStore filestore : filestores.values()) {
String name = filestore.getName();
String description = filestore.getDescription();
long usableSpace = filestore.getUsableSpace();
long totalSpace = filestore.getTotalSpace();
Assert.assertNotNull(name);
Assert.assertNotNull(description);
Assert.assertTrue(usableSpace > -1L);
Assert.assertTrue(totalSpace > -1L);
print("===FILE STORE #%d ===", ++i);
print(" Name=[%s]", name);
print(" Description=[%s]", description);
print(" UsableSpace=[%s] (%d)", FormatUtil.formatBytes(usableSpace), usableSpace);
print(" TotalSpace=[%s] (%d)", FormatUtil.formatBytes(totalSpace), totalSpace);
print(" toString=[%s]", filestore.toString());
}
}
示例3: getStorageAvailablePercent
import oshi.software.os.OSFileStore; //导入方法依赖的package包/类
@Override
public DecimalType getStorageAvailablePercent(int deviceIndex) throws DeviceNotFoundException {
// In the current OSHI version a new query is required for the storage data values to be updated
// In OSHI 4.0.0. it is planned to change this mechanism - see https://github.com/oshi/oshi/issues/310
fileStores = operatingSystem.getFileSystem().getFileStores();
OSFileStore fileStore = (OSFileStore) getDevice(fileStores, deviceIndex);
long totalSpace = fileStore.getTotalSpace();
long freeSpace = fileStore.getUsableSpace();
if (totalSpace > 0) {
double freePercentDecimal = (double) freeSpace / (double) totalSpace;
BigDecimal freePercent = getPercentsValue(freePercentDecimal);
return new DecimalType(freePercent);
} else {
return null;
}
}
示例4: getStorageUsedPercent
import oshi.software.os.OSFileStore; //导入方法依赖的package包/类
@Override
public DecimalType getStorageUsedPercent(int deviceIndex) throws DeviceNotFoundException {
// In the current OSHI version a new query is required for the storage data values to be updated
// In OSHI 4.0.0. it is planned to change this mechanism - see https://github.com/oshi/oshi/issues/310
fileStores = operatingSystem.getFileSystem().getFileStores();
OSFileStore fileStore = (OSFileStore) getDevice(fileStores, deviceIndex);
long totalSpace = fileStore.getTotalSpace();
long freeSpace = fileStore.getUsableSpace();
long usedSpace = totalSpace - freeSpace;
if (totalSpace > 0) {
double usedPercentDecimal = (double) usedSpace / (double) totalSpace;
BigDecimal usedPercent = getPercentsValue(usedPercentDecimal);
return new DecimalType(usedPercent);
} else {
return null;
}
}
示例5: publishFilesystem
import oshi.software.os.OSFileStore; //导入方法依赖的package包/类
private void publishFilesystem(final Map<String, Object> sharedData) {
HardwareAbstractionLayer hal = m_systemInfo.getHardware();
for (OSFileStore fs : hal.getFileStores()) {
long free = fs.getUsableSpace();
long total = fs.getTotalSpace();
long used = total - free;
String instance = fs.getName() + " (" + fs.getDescription() + ")";
publishMetric(sharedData, FILESYSTEM_USED, used, instance);
publishMetric(sharedData, FILESYSTEM_FREE, free, instance);
publishMetric(sharedData, FILESYSTEM_TOTAL, total, instance);
}
}
示例6: getStorageTotal
import oshi.software.os.OSFileStore; //导入方法依赖的package包/类
@Override
public DecimalType getStorageTotal(int index) throws DeviceNotFoundException {
// In the current OSHI version a new query is required for the storage data values to be updated
// In OSHI 4.0.0. it is planned to change this mechanism - see https://github.com/oshi/oshi/issues/310
fileStores = operatingSystem.getFileSystem().getFileStores();
OSFileStore fileStore = (OSFileStore) getDevice(fileStores, index);
long totalSpace = fileStore.getTotalSpace();
totalSpace = getSizeInMB(totalSpace);
return new DecimalType(totalSpace);
}
示例7: getStorageUsed
import oshi.software.os.OSFileStore; //导入方法依赖的package包/类
@Override
public DecimalType getStorageUsed(int index) throws DeviceNotFoundException {
// In the current OSHI version a new query is required for the storage data values to be updated
// In OSHI 4.0.0. it is planned to change this mechanism - see https://github.com/oshi/oshi/issues/310
fileStores = operatingSystem.getFileSystem().getFileStores();
OSFileStore fileStore = (OSFileStore) getDevice(fileStores, index);
long totalSpace = fileStore.getTotalSpace();
long freeSpace = fileStore.getUsableSpace();
long usedSpace = totalSpace - freeSpace;
usedSpace = getSizeInMB(usedSpace);
return new DecimalType(usedSpace);
}
示例8: getFileSystems
import oshi.software.os.OSFileStore; //导入方法依赖的package包/类
/**
* this function retrieve informations about filesystems and calculate total and free space for each of them.
* After processing the data, send them to the model invoking <code>setAvailabeFileSystemInModel(String[])</code>
*
* @see MemoryStats#setAvailabeFileSystemInModel(String[])
* @return a string containing informations about all filesystems founded with total and free size, label, and type of device
*/
public String getFileSystems() {
OSFileStore[] fsArray = systemInfo.getOperatingSystem().getFileSystem().getFileStores();
String[] numericSpace = new String[fsArray.length];
String[] volume = new String[fsArray.length];
String[] stringBuilder = new String[fsArray.length];
for (int i = 0; i < fsArray.length; i++) {
OSFileStore fs = fsArray[i];
long usable = fs.getUsableSpace();
long total = fs.getTotalSpace();
stringBuilder[i] = (String.format(" %s (%s) [%s] %s free of %s (%.1f%%) " +
(fs.getLogicalVolume() != null && fs.getLogicalVolume().length() > 0 ? "[%s]" : "%s") +
"%n", fs.getName(),
fs.getDescription().isEmpty() ? "file system" : fs.getDescription(), fs.getType(),
FormatUtil.formatBytes(usable), FormatUtil.formatBytes(fs.getTotalSpace()), 100d * usable / total, fs.getLogicalVolume()));
try {
if (total == 0) {
volume[i] = fs.getMount();
numericSpace[i] = "0";
} else {
volume[i] = fs.getMount();
numericSpace[i] = String.format("%.1f", (100d * usable / total)).replace(",", ".");
}
} catch (NumberFormatException e) {
numericSpace[i] = "error";
}
}
for (int i = 0; i < numericSpace.length; i++) {
if (volume[i].equals("C:\\")) {
String genericString = numericSpace[0];
numericSpace[0] = numericSpace[i];
numericSpace[i] = genericString;
genericString = stringBuilder[0];
stringBuilder[0] = stringBuilder[i];
stringBuilder[i] = genericString;
}
}
setAvailabeFileSystemInModel(numericSpace);
return String.join("", stringBuilder);
}