Example usage for org.apache.commons.io FileSystemUtils freeSpaceKb

List of usage examples for org.apache.commons.io FileSystemUtils freeSpaceKb

Introduction

In this page you can find the example usage for org.apache.commons.io FileSystemUtils freeSpaceKb.

Prototype

public static long freeSpaceKb(String path) throws IOException 

Source Link

Document

Returns the free space on a drive or volume in kilobytes by invoking the command line.

Usage

From source file:com.splout.db.dnode.DNodeHandler.java

/**
 * Returns an {@link com.splout.db.dnode.beans.DNodeSystemStatus} filled with
 * the appropriated data.//from w  ww . j  ava  2s  .  c  om
 */
@Override
public String status() throws DNodeException {
    try {
        DNodeSystemStatus status = new DNodeSystemStatus();
        if (lastException == null) {
            status.setSystemStatus("UP");
            status.setLastExceptionTime(-1);
        } else {
            status.setSystemStatus("Last exception: " + lastException);
            status.setLastExceptionTime(lastExceptionTime);
        }
        status.setUpSince(upSince);
        status.setFailedQueries(failedQueries.get());
        status.setnQueries(performanceTool.getNQueries());
        status.setAverage(performanceTool.getAverage());
        status.setSlowQueries(slowQueries);
        status.setDeploysInProgress(deployInProgress.get());
        status.setHttpExchangerAddress(httpExchangerAddress());
        status.setTcpAddress(getTCPAPIAddress());
        status.setBalanceActionsStateMap(balanceActionsStateMap);
        File folder = new File(config.getString(DNodeProperties.DATA_FOLDER));
        if (folder.exists()) {
            status.setFreeSpaceInDisk(FileSystemUtils.freeSpaceKb(folder.toString()));
            status.setOccupiedSpaceInDisk(FileUtils.sizeOfDirectory(folder));
            Collection<File> files = FileUtils.listFilesAndDirs(folder, TrueFileFilter.INSTANCE,
                    TrueFileFilter.INSTANCE);
            status.setFiles(new ArrayList<String>(
                    Lists.transform(Lists.newArrayList(files), new Function<File, String>() {
                        @Override
                        public String apply(File file) {
                            return file.getAbsolutePath() + " (" + FileUtils.sizeOf(file) + " bytes)";
                        }
                    })));
            Collections.sort(status.getFiles());
        } else {
            status.setOccupiedSpaceInDisk(0);
            status.setFreeSpaceInDisk(FileSystemUtils.freeSpaceKb("."));
            status.setFiles(new ArrayList<String>());
        }
        return JSONSerDe.ser(status);
    } catch (Throwable t) {
        unexpectedException(t);
        throw new DNodeException(EXCEPTION_UNEXPECTED, t.getMessage());
    }
}

From source file:nu.kelvin.jfileshare.servlets.AboutServlet.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ServletContext app = getServletContext();
    RequestDispatcher disp;//  w  w w.ja  v a 2s  . c  om
    req.setAttribute("tab", "About");
    disp = app.getRequestDispatcher("/templates/About.jsp");
    HttpSession session = req.getSession();
    Conf conf = (Conf) app.getAttribute("conf");

    req.setAttribute("daysLogRetention", conf.getDaysLogRetention());

    if (session.getAttribute("user") != null) {
        Connection dbConn = null;
        PreparedStatement st = null;
        try {
            long bytesStoreAvailable = FileSystemUtils.freeSpaceKb(conf.getPathStore()) * 1024;
            req.setAttribute("bytesStoreAvailable", FileItem.humanReadable(bytesStoreAvailable));

            dbConn = ds.getConnection();
            st = dbConn.prepareStatement(
                    "select cast(count(1) as char) as logins, cast(count(distinct payload) as char) as uniqueLogins from Logs where action=\"login\" and date > (now() - INTERVAL ? DAY)");
            st.setInt(1, conf.getDaysLogRetention());
            ResultSet rs = st.executeQuery();
            if (rs.first()) {
                req.setAttribute("logins", rs.getString("logins"));
                req.setAttribute("uniqueLogins", rs.getString("uniqueLogins"));
            }

            st = dbConn.prepareStatement(
                    "select cast(count(1) as char) as downloads, sum(cast(payload as unsigned)) as bytesDownloads from Logs where action=\"download\" and date > (now() - INTERVAL ? DAY)");
            st.setInt(1, conf.getDaysLogRetention());
            rs = st.executeQuery();
            if (rs.first()) {
                req.setAttribute("downloads", rs.getString("downloads"));
                req.setAttribute("bytesDownloads", FileItem.humanReadable(rs.getLong("bytesDownloads")));
            }

            st = dbConn.prepareStatement(
                    "select cast(count(1) as char) as uploads, sum(cast(payload as unsigned)) as bytesUploads from Logs where action=\"upload\" and date > (now() - INTERVAL ? DAY)");
            st.setInt(1, conf.getDaysLogRetention());
            rs = st.executeQuery();
            if (rs.first()) {
                req.setAttribute("uploads", rs.getString("uploads"));
                req.setAttribute("bytesUploads", FileItem.humanReadable(rs.getLong("bytesUploads")));
            }
            st.close();
        } catch (SQLException e) {
            logger.severe(e.toString());
        } finally {
            if (dbConn != null) {
                try {
                    dbConn.close();
                } catch (SQLException ignore) {
                }
            }
        }
    }
    disp.forward(req, resp);
}

From source file:ome.tools.FileSystem.java

/**
 * This method will return the free space in kilobytes TODO - resolve the
 * slash mount//from   ww  w.j  av a  2s .c o m
 * 
 * @return long of free space
 */
public long free(String mountRoot) throws RuntimeException {
    long result = 0L;

    try {
        result = FileSystemUtils.freeSpaceKb(mountRoot);
    } catch (IOException ioex) {
        throw new RuntimeException(ioex.getMessage());
    } catch (IllegalArgumentException illex) {
        throw new RuntimeException(illex.getMessage());
    } catch (IllegalStateException stex) {
        throw new RuntimeException(stex.getMessage());
    }

    return result;
}

From source file:org.easyrec.controller.dev.InfoController.java

public ModelAndView home(HttpServletRequest request, HttpServletResponse httpServletResponse) {
    String tenantId = ServletUtils.getSafeParameter(request, "tenantId", "");
    String operatorId = ServletUtils.getSafeParameter(request, "operatorId", "");

    ModelAndView mav = new ModelAndView("page");

    mav.addObject("title", "??::?");

    mav.addObject("operatorId", operatorId);
    mav.addObject("tenantId", tenantId);

    if (Security.isDeveloper(request)) {
        mav.setViewName("dev/page");
        mav.addObject("page", "home");
        mav.addObject("operatorCount", operatorDAO.count());
        mav.addObject("tenantCount", remoteTenantDAO.count());
        mav.addObject("dbName", operatorDAO.getDbName());
        mav.addObject("dbUserName", operatorDAO.getDbUserName());
        mav.addObject("signedinOperatorId", Security.signedInOperatorId(request));

        mav.addObject("heapsize",
                ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax() / (1000000));
        mav.addObject("usedmemory",
                ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed() / (1000000));

        int computationTimeInMilliseconds = logEntryDAO.getComputationDurationForDate() * 1000;
        String computationTime = HumanTime.approximately(computationTimeInMilliseconds);
        computationTime = computationTime.replaceAll("ms", "@1");
        computationTime = computationTime.replaceAll("s", "@2");
        computationTime = computationTime.replaceAll("m", "@3");
        computationTime = computationTime.replaceAll("h", "@4");
        computationTime = computationTime.replaceAll("d", "@5");
        computationTime = computationTime.replaceAll("@1", "milliseconds");
        computationTime = computationTime.replaceAll("@2", "seconds");
        computationTime = computationTime.replaceAll("@3", "minutes");
        computationTime = computationTime.replaceAll("@4", "hours");
        computationTime = computationTime.replaceAll("@5", "days");
        mav.addObject("dailyComputationTime", computationTime);

        long freeSpace = 0L;

        try {//from   ww  w  .  java  2 s.c om
            freeSpace = FileSystemUtils.freeSpaceKb(System.getProperties().getProperty("user.dir"));
        } catch (IOException e) {
            logger.error("Could not check free Free Disc Space :" + e.getMessage());
        }

        mav.addObject("freespace", freeSpace / 1048576);

        return mav;
    } else {
        return MessageBlock.createSingle(mav, MSG.NOT_SIGNED_IN, HOME, MSG.ERROR);
    }
}

From source file:org.jam.metrics.FreeDiskSpaceMetricBean.java

@Metric(fieldName = { "freeDiskSpaceGB" }, groupName = "freeDiskSpace")
public double freeDiskSpace() {
    try {//from   w w w .jav a 2  s.  co  m
        //calculate free disk space 
        double freeDiskSpace = FileSystemUtils.freeSpaceKb("/");

        //convert the number into gigabyte
        freeDiskSpaceGB = freeDiskSpace / 1024 / 1024;

        System.out.println("Free Disk Space of a Linux OS (GB):" + freeDiskSpaceGB);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return freeDiskSpaceGB;
}

From source file:org.neociclo.odetteftp.camel.AcceptIncomingFileHandler.java

private boolean checkFileSystemSpace(File localFile, long fileSize) {
    try {/*from   w  ww. j  a v a 2s .c om*/
        long freeSpace = FileSystemUtils.freeSpaceKb(localFile.getParent());
        return freeSpace > fileSize;
    } catch (IOException e) {
        LOGGER.warn("Tried to check file system's free space", e);
    }

    return true;
}

From source file:org.openthinclient.util.dpkg.DPKGPackageManager.java

public long getFreeDiskSpace() throws PackageManagerException {
    try {//from  w  ww . ja va2s  .  co m
        return FileSystemUtils.freeSpaceKb(installDir.getAbsolutePath());
    } catch (final IOException io) {
        io.printStackTrace();
        addWarning(io.toString());
        logger.error("Failed to access free disk space information", io);
        return 0;

        // throw new PackageManagerException(io);

    }
}

From source file:org.waarp.common.file.filesystembased.specific.FilesystemBasedCommonsIo.java

/**
 * /*from   w w  w .j  a  v  a2  s .  c  o  m*/
 * @param pathname
 * @return the free space of the given pathname
 */
public static long freeSpace(String pathname) {
    try {
        return FileSystemUtils.freeSpaceKb(pathname) << 10;
    } catch (IOException e) {
        return -1;
    }
}