Java Code Examples for oshi.hardware.HWDiskStore#getSize()

The following examples show how to use oshi.hardware.HWDiskStore#getSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SystemMonitorUtil.java    From base-admin with MIT License 6 votes vote down vote up
/**
 * 获取Windows 磁盘使用率
 *
 * @return 磁盘使用率
 */
private static HashMap<String, Long> getWinDiskUsage() {
    HardwareAbstractionLayer hal = systemInfo.getHardware();
    HWDiskStore[] diskStores = hal.getDiskStores();
    HashMap<String, Long> hashMap = new HashMap<>();
    long total = 0;
    long used = 0;
    if (diskStores != null && diskStores.length > 0) {
        for (HWDiskStore diskStore : diskStores) {
            long size = diskStore.getSize();
            long writeBytes = diskStore.getWriteBytes();
            total += size;
            used += writeBytes;
        }
    }
    hashMap.put("total",total);
    hashMap.put("used",used);
    return hashMap;
}
 
Example 2
Source File: HWIDProvider.java    From Launcher with GNU General Public License v3.0 5 votes vote down vote up
public String getHWDiskID() {
    HWDiskStore[] hwDiskStore = hardware.getDiskStores();
    long size = 0;
    HWDiskStore maxStore = null;
    for (HWDiskStore store : hwDiskStore) {
        if (store.getSize() > size) {
            maxStore = store;
            size = store.getSize();
        }
    }
    if (maxStore != null) {
        return maxStore.getSerial();
    }
    return null;
}
 
Example 3
Source File: BugReportGenerator.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private String generate() throws IOException {
    File reports = new File(Nukkit.DATA_PATH, "logs/bug_reports");
    if (!reports.isDirectory()) {
        reports.mkdirs();
    }

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmSS");
    String date = simpleDateFormat.format(new Date());

    SystemInfo systemInfo = new SystemInfo();
    long totalDiskSize = 0;
    StringBuilder model = new StringBuilder();
    for (HWDiskStore hwDiskStore : systemInfo.getHardware().getDiskStores()) {
        totalDiskSize += hwDiskStore.getSize();
        if (!model.toString().contains(hwDiskStore.getModel())) {
            model.append(hwDiskStore.getModel()).append(" ");
        }
    }

    StringWriter stringWriter = new StringWriter();
    throwable.printStackTrace(new PrintWriter(stringWriter));


    File mdReport = new File(reports, date + "_" + throwable.getClass().getSimpleName() + ".md");
    mdReport.createNewFile();
    String content = Utils.readFile(this.getClass().getClassLoader().getResourceAsStream("report_template.md"));

    Properties properties = getGitRepositoryState();
    System.out.println(properties.getProperty("git.commit.id.abbrev"));
    String abbrev = properties.getProperty("git.commit.id.abbrev");

    content = content.replace("${NUKKIT_VERSION}", Nukkit.VERSION);
    content = content.replace("${GIT_COMMIT_ABBREV}", abbrev);
    content = content.replace("${JAVA_VERSION}", System.getProperty("java.vm.name") + " (" + System.getProperty("java.runtime.version") + ")");
    content = content.replace("${HOSTOS}", systemInfo.getOperatingSystem().getFamily() + " [" + systemInfo.getOperatingSystem().getVersion().getVersion() + "]");
    content = content.replace("${MEMORY}", getCount(systemInfo.getHardware().getMemory().getTotal(), true));
    content = content.replace("${STORAGE_SIZE}", getCount(totalDiskSize, true));
    content = content.replace("${CPU_TYPE}", systemInfo.getHardware().getProcessor().getName());
    content = content.replace("${PHYSICAL_CORE}", String.valueOf(systemInfo.getHardware().getProcessor().getPhysicalProcessorCount()));
    content = content.replace("${LOGICAL_CORE}", String.valueOf(systemInfo.getHardware().getProcessor().getLogicalProcessorCount()));
    content = content.replace("${STACKTRACE}", stringWriter.toString());
    content = content.replace("${PLUGIN_ERROR}", String.valueOf(!throwable.getStackTrace()[0].getClassName().startsWith("cn.nukkit")).toUpperCase());
    content = content.replace("${STORAGE_TYPE}", model.toString());

    Utils.writeFile(mdReport, content);

    return mdReport.getAbsolutePath();
}