Example usage for java.io File getFreeSpace

List of usage examples for java.io File getFreeSpace

Introduction

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

Prototype

public long getFreeSpace() 

Source Link

Document

Returns the number of unallocated bytes in the partition named by this abstract path name.

Usage

From source file:com.stimulus.archiva.domain.Volume.java

protected long getAvailableBytes(File filePath, long usedBytes) {
    long freeSpaceBytes = filePath.getFreeSpace();
    long maxSizeBytes = maxSize * 1024 * 1024;
    long freeSpace2Bytes = maxSizeBytes - usedBytes;
    if (freeSpaceBytes < freeSpace2Bytes)
        return freeSpaceBytes;
    else//from  w  w  w. ja v a  2s  . c  om
        return freeSpace2Bytes;
}

From source file:org.h819.commons.file.MyPDFUtilss.java

/**
 * ???//from   w ww  .  j ava2s.  c o  m
 *
 * @param srcPdfFileDir
 * @param descPdfFileDir
 * @return
 */
private static boolean isEnoughtSpace(File srcPdfFileDir, File descPdfFileDir) {

    if (!srcPdfFileDir.exists() && !srcPdfFileDir.isDirectory()) {
        logger.info(srcPdfFileDir.getAbsolutePath() + " not exist.");
        return false;
    }

    try {
        FileUtils.forceMkdir(descPdfFileDir);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // ??

    // 
    long prefixDiskFreeSize = descPdfFileDir.getFreeSpace();
    // ??
    long srcSize = FileUtils.sizeOfDirectory(srcPdfFileDir);

    // logger.info(descPdfFileDir.getAbsolutePath() + " "
    // + prefixDiskFreeSize / 1000000.00 + " M");
    // logger.info(srcPdfFileDir.getAbsolutePath() + " ? :" + srcSize
    // / 1000000.00 + " M");

    if (prefixDiskFreeSize < srcSize) {
        logger.info(FilenameUtils.getPrefix(descPdfFileDir.getAbsolutePath()) + " has not enoght disk size .");
        return false;
    }

    return true;

}

From source file:dev.dworks.apps.anexplorer.provider.ExternalStorageProvider.java

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
    synchronized (mRootsLock) {
        for (String rootId : mIdToPath.keySet()) {
            final RootInfo root = mIdToRoot.get(rootId);
            final File path = mIdToPath.get(rootId);

            final RowBuilder row = result.newRow();
            row.add(Root.COLUMN_ROOT_ID, root.rootId);
            row.add(Root.COLUMN_FLAGS, root.flags);
            row.add(Root.COLUMN_TITLE, root.title);
            row.add(Root.COLUMN_DOCUMENT_ID, root.docId);
            row.add(Root.COLUMN_PATH, root.path);
            if (ROOT_ID_PRIMARY_EMULATED.equals(root.rootId) || root.rootId.startsWith(ROOT_ID_SECONDARY)
                    || root.rootId.startsWith(ROOT_ID_PHONE)) {
                final File file = root.rootId.startsWith(ROOT_ID_PHONE) ? Environment.getRootDirectory() : path;
                row.add(Root.COLUMN_AVAILABLE_BYTES, file.getFreeSpace());
                row.add(Root.COLUMN_TOTAL_BYTES, file.getTotalSpace());
            }//  w  ww.j a  va 2 s . c om
        }
    }
    return result;
}

From source file:org.h819.commons.file.MyPDFUtilss.java

/**
 * http://www.javabeat.net/javascript-in-pdf-documents-using-itext/
 * http://www.javabeat.net/javascript-communication-between-html-and-pdf-in-itext/
 *  PDF  field  javaScript//from w w w.j  av a2s  . com
 * <p>
 * pdf ? javaScript?????
 * <p>
 * javaScript ?? filed  filed javaScript ???
 * <p>
 * ?? javaScript 
 * <p>
 *  itext  reader.getJavaScript()? pdf  JavaScript??(adobe pro
 * ????)
 * <p>
 * ??? field ??
 *
 * @param srcPdfFileDir   ?
 * @param descPdfFileDir  
 * @param removeFieldName  javaScript ???
 * @throws java.io.IOException
 */
public static void removeFieldJavaScript(File srcPdfFileDir, File descPdfFileDir, String removeFieldName)
        throws IOException {

    if (!srcPdfFileDir.isDirectory()) {
        logger.info("srcPdfFileDir is not a Directory: " + srcPdfFileDir.getAbsolutePath());
        return;
    }

    File listFiles[] = srcPdfFileDir.listFiles();

    if (listFiles.length == 0) {
        logger.info("srcPdfFileDir has not file. " + srcPdfFileDir.getAbsolutePath());
        return;
    }

    FileUtils.forceMkdir(descPdfFileDir);

    // ??

    // 
    long prefixDiskFreeSize = descPdfFileDir.getFreeSpace();
    // ??
    long srcSize = FileUtils.sizeOf(srcPdfFileDir);

    logger.info(descPdfFileDir.getAbsolutePath() + " " + prefixDiskFreeSize / 1000000.00
            + " M");
    logger.info(srcPdfFileDir.getAbsolutePath() + " ? :" + srcSize / 1000000.00 + " M");

    if (prefixDiskFreeSize < srcSize) {

        logger.info(FilenameUtils.getPrefix(descPdfFileDir.getAbsolutePath()) + " has not enoght disk size .");

        return;
    }

    // logger.info(descPdfFileDir.getAbsolutePath());

    for (File f : listFiles) {
        String fileName = f.getName();
        String extensiion = FilenameUtils.getExtension(fileName).toLowerCase();

        PdfReader reader = null;

        PdfStamper stamper = null;

        if (f.isFile()) {
            if (extensiion.equals("pdf")) {

                reader = getPdfReader(f);

                File fileDesc = new File(descPdfFileDir.getAbsolutePath() + File.separator + fileName);

                try {
                    stamper = new PdfStamper(reader, FileUtils.openOutputStream(fileDesc));

                    /**
                     * ???
                     * **/
                    // reader.removeFields();

                    /**
                     * ??? javaScript ?
                     * **/
                    AcroFields form = stamper.getAcroFields();
                    form.removeField(removeFieldName);

                    stamper.close();
                    reader.close();

                } catch (DocumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            } else
                continue;

        } // end if f.isFile

        else if (f.isDirectory()) {
            removeFieldJavaScript(f, new File(descPdfFileDir.getAbsolutePath() + File.separator + fileName),
                    removeFieldName);
        } // end if f.isDirectory
        else
            continue;

    } // end for

    logger.info("finished !");
}

From source file:eu.europeana.corelib.europeanastatic.controllers.ImageController.java

private void respondWithDebug(HttpServletResponse response, File cachedFile) throws IOException {

    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();
    try {//from  w  ww  .j  a va  2 s  .  c  o  m
        if (cachedFile == null) {
            out.println("Image file was not copied to the image repository");
        } else {
            out.println("Local file: " + cachedFile.getCanonicalPath());
            if (cachedFile.exists()) {
                out.println("Exists");
                if (cachedFile.canRead()) {
                    out.println("Can be read");
                    out.println("Size: " + cachedFile.length());
                } else {
                    out.println("Cannot be read - permissions are wrong");
                }
            } else {
                out.println("Does not exist");
            }
            out.println("And by the way, there are " + (cachedFile.getFreeSpace() / 1024 / 1024)
                    + " Mb left on the partition where images are stored");
        }
    } finally {
        out.close();
    }
}

From source file:org.lockss.util.PlatformUtil.java

public DF getJavaDF(String path) {
    File f = null;
    try {//w ww.  j av a 2  s  . c om
        f = new File(path).getCanonicalFile();
    } catch (IOException e) {
        f = new File(path).getAbsoluteFile();
    }
    // mirror the df behaviour of returning null if path doesn't exist
    if (!f.exists()) {
        return null;
    }
    DF df = new DF();
    df.path = path;
    df.size = f.getTotalSpace() / 1024;
    df.avail = f.getUsableSpace() / 1024;
    df.used = df.size - (f.getFreeSpace() / 1024);
    df.percent = Math.ceil((df.size - df.avail) * 100.00 / df.size);
    df.percentString = String.valueOf(Math.round(df.percent)) + "%";
    df.percent /= 100.00;
    df.fs = null;
    df.mnt = longestRootFile(f);
    if (log.isDebug2())
        log.debug2(df.toString());
    return df;
}

From source file:com.amaze.filemanager.utils.Futils.java

public long[] getSpaces(HFile hFile) {
    if (!hFile.isSmb() && hFile.isDirectory()) {
        try {/*from   w w  w  .ja v a  2s .  c om*/
            File file = new File(hFile.getPath());
            long[] ints = new long[] { file.getTotalSpace(), file.getFreeSpace(),
                    folderSize(new File(hFile.getPath())) };
            return ints;
        } catch (Exception e) {
            return new long[] { -1, -1, -1 };
        }
    }
    return new long[] { -1, -1, -1 };
}

From source file:com.topsec.tsm.sim.sysconfig.web.SystemConfigController.java

/**
 * ?/* w w  w . j a  va2 s . c  o  m*/
 * 
 * @return
 */
private List getLocalFileRoots() {
    List listroots = new ArrayList();
    File[] roots = File.listRoots();
    for (File file : roots) {
        if (file.getTotalSpace() <= 0)
            continue;
        TreeData treedata = new TreeData(file.getPath());
        Map attr = new HashMap();
        attr.put("path", file.getPath());
        attr.put("totalSpace", CommonUtils.formatterDiskSize(file.getTotalSpace()));
        attr.put("freeSpace", CommonUtils.formatterDiskSize(file.getFreeSpace()));
        treedata.setId(file.getPath());
        treedata.setAttributes(attr);
        listroots.add(treedata);
    }
    return listroots;
}

From source file:base.BasePlayer.AddGenome.java

static void downloadGenome(String urls) {
    try {//from www .j ava2s .c  o  m

        URL fastafile = AddGenome.genomeHash.get(urls)[0];
        String targetDir = "";
        //boolean writable = true;

        File test = new File(Main.genomeDir.getCanonicalPath() + "/test");

        //File f = new File(Main.genomeDir.getCanonicalPath());         

        if (test.mkdir()) {
            /*if(fastafile.getFile().contains("GRCh38")) {
                      
                  if((test.getFreeSpace()/1048576) < (60000000000L/1048576)) {
              Main.showError("Sorry, you need more than 60GB of disk space to install GRCh38.\nGRCh38 FASTA file size is ~50GB uncompressed.\nThis drive has " +test.getFreeSpace()/1048576/1000 +"GB.", "Note");
              test.delete();
              return;
                  }                                                    
               }
            else*/ if ((test.getFreeSpace() / 1048576) < (5000000000L / 1048576)) {
                Main.showError("Sorry, you need more than 5GB of disk space.\nThis drive has "
                        + test.getFreeSpace() / 1048576 / 1000 + "GB.", "Note");
                test.delete();
                return;
            }
            test.delete();

            targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/";
            File fasta = new File(targetDir + FilenameUtils.getName(fastafile.getFile()));
            URL gfffile = AddGenome.genomeHash.get(urls)[1];
            targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/annotation/"
                    + FilenameUtils.getName(gfffile.getFile()) + "/";
            File gff = new File(targetDir + FilenameUtils.getName(gfffile.getFile()));
            AddGenome.OutputRunner genomeadd = new AddGenome.OutputRunner(urls, fasta, gff, urls);
            genomeadd.createGenome = true;
            genomeadd.execute();
        } else {
            try {

                JFileChooser chooser = new JFileChooser();
                chooser.setAcceptAllFileFilterUsed(false);
                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                chooser.setDialogTitle("Select a local directory for genome files...");
                File outfile = null;

                while (true) {
                    int returnVal = chooser.showSaveDialog((Component) AddGenome.panel);

                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        outfile = chooser.getSelectedFile();
                        File genomedir = new File(outfile.getCanonicalPath() + "/genomes");
                        if (new File(outfile.getCanonicalPath() + "/genomes").mkdir()) {
                            if (fastafile.getFile().contains("GRCh38")) {
                                if ((outfile.getFreeSpace() / 1048576) < (200000000000L / 1048576)) {
                                    Main.showError(
                                            "Please, select local drive with more than 60GB of disk space.\nGRCh38 FASTA file is ~50GB uncompressed.\nThis drive has "
                                                    + outfile.getFreeSpace() / 1048576 / 1000 + "GB.",
                                            "Note");
                                    genomedir.delete();
                                    continue;
                                }
                            } else if ((outfile.getFreeSpace() / 1048576) < (5000000000L / 1048576)) {
                                Main.showError(
                                        "Please, select local drive with more than 5GB of disk space.\nThis drive has "
                                                + outfile.getFreeSpace() / 1048576 / 1000 + "GB.",
                                        "Note");
                                genomedir.delete();
                                continue;
                            }
                        } else {
                            Main.showError(
                                    "No writing permissions for this directory. \nPlease, select new directory for genomes.",
                                    "Error");
                            continue;
                        }

                        /*if (!new File(outfile.getCanonicalPath() +"/genomes").mkdir()) {
                           Main.showError("Could not create genome directory in " +outfile.getCanonicalPath(), "Error");
                           continue;
                        }*/

                        break;
                    }
                    if (returnVal == JFileChooser.CANCEL_OPTION) {
                        outfile = null;
                        downloading = false;
                        break;
                    }
                }
                if (outfile != null) {
                    Main.genomeDir = new File(outfile.getCanonicalPath() + "/genomes");
                    genomedirectory.setText(Main.genomeDir.getCanonicalPath());
                    Main.writeToConfig("genomeDir=" + Main.genomeDir.getCanonicalPath());
                    targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/";
                    File fasta = new File(targetDir + FilenameUtils.getName(fastafile.getFile()));
                    URL gfffile = AddGenome.genomeHash.get(urls)[1];
                    targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/annotation/"
                            + FilenameUtils.getName(gfffile.getFile()) + "/";
                    File gff = new File(targetDir + FilenameUtils.getName(gfffile.getFile()));
                    AddGenome.OutputRunner genomeadd = new AddGenome.OutputRunner(urls, fasta, gff, urls);
                    genomeadd.createGenome = true;
                    genomeadd.execute();
                }
                downloading = false;
                /* new File(outfile.getCanonicalPath() +"/genomes").mkdir();
                File fasta = new File(targetDir +FilenameUtils.getName(fastafile.getFile()));                     
                        
                URL gfffile= AddGenome.genomeHash.get(urls)[1];
                targetDir = AddGenome.userDir +"/genomes/" +urls +"/annotation/" +FilenameUtils.getName(gfffile.getFile()) +"/";
                File gff = new File(targetDir +FilenameUtils.getName(gfffile.getFile()));
                        
                AddGenome.OutputRunner genomeadd = new AddGenome.OutputRunner(urls, fasta, gff, urls);
                genomeadd.createGenome = true;
                genomeadd.execute();
                */
            } catch (Exception ex) {
                downloading = false;
                ex.printStackTrace();
            }

        }

    } catch (Exception e) {
        downloading = false;
        e.printStackTrace();
    }

}

From source file:net.sf.jvifm.ui.FileLister.java

private void generateOneItemForWinRoot(TableItem item, File file, int index) {
    item.setText(0, file.getPath().substring(0, 2));

    item.setText(1, StringUtil.formatSize(file.getTotalSpace()));
    item.setText(2, StringUtil.formatSize(file.getFreeSpace()));
    item.setImage(0, driveImage);/*w  w w  . j  a  v  a 2 s .  c  o m*/
    String selection = (String) historyManager.getSelectedItem(""); //$NON-NLS-1$
    if (file.getPath().equalsIgnoreCase(selection + File.separator)) {
        currentRow = index;
    }
}