Example usage for org.apache.commons.io FileUtils sizeOfDirectory

List of usage examples for org.apache.commons.io FileUtils sizeOfDirectory

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils sizeOfDirectory.

Prototype

public static long sizeOfDirectory(File directory) 

Source Link

Document

Counts the size of a directory recursively (sum of the length of all files).

Usage

From source file:com.pari.nm.utils.backup.BackupRestore.java

public boolean doImageBackup(File backupDir, File imageDir, BackupMetaData bkupDetails) {

    File imgBkpDir = new File(backupDir, IMAGE_DIRECTORY);
    if (!copyDirectory(imageDir, imgBkpDir)) {
        logger.error("Failed to copy the image file");
        return false;
    }//  w w w  .  j ava2s  .co m
    BackupComponentDetails compDetail = new BackupComponentDetails();
    compDetail.setComponentType(BackupComponentType.IMAGES);
    int numberOfFiles = updateTotalFile(imgBkpDir, compDetail);
    compDetail.setNumberOfFiles(numberOfFiles);
    double totalFileSize = FileUtils.sizeOfDirectory(imgBkpDir);
    compDetail.setTotalFileSize(totalFileSize / (1024 * 1024 * 1024));
    bkupDetails.setComponentDetail(BackupComponentType.IMAGES, compDetail);
    return true;
}

From source file:com.edgenius.core.repository.SimpleRepositoryServiceImpl.java

/**
 * @obsolete,use CrWorksSpace table replace Quota file (I thought, every space should has a file which contains Quota info)
 * @throws RepositoryQuotaException //from   w w  w .ja  v  a  2 s .  com
 */
private void checkSpaceQuotaFile(ITicket ticket, long size) throws RepositoryQuotaException {

    CrWorkspace crW = getCrWorkspace(ticket);
    String spaceDir = FileUtil.getFullPath(homeDir, crW.getSpaceUuid());
    File quotaFile = new File(FileUtil.getFullPath(spaceDir, QUOTA_FILE_NAME));
    long quota = Global.SpaceQuota;
    if (!quotaFile.exists()) {
        //it is already be default quota size
        createQuotaFile(ticket);
    } else {
        //read quota from file
        InputStream is = null;
        try {
            is = new FileInputStream(quotaFile);
            byte[] out = new byte[1024];
            int len = -1;
            StringBuffer sb = new StringBuffer();
            while ((len = is.read(out)) != -1) {
                sb.append(new String(out, 0, len));
            }
            quota = NumberUtils.toLong(sb.toString(), Global.SpaceQuota);
        } catch (Exception e) {
            log.error("Failed get quota size for space " + ticket.getSpacename(), e);
            //nothing
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
    //append file size
    long spaceSize = FileUtils.sizeOfDirectory(new File(spaceDir)) + size;

    if (spaceSize > quota) {
        String error = "Space " + ticket.getSpacename() + " quota is " + quota + " and current size is "
                + spaceSize;
        log.info(error);
        throw new RepositoryQuotaException(error);
    }

}

From source file:it.drwolf.ridire.session.CrawlerManager.java

private long getRawBytesFromFileSystem(String jobName) throws NullPointerException {
    String dir = this.entityManager.find(Parameter.class, Parameter.JOBS_DIR.getKey()).getValue();
    return FileUtils.sizeOfDirectory(new File(dir + CrawlerManager.FILE_SEPARATOR + jobName
            + CrawlerManager.FILE_SEPARATOR + "arcs" + CrawlerManager.FILE_SEPARATOR));
}

From source file:ca.uviccscu.lp.server.main.MainFrame.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    l.info("Add game action activated");
    MainFrame.lockInterface();//  www .ja v a 2  s.c o m
    MainFrame.updateTask("Adding game...", true);
    AddGameDialog addGameDialog = new AddGameDialog(this, true);
    addGameDialog.setLocationRelativeTo(null);
    //addGameDialog.setVisible(true);
    final Game g = addGameDialog.popupCreateDialog();
    if (g != null) {
        l.trace("Analyzing game: " + g.gameAbsoluteFolderPath);
        MainFrame.updateTask("Adding game...", true);
        final int row = getNextFreeRowNumber();
        addFreeRow();
        jTable1.getModel().setValueAt(g.gameName, row, 0);
        jTable1.getModel().setValueAt(g.gameAbsoluteExecPath, row, 1);
        jTable1.getModel().setValueAt(GamelistStorage.gameStatusToString(g.gameStatus), row, 3);
        MainFrame.updateProgressBar(0, 0, 0, "Analyzing game", true, true);
        final ObjectPlaceholder obj = new ObjectPlaceholder();
        SwingWorker worker = new SwingWorker<Long, Void>() {

            @Override
            public Long doInBackground() throws IOException {
                l.trace("Checking size");
                MainFrame.updateProgressBar(0, 0, 0, "Analyzing game size", true, true);
                obj.payload = FileUtils.sizeOfDirectory(new File(g.gameAbsoluteFolderPath));
                l.trace("Checking files");
                MainFrame.updateProgressBar(0, 0, 0, "Analyzing game files", true, true);
                g.gameFileNumber = FileUtils.listFiles(new File(g.gameAbsoluteFolderPath), null, true).size();
                l.trace("Checking CRC32");
                MainFrame.updateProgressBar(0, 0, 0, "Analyzing game signature", true, true);
                g.gameExecCRC32 = FileUtils.checksumCRC32(new File(g.gameAbsoluteExecPath));
                return ((Long) obj.payload);
            }

            public void done() {
                l.trace("Finishing game check");
                MainFrame.updateProgressBar(0, 0, 0, "Finishing game creation", false, false);
                g.gameSize = ((Long) obj.payload);
                /*
                double mbsize = Math.ceil(g.gameSize / (1024 * 1024));
                jTable1.getModel().setValueAt(mbsize, row, 2);
                 * 
                 */
                jTable1.getModel().setValueAt(FileUtils.byteCountToDisplaySize(g.gameSize), row, 2);
                Shared.lastCreatedGame = null;
                GamelistStorage.addGame(g);
                jTable1.getModel().setValueAt(GamelistStorage.gameStatusToString(g.gameStatus), row, 3);
                g.gameStatus = 0;
                SettingsManager.getStorage().storeGame(g);
                /*
                try {
                SettingsManager.storeCurrentSettings();
                } catch (Exception ex) {
                l.debug(ex.getMessage(), ex);
                }
                 * 
                 */
                l.trace("Done adding game");
                MainFrame.setReportingIdle();
                MainFrame.unlockInterface();
            }
        };
        worker.execute();
    } else {
        l.debug("Add game dialog - null game returned, nothing done");
        MainFrame.setReportingIdle();
        MainFrame.unlockInterface();
    }
    MainFrame.updateGameInterfaceFromStorage();
}

From source file:ca.uviccscu.lp.server.main.MainFrame.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    l.info("Edit game action activated");
    MainFrame.lockInterface();// w w  w  . ja v  a 2s .com
    MainFrame.updateTask("Editing game...", true);
    l.info("Starting game edit action");
    DefaultTableModel mdl = (DefaultTableModel) jTable1.getModel();
    final int row = jTable1.getSelectedRow();
    if (row >= 0 && mdl.getValueAt(row, 0) != null) {
        AddGameDialog addGameDialog = new AddGameDialog(this, true);
        addGameDialog.setLocationRelativeTo(null);
        //addGameDialog.setVisible(true);
        final Game temp = GamelistStorage.getGame((String) mdl.getValueAt(row, 0));
        final Game g = addGameDialog.popupEditDialog(temp);
        if (g != null) {
            l.trace("Edit done, checking for changes");
            //l.trace("Calculating folder size: " + g.gameAbsoluteFolderPath);
            MainFrame.updateTask("Checking for changes...", true);
            MainFrame.updateGameInterfaceFromStorage();
            boolean changed = true;
            if (temp.gameAbsoluteExecPath.equals(g.gameAbsoluteExecPath)
                    && temp.gameAbsoluteFolderPath.equals(g.gameAbsoluteFolderPath)) {
                l.trace("Location same - assuming no changes made");
                g.gameName = temp.gameName;
                g.gameBatCommands = temp.gameBatCommands;
                g.gamePName = temp.gamePName;
                g.gamePUser = temp.gamePUser;
                g.gamePWName = temp.gamePWName;
                g.gameRuntimeFlags = temp.gameRuntimeFlags;
                changed = false;
            } else {
                l.trace("Locations changed - rescanning the game");
                g.gameStatus = 0;
                MainFrame.updateProgressBar(0, 0, 0, "Calculating game size", true, true);
                final ObjectPlaceholder obj = new ObjectPlaceholder();
                SwingWorker worker = new SwingWorker<Long, Void>() {

                    @Override
                    public Long doInBackground() throws IOException {
                        MainFrame.lockInterface();
                        l.trace("Checking size");
                        MainFrame.updateProgressBar(0, 0, 0, "Analyzing game size", true, true);
                        obj.payload = FileUtils.sizeOfDirectory(new File(g.gameAbsoluteFolderPath));
                        l.trace("Checking files");
                        MainFrame.updateProgressBar(0, 0, 0, "Analyzing game files", true, true);
                        g.gameFileNumber = FileUtils.listFiles(new File(g.gameAbsoluteFolderPath), null, true)
                                .size();
                        l.trace("Checking CRC32");
                        MainFrame.updateProgressBar(0, 0, 0, "Analyzing game signature", true, true);
                        g.gameExecCRC32 = FileUtils.checksumCRC32(new File(g.gameAbsoluteExecPath));
                        return ((Long) obj.payload);
                    }

                    @Override
                    public void done() {
                        l.trace("Finishing game check");
                        MainFrame.updateProgressBar(0, 0, 0, "Finishing game edit", false, false);
                        g.gameSize = ((Long) obj.payload);
                        /*
                        double mbsize = Math.ceil(g.gameSize / (1024 * 1024));
                        jTable1.getModel().setValueAt(mbsize, row, 2);
                         *
                         */
                        g.copyTo(temp);
                        Shared.lastCreatedGame = null;
                        l.trace("Done editing game");
                        MainFrame.updateGameInterfaceFromStorage();
                        MainFrame.unlockInterface();
                        MainFrame.setReportingIdle();
                    }
                };
                worker.execute();
            }
            //we are trusting the size task to finish here ELSE TROUBLE
            /*
            GamelistStorage.removeGame(temp.gameName);
            GamelistStorage.addGame(g);
             * 
             */
            if (!changed) {
                MainFrame.unlockInterface();
                MainFrame.setReportingIdle();
            }
            MainFrame.updateGameInterfaceFromStorage();
        } else {
            MainFrame.unlockInterface();
            MainFrame.setReportingIdle();
            MainFrame.updateGameInterfaceFromStorage();
        }
    } else {
        l.trace("Game edit - bad selection or empty table");
        JOptionPane.showMessageDialog(this, "Invalid selection - can't edit", "Edit error",
                JOptionPane.WARNING_MESSAGE);
        MainFrame.unlockInterface();
        MainFrame.setReportingIdle();
        MainFrame.updateGameInterfaceFromStorage();
    }
}

From source file:net.sourceforge.subsonic.controller.VideoConversionSettingsController.java

private long getDiskUsage() {
    File dir = new File(settingsService.getVideoConversionDirectory());
    if (dir.canRead() && dir.isDirectory()) {
        return FileUtils.sizeOfDirectory(dir);
    }/*from w  w  w . j av  a2 s  . co m*/
    return 0;
}

From source file:net.yacy.search.ResourceObserver.java

public long getSizeOfDataPath(final boolean cached) {
    if (cached && System.currentTimeMillis() - this.sizeOfDirectory_lastCountTime < 600000)
        return this.sizeOfDirectory_lastCountValue;
    this.sizeOfDirectory_lastCountTime = System.currentTimeMillis();
    try {//w  w  w  . j  a  v  a  2 s .  c  o  m
        this.sizeOfDirectory_lastCountValue = FileUtils.sizeOfDirectory(this.path);
    } catch (Throwable e) {
    } // org.apache.commons.io.FileUtils.sizeOf calls sizes of files which are there temporary and may cause an exception. Thats a bug inside FileUtils
    return this.sizeOfDirectory_lastCountValue;
}

From source file:org.apache.carbondata.core.datastorage.store.impl.FileFactory.java

/**
 * It computes size of directory/*w w  w . j a va 2  s .c  om*/
 *
 * @param filePath
 * @return size in bytes
 * @throws IOException
 */
public static long getDirectorySize(String filePath) throws IOException {
    FileType fileType = getFileType(filePath);
    switch (fileType) {
    case HDFS:
    case ALLUXIO:
    case VIEWFS:
        Path path = new Path(filePath);
        FileSystem fs = path.getFileSystem(configuration);
        return fs.getContentSummary(path).getLength();
    case LOCAL:
    default:
        File file = new File(filePath);
        return FileUtils.sizeOfDirectory(file);
    }
}

From source file:org.apache.carbondata.core.datastore.impl.FileFactory.java

/**
 * It computes size of directory/*from ww  w. j a v a 2  s .c om*/
 *
 * @param filePath
 * @return size in bytes
 * @throws IOException
 */
public static long getDirectorySize(String filePath) throws IOException {
    FileType fileType = getFileType(filePath);
    switch (fileType) {
    case HDFS:
    case ALLUXIO:
    case VIEWFS:
        Path path = new Path(filePath);
        FileSystem fs = path.getFileSystem(configuration);
        return fs.getContentSummary(path).getLength();
    case LOCAL:
    default:
        filePath = getUpdatedFilePath(filePath, fileType);
        File file = new File(filePath);
        return FileUtils.sizeOfDirectory(file);
    }
}

From source file:org.apache.cloudstack.storage.resource.NfsSecondaryStorageResource.java

private UploadStatusAnswer execute(UploadStatusCommand cmd) {
    String entityUuid = cmd.getEntityUuid();
    if (uploadEntityStateMap.containsKey(entityUuid)) {
        UploadEntity uploadEntity = uploadEntityStateMap.get(entityUuid);
        if (uploadEntity.getUploadState() == UploadEntity.Status.ERROR) {
            uploadEntityStateMap.remove(entityUuid);
            return new UploadStatusAnswer(cmd, UploadStatus.ERROR, uploadEntity.getErrorMessage());
        } else if (uploadEntity.getUploadState() == UploadEntity.Status.COMPLETED) {
            UploadStatusAnswer answer = new UploadStatusAnswer(cmd, UploadStatus.COMPLETED);
            answer.setVirtualSize(uploadEntity.getVirtualSize());
            answer.setInstallPath(uploadEntity.getTmpltPath());
            answer.setPhysicalSize(uploadEntity.getPhysicalSize());
            answer.setDownloadPercent(100);
            uploadEntityStateMap.remove(entityUuid);
            return answer;
        } else if (uploadEntity.getUploadState() == UploadEntity.Status.IN_PROGRESS) {
            UploadStatusAnswer answer = new UploadStatusAnswer(cmd, UploadStatus.IN_PROGRESS);
            long downloadedSize = FileUtils.sizeOfDirectory(new File(uploadEntity.getInstallPathPrefix()));
            int downloadPercent = (int) (100 * downloadedSize / uploadEntity.getContentLength());
            answer.setDownloadPercent(Math.min(downloadPercent, 100));
            return answer;
        }/*from   www  . j  a v  a  2 s.  c  om*/
    }
    return new UploadStatusAnswer(cmd, UploadStatus.UNKNOWN);
}