Example usage for java.io File getCanonicalFile

List of usage examples for java.io File getCanonicalFile

Introduction

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

Prototype

public File getCanonicalFile() throws IOException 

Source Link

Document

Returns the canonical form of this abstract pathname.

Usage

From source file:org.gradle.util.GFileUtils.java

public static File canonicalise(File src) {
    try {//from   w w w .j  av  a2  s.  c om
        return src.getCanonicalFile();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.commonjava.web.config.io.ConfigFileUtils.java

private static List<File> listRecursively(final File dir) throws IOException {
    final List<File> files = new ArrayList<File>();
    final File d = dir.getCanonicalFile();

    recurse(d, files);/*from  ww w . j  ava2  s .co m*/

    return files;
}

From source file:com.sap.prd.mobile.ios.mios.FileUtils.java

static File getCanonicalFile(File f) throws IORuntimeException {
    try {/*from  w  ww  .  j  av  a  2 s .  co  m*/
        return f.getCanonicalFile();
    } catch (final IOException ex) {
        throw new IORuntimeException(ex.getMessage(), ex);
    }
}

From source file:org.nuxeo.osgi.application.StandaloneApplication.java

public static Environment createEnvironment() throws IOException {
    if (options != null) {
        String val = options.getOption("home");
        if (val == null) {
            val = System.getProperty(Environment.HOME_DIR);
            if (val == null) {
                val = ".";
            }//from  ww  w.j  a  v  a 2s. c o m
        }
        File home = new File(val);
        home = home.getCanonicalFile();
        Environment env = new Environment(home);
        env.setCommandLineArguments(args);
        val = options.getOption("data");
        if (val != null) {
            env.setData(new File(val).getCanonicalFile());
        }
        val = options.getOption("log");
        if (val != null) {
            env.setLog(new File(val).getCanonicalFile());
        }
        val = options.getOption("config");
        if (val != null) {
            env.setConfig(new File(val).getCanonicalFile());
        }
        val = options.getOption("web");
        if (val != null) {
            env.setWeb(new File(val).getCanonicalFile());
        }
        val = options.getOption("tmp");
        if (val != null) {
            env.setTemp(new File(val).getCanonicalFile());
        }
        val = options.getOption("bundles");
        if (val != null) {
            env.setPath(Environment.BUNDLES, new File(val).getCanonicalFile());
        }
        env.setHostApplicationName(Environment.NXSERVER_HOST);
        env.setHostApplicationVersion("1.0.0");
        env.getData().mkdirs();
        env.getLog().mkdirs();
        env.getTemp().mkdirs();
        return env;
    } else {
        return new Environment(new File("").getCanonicalFile());
    }
}

From source file:net.morimekta.idltool.IdlUtils.java

public static File findHomeDotCacheIdlTool(File cacheOverride) throws IOException {
    if (cacheOverride != null) {
        cacheOverride = cacheOverride.getCanonicalFile();
        if (cacheOverride.exists() && cacheOverride.isDirectory()) {
            return cacheOverride;
        }/* ww w .ja v  a2 s .  co  m*/
        throw new IOException("No such cache directory: " + cacheOverride.toString());
    }

    File home = new File(System.getenv("HOME")).getAbsoluteFile().getCanonicalFile();
    cacheOverride = new File(new File(home, ".cache"), "idltool");
    if (!cacheOverride.exists()) {
        if (!cacheOverride.mkdirs()) {
            throw new IOException("Unable to create RC directory: " + cacheOverride.toString());
        }
    }
    if (!cacheOverride.isDirectory()) {
        throw new IOException("RC location is not a directory: " + cacheOverride.toString());
    }
    return cacheOverride;
}

From source file:com.thoughtworks.go.util.FileUtil.java

public static boolean isChildOf(File parent, File subdirectory) throws IOException {
    File parentFile = parent.getCanonicalFile();
    File current = subdirectory.getCanonicalFile();
    return !current.equals(parentFile) && isSubdirectoryOf(parent, subdirectory);
}

From source file:org.optaconf.service.AbstractClientArquillianTest.java

private static File findPomFile() {
    File file = new File("pom.xml");
    if (!file.exists()) {
        throw new IllegalStateException("The file (" + file + ") does not exist.\n"
                + "This test needs to be run with the working directory " + POM_DIRECTORY_NAME + ".");
    }//ww w .ja v  a2s . c  o m
    try {
        file = file.getCanonicalFile();
    } catch (IOException e) {
        throw new IllegalStateException("Could not get cannonical file for file (" + file + ").", e);
    }
    if (!file.getParentFile().getName().equals(POM_DIRECTORY_NAME)) {
        throw new IllegalStateException("The file (" + file + ") is not correct.\n"
                + "This test needs to be run with the working directory " + POM_DIRECTORY_NAME + ".");
    }
    return file;
}

From source file:com.thoughtworks.go.util.FileUtil.java

public static boolean isSubdirectoryOf(File parent, File subdirectory) throws IOException {
    File parentFile = parent.getCanonicalFile();
    File current = subdirectory.getCanonicalFile();
    while (current != null) {
        if (current.equals(parentFile)) {
            return true;
        }/* ww  w.j a v  a2s.c o  m*/
        current = current.getParentFile();
    }
    return false;
}

From source file:net.rim.ejde.internal.model.BlackBerryVMInstallType.java

/**
 * Returns the default javadoc location specified in the properties or <code>null</code> if none.
 *
 * @param properties/*  ww  w.  j  ava  2s.  co  m*/
 *            properties map
 *
 * @return javadoc location specified in the properties or <code>null</code> if none
 */
public static URL getJavadocLocation(final Map properties) {
    final String javadoc = BlackBerryVMInstallType.getProperty(ExecutionEnvironmentDescription.JAVADOC_LOC,
            properties);
    if ((javadoc != null) && (javadoc.length() > 0)) {
        try {
            URL url = new URL(javadoc);
            if ("file".equalsIgnoreCase(url.getProtocol())) { //$NON-NLS-1$
                final File file = new File(url.getFile());
                url = file.getCanonicalFile().toURL();
            }
            return url;
        } catch (final MalformedURLException e) {
            BlackBerryVMInstallType.log.error("", e); //$NON-NLS-1$
            return null;
        } catch (final IOException e) {
            BlackBerryVMInstallType.log.error("", e); //$NON-NLS-1$
            return null;
        }
    }
    final String version = BlackBerryVMInstallType.getProperty(ExecutionEnvironmentDescription.LANGUAGE_LEVEL,
            properties);
    if (version != null)
        return StandardVMType.getDefaultJavadocLocation(version);
    return null;
}

From source file:org.apache.geode.internal.util.IOUtils.java

/**
 * This method attempts to get the canonical form of the specified file otherwise returns it's
 * absolute form.//from   w  ww. j  ava2s.c  o m
 * <p/>
 * 
 * @param file the java.io.File object who's canonical representation is attempted to be returned.
 * @return the canonical form of the specified File or the absolute form if an IOException occurs
 *         during the File.getCanonicalFile call.
 * @see java.io.File#getCanonicalFile()
 * @see java.io.File#getAbsoluteFile()
 */
public static File tryGetCanonicalFileElseGetAbsoluteFile(final File file) {
    try {
        return file.getCanonicalFile();
    } catch (IOException e) {
        return file.getAbsoluteFile();
    }
}