Example usage for java.io File getTotalSpace

List of usage examples for java.io File getTotalSpace

Introduction

In this page you can find the example usage for java.io File getTotalSpace.

Prototype

public long getTotalSpace() 

Source Link

Document

Returns the size of the partition named by this abstract pathname.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    // create new files
    File f = new File("c:/");

    System.out.print(f.getTotalSpace());

}

From source file:Main.java

public static void main(String[] args) {
    File file = new File("C:");
    long totalSpace = file.getTotalSpace();
    System.out.println("Total space on " + file + " = " + totalSpace + "bytes");

    // Check the free space in C:
    long freeSpace = file.getFreeSpace();
    System.out.println("Free space on " + file + " = " + freeSpace + "bytes");
}

From source file:org.jdal.util.processor.JasperReportFileProcessor.java

public static void main(String[] args) {
    try {//  w  w  w  . jav a  2  s.  com
        JasperReport report = JasperCompileManager
                .compileReport("/home/jose/Projects/telmma/Documents/Code/testParameters.jrxml");

        System.out.println("Query en el jasper: " + report.getQuery().getText());
        for (JRParameter param : report.getParameters()) {
            if (!param.isSystemDefined())
                System.out.println(param.getName());
        }
        Map<String, Object> parameters = new HashMap<String, Object>();
        // TEST
        parameters.put("NombreCiudad", "Huelva");

        JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, new JREmptyDataSource());
        byte[] reportBin = JasperExportManager.exportReportToPdf(jasperPrint);

        if (Desktop.isDesktopSupported()) {
            Desktop desktop = Desktop.getDesktop();
            File outputFile;
            try {
                outputFile = File.createTempFile("simple_report", ".pdf");
                //outputFile.deleteOnExit();
                // Create the file with the raw data provided by the file processor 
                FileUtils.writeByteArrayToFile(outputFile, reportBin);

                System.out.println("OutputFile -> " + outputFile.getName() + " " + outputFile.getTotalSpace());

                desktop.open(outputFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:Main.java

public static double getTFlashCardSpaceWhenInsertSdcard() {
    File dir;
    if (getStorageDirWhenInsertSdcard() != null) {
        dir = new File(T_FLASH_PATH);
        return dir.getTotalSpace() * 0.8;
    }//from  ww w  .j  a v a  2  s.  c  o  m

    return 0;
}

From source file:Main.java

public static double getTFlashCardSpace() {
    File dir;
    if (isTFlashCardExists()) {
        dir = new File(T_FLASH_PATH);
        return dir.getTotalSpace() * 0.8;
    }/*from  ww w.j a  v a2  s  .co  m*/

    return 0;
}

From source file:net.centro.rtb.monitoringcenter.infos.OperatingSystemInfo.java

public static OperatingSystemInfo create() {
    OperatingSystemInfo operatingSystemInfo = new OperatingSystemInfo();

    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();

    operatingSystemInfo.name = operatingSystemMXBean.getName();
    operatingSystemInfo.version = operatingSystemMXBean.getVersion();

    if (SystemUtils.IS_OS_LINUX) {
        operatingSystemInfo.distributionName = resolveLinuxDistributionName();
    }//from   w ww. j  a v  a  2 s. c o m

    operatingSystemInfo.architecture = operatingSystemMXBean.getArch();
    operatingSystemInfo.numberOfLogicalProcessors = operatingSystemMXBean.getAvailableProcessors();

    if (com.sun.management.OperatingSystemMXBean.class.isAssignableFrom(operatingSystemMXBean.getClass())) {
        com.sun.management.OperatingSystemMXBean sunOsMxBean = com.sun.management.OperatingSystemMXBean.class
                .cast(operatingSystemMXBean);
        operatingSystemInfo.physicalMemorySizeInBytes = sunOsMxBean.getTotalPhysicalMemorySize();
        operatingSystemInfo.swapSpaceSizeInBytes = sunOsMxBean.getTotalSwapSpaceSize();
    }

    Map<String, Long> diskSpaceInBytesByRootPaths = new HashMap<>();
    for (File rootFile : File.listRoots()) {
        diskSpaceInBytesByRootPaths.put(rootFile.getAbsolutePath(), rootFile.getTotalSpace());
    }
    operatingSystemInfo.diskSpaceInBytesByRootPaths = diskSpaceInBytesByRootPaths;

    return operatingSystemInfo;
}

From source file:io.hawkcd.agent.AgentConfiguration.java

private static void configureEnvironmentInfo() {
    File file = new File("/");
    int gb = 1024 * 1024 * 1024;

    environmentInfo.setOsName(System.getProperty("os.name"));
    environmentInfo.setTotalDiskSpaceGBytes(file.getFreeSpace() / gb);
    environmentInfo.setFreeDiskSpaceGBytes(file.getTotalSpace() / gb);
    environmentInfo.setTotalRamMBytes(// w w w .  j  ava  2  s .c o m
            ((OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize()
                    * 1024);
    environmentInfo.setFreeRamMBytes(
            ((OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getFreePhysicalMemorySize()
                    * 1024);
}

From source file:org.benetech.secureapp.generator.BuildingApkController.java

private static void LogMemoryCheck(HttpSession session, String description, File baseBuildDir) {
    long totalSpace = getMegaBytes(baseBuildDir.getTotalSpace());
    long freeSpace = getMegaBytes(baseBuildDir.getFreeSpace());
    long usableSpace = getMegaBytes(baseBuildDir.getUsableSpace());

    int processors = Runtime.getRuntime().availableProcessors();
    long freeMemory = getMegaBytes(Runtime.getRuntime().freeMemory());
    long maxMemory = Runtime.getRuntime().maxMemory();
    String jvmMemory = (maxMemory == Long.MAX_VALUE ? "no limit" : String.valueOf(getMegaBytes(maxMemory)));
    long totalMemory = getMegaBytes(Runtime.getRuntime().totalMemory());
    StringBuilder memoryUsed = new StringBuilder();
    memoryUsed.append("MEMORY CHECK: ");
    memoryUsed.append(description);/* w ww  .ja v  a 2s. c o  m*/
    memoryUsed.append(": Processors = ");
    memoryUsed.append(processors);
    memoryUsed.append(", Total Memory = ");
    memoryUsed.append(totalMemory);
    memoryUsed.append(" MB, JVM Memory = ");
    memoryUsed.append(jvmMemory);
    memoryUsed.append(" MB, Free Memory = ");
    memoryUsed.append(freeMemory);
    memoryUsed.append(" MB -- Disk Total Space = ");
    memoryUsed.append(totalSpace);
    memoryUsed.append(" MB, Disk Usable Space = ");
    memoryUsed.append(usableSpace);
    memoryUsed.append(" MB, Disk Free Space = ");
    memoryUsed.append(freeSpace);
    memoryUsed.append(" MB.");
    SagLogger.logInfo(session, memoryUsed.toString());
}

From source file:Main.java

private static byte[] getBytesFromFile(File file) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
    try {/*w  w w  . j  a  v a  2  s .c  om*/
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        int maxBufferSize = 1024 * 1024;
        int bufferSize = (int) Math.min(file.getTotalSpace(), maxBufferSize);
        byte[] buffer = new byte[bufferSize];

        // read file and write it into form...
        int bytesRead = 0;

        if (fileInputStream != null) {
            bytesRead = fileInputStream.read(buffer, 0, bufferSize);
        }

        while (bytesRead > 0) {
            dataOutputStream.write(buffer, 0, bufferSize);
            int bytesAvailable = fileInputStream.available();
            bufferSize = Math.min(bytesAvailable, maxBufferSize);
            bytesRead = fileInputStream.read(buffer, 0, bufferSize);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return byteArrayOutputStream.toByteArray();
}

From source file:gov.nasa.ensemble.common.io.FileUtilities.java

public static String getUsableSpaceString(File anyFileInSystem) {
    long totalSpace = anyFileInSystem.getTotalSpace();
    if (totalSpace == 0)
        return "Disk space unknown.";
    long usableSpace = anyFileInSystem.getUsableSpace();
    return bytesString(usableSpace) + " out of " + bytesString(totalSpace) + " available.";
}