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.geoserver.catalog.rest.StructuredCoverageStoresTest.java

@Test
public void testHarvestSingle() throws Exception {
    File file = movedFiles.get(0);
    File target = new File(mosaic, file.getName());
    assertTrue(file.renameTo(target));//from  w w w .  j a v  a  2 s .c  o  m

    URL url = DataUtilities.fileToURL(target.getCanonicalFile());
    String body = url.toExternalForm();
    MockHttpServletResponse response = postAsServletResponse(
            "/rest/workspaces/wcs/coveragestores/watertemp/external.imagemosaic", body, "text/plain");
    assertEquals(202, response.getStatusCode());

    Document dom = getAsDOM(
            "/rest/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml");
    // print(dom);
    assertXpathEvaluatesTo("3", "count(//gf:watertemp)", dom);
    assertXpathEvaluatesTo("1", "count(//gf:watertemp[gf:location = '" + file.getName() + "'])", dom);
}

From source file:org.broadinstitute.gatk.utils.io.IOUtilsUnitTest.java

@Test
public void testDottedSubDir() throws IOException {
    File subDir = IOUtils.absolute(new File("."), new File("path/../to/file"));
    Assert.assertEquals(subDir.getCanonicalFile(), new File("path/../to/./file").getCanonicalFile());

    subDir = IOUtils.absolute(new File("."), new File("/path/../to/file"));
    Assert.assertEquals(subDir, new File("/path/../to/file"));

    subDir = IOUtils.absolute(new File("/different/../path"), new File("path/to/file"));
    Assert.assertEquals(subDir, new File("/different/../path/path/to/file"));

    subDir = IOUtils.absolute(new File("/different/./path"), new File("/path/../to/file"));
    Assert.assertEquals(subDir, new File("/path/../to/file"));
}

From source file:com.fimagena.filepicker.FilePickerFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);/*from w  w  w  .  j a  v  a  2  s. com*/
    setRetainInstance(true);

    File mnt = new File("/storage");
    if (!mnt.exists())
        mnt = new File("/mnt");
    mFileSystemRoots = mnt.listFiles(new FileFilter() {
        @Override
        public boolean accept(File f) {
            try {
                File canon = (f.getParent() == null) ? f
                        : new File(f.getParentFile().getCanonicalFile(), f.getName());
                boolean isSymlink = !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
                return f.isDirectory() && f.exists() && f.canWrite() && !f.isHidden() && !isSymlink;
            } catch (Exception e) {
                return false;
            }
        }
    });

    mAdapter = new FileItemAdapter(this, mParams, mStartPath);
}

From source file:com.asakusafw.directio.hive.tools.cli.GenerateCreateTableTest.java

/**
 * parse minimum args.//from w  ww  .  j av  a  2s.  c  o  m
 * @throws Exception if failed
 */
@Test
public void parse_simple() throws Exception {
    File source = folder.newFolder();
    File output = folder.newFile();
    Configuration conf = parse(new String[] { "--classpath", source.getPath(), "--output", output.getPath(), });
    assertThat(conf.sources, hasSize(1));
    assertThat(conf.sources.get(0).getCanonicalFile(), is(source.getCanonicalFile()));
    assertThat(conf.output.getCanonicalFile(), is(output.getCanonicalFile()));
    assertThat(conf.classLoader, canLoad(source));
}

From source file:org.hyperic.hq.plugin.weblogic.WeblogicProductPlugin.java

public String[] getClassPath(ProductPluginManager manager) {
    Properties props = manager.getProperties();
    String installpath = props.getProperty(PROP_INSTALLPATH);

    //jaas is the default, provide a way to use jndi instead
    //just in case.
    String auth = props.getProperty("weblogic.auth.method", "jaas").toLowerCase();

    NEW_DISCOVERY = props.getProperty("weblogic.discovery.new", "false").equalsIgnoreCase("true");
    log.debug("[getClassPath] weblogic.discovery.new=" + NEW_DISCOVERY);

    usePlatformName = props.getProperty("weblogic.discover.pname", "false").equalsIgnoreCase("true");
    log.debug("[getClassPath] usePlatformName=" + usePlatformName);

    // SSL2WAYS CERTs
    ssl2ways_key = props.getProperty("weblogic.ssl2ways.key");
    ssl2ways_key_pass = props.getProperty("weblogic.ssl2ways.key.pass", "");
    ssl2ways_cert = props.getProperty("weblogic.ssl2ways.cert");
    //can't do jaas w/o login config
    final String loginConfig = "java.security.auth.login.config";

    if (System.getProperty(loginConfig) == null) { //cmdline PluginDumper
        String pdk = System.getProperty(ProductPluginManager.PROP_PDK_DIR);
        String config;//from   w w w.  ja v a 2 s. c om
        String configFile = "jaas.config";
        if (pdk != null) {
            config = pdk + "/../" + configFile;
        } else {
            config = configFile;
        }
        if (new File(config).exists()) {
            log.debug("-D" + loginConfig + "=" + config);
            System.setProperty(loginConfig, config);
        }
    }

    if ("jndi".equals(auth) || System.getProperty(loginConfig) == null) {
        useJAAS = false;
    } else if ("ssl2ways".equals(auth)) {
        useJAAS = false;
        ssl2ways = true;
    } else if (!"jaas".equals(auth)) {
        String msg = "Unsupported authentication method: " + auth;
        throw new IllegalArgumentException(msg);
    }

    //e.g. DB has SP2 and SP4 instances managed by 1 agent,
    //weblogic.servlet.internal.dd.ContainerDescriptor
    //serial UID is incompatible
    //XXX not working w/ 9.1, not sure why yet.
    //disabled by default for now.
    if ("true".equals(props.getProperty("weblogic.autort"))) {
        autoRT = true;
    }

    //XXX tmp ssl support solution
    for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        String key = (String) entry.getKey();
        if (!key.startsWith("weblogic.security.")) {
            continue;
        }

        System.setProperty(key, (String) entry.getValue());
    }

    String expire = props.getProperty(AttributeGetter.PROP_ATTR_EXPIRE);
    if (expire != null) {
        System.setProperty(AttributeGetter.PROP_ATTR_EXPIRE, expire);
    }

    //the jars relative to installpath
    String[] classpath = super.getClassPath(manager);

    if (installpath == null) {
        File path = null;

        //try the process table first
        if (path == null) {
            String dir = WeblogicDetector.getRunningInstallPath();

            if (dir != null) {
                path = new File(dir);
            }
        }

        //fallback to registry on win32 only
        if ((path == null) && isWin32()) {
            path = WeblogicFinder.getServiceInstallPath();
        }

        if (path == null) {
            return classpath; //can be adjusted later
        } else {
            installpath = path.getAbsolutePath();
            log.info(PROP_INSTALLPATH + " not set, defaulting to: " + installpath);
        }
    }

    //XXX ugh.  required for ssl to find license file.
    //weblogic tries to figure this stuff out based on classpath
    //which does not work with our plugin classloader.
    String wlHome = props.getProperty("weblogic.home", new File(installpath, "server").toString());
    System.setProperty("weblogic.home", wlHome);

    String beaHome = props.getProperty("bea.home", new File(installpath).getParentFile().toString());

    System.setProperty("bea.home", beaHome);

    File weblogicJar = new File(installpath, "lib/weblogic.jar");

    try {
        if (weblogicJar.getCanonicalFile().exists()) {
            //configured to use 6.1, jaas is not supported.
            useJAAS = false;
        }
    } catch (IOException e) {
    }

    for (int i = 0; i < classpath.length; i++) {
        File jar = new File(installpath, classpath[i]);
        if (jar.exists()) {
            classpath[i] = jar.getPath();
        }
    }

    return classpath;
}

From source file:net.morimekta.idltool.cmd.RemoteStatus.java

private String readFile(File file) throws IOException {
    try (FileInputStream fis = new FileInputStream(file.getCanonicalFile().getAbsoluteFile())) {
        return readString(new BufferedReader(new InputStreamReader(fis)));
    }//from   www  .  ja v  a2s  .c o  m
}

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

public FrameworkBootstrap(MutableClassLoader loader, File home) throws IOException {
    this.home = home.getCanonicalFile();
    this.loader = loader;
    initializeEnvironment();/*  w  ww. ja v a2 s  .  c o m*/
}

From source file:com.junoyoon.BullsHtml.java

private void buildSrcFileList(ArrayList<SrcFile> srcFileList, Element eachFolder, File baseDir) {
    try {/*from  ww w  .j  a v  a2 s. c o  m*/
        baseDir = baseDir.getCanonicalFile();
    } catch (IOException e) {
        BullsHtml.printErrorAndExit(e);
    }
    for (Object elementObject : eachFolder.getChildren()) {
        Element element = (Element) elementObject;
        String name = element.getName();
        if ("folder".equals(name)) {
            String newFolderName = element.getAttributeValue("name");
            File newFile = this.rootPathPattern.matcher(newFolderName).find() ? new File(newFolderName)
                    : new File(baseDir, newFolderName);
            buildSrcFileList(srcFileList, element, newFile);
        } else if ("src".equals(name)) {
            srcFileList.add(new SrcFile().init(baseDir, element));
        }
    }
}

From source file:org.geoserver.catalog.rest.DataStoreFileUploadTest.java

@Test
public void testShapeFileUploadNotExisting() throws Exception {
    File file = new File("./target/notThere.tiff");
    if (file.exists()) {
        assertTrue(file.delete());/*w w  w  .j a  v a 2s.c  o m*/
    }

    URL url = DataUtilities.fileToURL(file.getCanonicalFile());
    String body = url.toExternalForm();
    MockHttpServletResponse response = putAsServletResponse("/rest/workspaces/gs/datastores/pds/external.shp",
            body, "text/plain");
    assertEquals(400, response.getStatusCode());
}

From source file:org.eclipse.gemini.blueprint.test.provisioning.internal.MavenPackagedArtifactFinder.java

File findPackagedArtifact(File startingDirectory) throws IOException {
    if (!isMavenProjectDirectory(startingDirectory)) {
        throw new IllegalStateException(startingDirectory + " does not contain a pom.xml file");
    }// w  ww . j a  v a 2 s .c  o m
    File rootMavenProjectDir = findRootMavenProjectDir(startingDirectory.getCanonicalFile());
    if (log.isTraceEnabled())
        log.trace("Starting local artifact search from " + rootMavenProjectDir.getAbsolutePath());

    File found = findInDirectoryTree(artifactName, rootMavenProjectDir);
    if (found == null) {
        throw new FileNotFoundException(
                "Cannot find the artifact <" + artifactName + "> with groupId <" + groupId + ">");
    }
    return found;
}