Example usage for java.io File getAbsoluteFile

List of usage examples for java.io File getAbsoluteFile

Introduction

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

Prototype

public File getAbsoluteFile() 

Source Link

Document

Returns the absolute form of this abstract pathname.

Usage

From source file:ezbake.deployer.impl.LocalFileArtifactWriter.java

@Override
public void deleteArtifact(DeploymentMetadata metadata) throws DeploymentException {
    File artifact = new File(buildFilePath(metadata));
    if (artifact.exists()) {
        artifact.delete();//from ww  w  .  j ava 2  s .c  om
    } else {
        log.warn("File {} didn't exist to delete", artifact.getAbsoluteFile());
    }
}

From source file:adams.core.io.ZipUtils.java

/**
 * Unzips the files in a ZIP file. Files can be filtered based on their
 * filename, using a regular expression (the matching sense can be inverted).
 *
 * @param input   the ZIP file to unzip/*from  w  w  w.j a v a  2  s  .c  o m*/
 * @param outputDir   the directory where to store the extracted files
 * @param createDirs   whether to re-create the directory structure from the
 *          ZIP file
 * @param match   the regular expression that the files are matched against
 * @param invertMatch   whether to invert the matching sense
 * @param bufferSize   the buffer size to use
 * @param errors   for storing potential errors
 * @return      the successfully extracted files
 */
@MixedCopyright(copyright = "Apache compress commons", license = License.APACHE2, url = "http://commons.apache.org/compress/examples.html")
public static List<File> decompress(File input, File outputDir, boolean createDirs, BaseRegExp match,
        boolean invertMatch, int bufferSize, StringBuilder errors) {
    List<File> result;
    ZipFile archive;
    Enumeration<ZipArchiveEntry> enm;
    ZipArchiveEntry entry;
    File outFile;
    String outName;
    byte[] buffer;
    BufferedInputStream in;
    BufferedOutputStream out;
    FileOutputStream fos;
    int len;
    String error;
    long read;

    result = new ArrayList<>();
    archive = null;
    try {
        // unzip archive
        buffer = new byte[bufferSize];
        archive = new ZipFile(input.getAbsoluteFile());
        enm = archive.getEntries();
        while (enm.hasMoreElements()) {
            entry = enm.nextElement();

            if (entry.isDirectory() && !createDirs)
                continue;

            // does name match?
            if (!match.isMatchAll() && !match.isEmpty()) {
                if (invertMatch && match.isMatch(entry.getName()))
                    continue;
                else if (!invertMatch && !match.isMatch(entry.getName()))
                    continue;
            }

            // extract
            if (entry.isDirectory() && createDirs) {
                outFile = new File(outputDir.getAbsolutePath() + File.separator + entry.getName());
                if (!outFile.mkdirs()) {
                    error = "Failed to create directory '" + outFile.getAbsolutePath() + "'!";
                    System.err.println(error);
                    errors.append(error + "\n");
                }
            } else {
                in = null;
                out = null;
                fos = null;
                outName = null;
                try {
                    // assemble output name
                    outName = outputDir.getAbsolutePath() + File.separator;
                    if (createDirs)
                        outName += entry.getName();
                    else
                        outName += new File(entry.getName()).getName();

                    // create directory, if necessary
                    outFile = new File(outName).getParentFile();
                    if (!outFile.exists()) {
                        if (!outFile.mkdirs()) {
                            error = "Failed to create directory '" + outFile.getAbsolutePath() + "', "
                                    + "skipping extraction of '" + outName + "'!";
                            System.err.println(error);
                            errors.append(error + "\n");
                            continue;
                        }
                    }

                    // extract data
                    in = new BufferedInputStream(archive.getInputStream(entry));
                    fos = new FileOutputStream(outName);
                    out = new BufferedOutputStream(fos, bufferSize);
                    read = 0;
                    while (read < entry.getSize()) {
                        len = in.read(buffer);
                        read += len;
                        out.write(buffer, 0, len);
                    }
                    result.add(new File(outName));
                } catch (Exception e) {
                    error = "Error extracting '" + entry.getName() + "' to '" + outName + "': " + e;
                    System.err.println(error);
                    errors.append(error + "\n");
                } finally {
                    FileUtils.closeQuietly(in);
                    FileUtils.closeQuietly(out);
                    FileUtils.closeQuietly(fos);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        errors.append("Error occurred: " + e + "\n");
    } finally {
        if (archive != null) {
            try {
                archive.close();
            } catch (Exception e) {
                // ignored
            }
        }
    }

    return result;
}

From source file:com.javacreed.apps.mail.Model.java

public void loadComposer(final File currentComposerFile) throws IOException, ClassNotFoundException {
    this.currentComposerFile = currentComposerFile.getAbsoluteFile();
    composer = Composer.readFromFile(currentComposerFile);
    variablesTableModel.setVariables(composer.getVariablesNames());
}

From source file:io.gravitee.gateway.services.localregistry.LocalApiDefinitionRegistry.java

private void initRegistry(File registryDir) {
    LOGGER.info("Loading API definitions from {}", registryDir.getAbsoluteFile());
    File[] definitionFiles = searchForDefinitions(registryDir);

    LOGGER.info("\t{} API definitions have been found.", definitionFiles.length);

    for (File definitionFile : definitionFiles) {
        try {//from  w  w  w. java 2s .  c om
            Api api = loadDefinition(definitionFile);
            apiManager.deploy(api);
            definitions.put(Paths.get(definitionFile.toURI()), api);
        } catch (IOException e) {
            LOGGER.error("Unable to load API definition from {}", definitionFile, e);
        }
    }
}

From source file:com.athena.chameleon.engine.threadpool.task.RegularFileDependencyCheckTask.java

public RegularFileDependencyCheckTask(File file, String rootPath, Policy policy,
        AnalyzeDefinition analyzeDefinition) {
    this(file.getAbsoluteFile() + " Dependency Check Task", file, rootPath, policy, analyzeDefinition);
}

From source file:net.leegorous.jsc.JSC.java

private void addClasspath(JsContextManager mgr, String rootPath, String cp) {
    if (cp == null)
        return;/*from www  .  j a va  2s  .c o  m*/
    List classpath = (List) cpMap.get(cp);
    if (classpath != null)
        return;
    List cps = normalizePath(cp);
    List result = new ArrayList();
    for (Iterator it = cps.iterator(); it.hasNext();) {
        String str = (String) it.next();
        File f = new File(getRealPath("/" + str));
        if (f.exists()) {
            mgr.addClasspath(f);
            result.add(f.getAbsoluteFile());
            continue;
        }
        String path = FilenameUtils.concat(rootPath, str);
        mgr.addClasspath(path);
        result.add(path);
    }
    cpMap.put(cp, result);
}

From source file:com.github.ithildir.liferay.mobile.go.GoSDKBuilder.java

protected void copyResource(String name, String destination) throws IOException {

    File destinationDir = new File(destination);

    destinationDir = new File(destinationDir.getAbsoluteFile(), CharPool.SLASH + name);

    URL sourceURL = getClass().getResource(CharPool.SLASH + name);
    URLConnection sourceConnection = sourceURL.openConnection();

    if (sourceConnection instanceof JarURLConnection) {
        copyJarResource((JarURLConnection) sourceConnection, destinationDir);
    } else {/*from w  ww.  j  a  v  a 2s .com*/
        File sourceDir = new File(sourceURL.getPath());

        FileUtils.copyDirectory(sourceDir, destinationDir);
    }

    Iterator<File> itr = FileUtils.iterateFiles(destinationDir, new String[] { "copy" }, true);

    while (itr.hasNext()) {
        File file = itr.next();

        String cleanPath = FilenameUtils.removeExtension(file.getAbsolutePath());

        File cleanFile = new File(cleanPath);

        if (!cleanFile.exists()) {
            FileUtils.moveFile(file, new File(cleanPath));
        } else {
            file.delete();
        }
    }
}

From source file:com.liferay.mobile.sdk.windows.WindowsSDKBuilder.java

protected void copyResource(String name, String destination) throws IOException {

    File destinationDir = new File(destination);

    destinationDir = destinationDir.getAbsoluteFile();

    URL sourceURL = getClass().getResource(CharPool.SLASH + name);
    URLConnection sourceConnection = sourceURL.openConnection();

    if (sourceConnection instanceof JarURLConnection) {
        copyJarResource((JarURLConnection) sourceConnection, destinationDir);
    } else {// ww  w  . j a  v  a  2s  . c  o m
        File sourceDir = new File(sourceURL.getPath());

        FileUtils.copyDirectory(sourceDir, destinationDir);
    }

    Iterator<File> itr = FileUtils.iterateFiles(destinationDir, new String[] { "copy" }, true);

    while (itr.hasNext()) {
        File file = itr.next();

        String cleanPath = FilenameUtils.removeExtension(file.getAbsolutePath());

        File cleanFile = new File(cleanPath);

        if (!cleanFile.exists()) {
            FileUtils.moveFile(file, new File(cleanPath));
        } else {
            file.delete();
        }
    }
}

From source file:com.rabidgremlin.legalbeagle.maven.MavenJarIdentifier.java

public void identifyFiles(Report report) throws Exception {

    for (ReportItem reportItem : report.getReportItems()) {
        File f = reportItem.getFile();

        String fileHash = DigestUtils.sha1Hex(new FileInputStream(f));

        try {//www  .  ja v  a2  s  .  c o m
            log.info("Processing {}...", f.getAbsoluteFile());

            Model mod = httpHelper.getPom(fileHash);

            if (mod != null) {
                reportItem.setReportItemStatus(ReportItemStatus.IDENTIFIED);
                reportItem.setDescription(mod.getName());

                List<License> licenses = getLicense(httpHelper, mod);
                if (licenses != null) {
                    for (License license : licenses) {
                        // some names have spaces and CR or LF in them
                        String licenseStr = license.getName().trim();
                        licenseStr = StringUtils.strip(licenseStr, "\n\r");

                        reportItem.addLicense(licenseStr);
                    }
                } else {
                    reportItem.setReportItemStatus(ReportItemStatus.NO_LICENSE_FOUND);
                }

            } else {
                reportItem.setReportItemStatus(ReportItemStatus.NOT_IDENTIFIED);
            }
        } catch (Exception e) {
            reportItem.setReportItemStatus(ReportItemStatus.ERR);
            reportItem.setError(e.getMessage());
        }

    }

}

From source file:com.cyberway.issue.io.WriterPool.java

public void invalidateFile(WriterPoolMember f) throws IOException {
    try {//from  w  w  w  .java2  s .c  om
        this.pool.invalidateObject(f);
    } catch (Exception e) {
        // Convert exception.
        throw new IOException(e.getMessage());
    }
    // It'll have been closed.  Rename with an '.invalid' suffix so it
    // gets attention.
    File file = f.getFile();
    file.renameTo(new File(file.getAbsoluteFile() + WriterPoolMember.INVALID_SUFFIX));
}