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.eclipse.ecr.runtime.deploy.ConfigurationDeployer.java

public void deploy(RuntimeContext ctx, File file, boolean trackChanges) throws Exception {
    _deploy(ctx, file.getCanonicalFile().toURI().toURL(), file, trackChanges);
}

From source file:com.fusesource.forge.jmstest.peristence.ProbeAwarePeristenceAdapter.java

public void init() {
    super.init();

    File dbFile = new File(getFileName());

    if (!dbFile.getAbsoluteFile().getParentFile().exists()) {
        try {/*from  ww w .  j  a  v a2  s . c  o  m*/
            dbFile.getCanonicalFile().mkdirs();
        } catch (IOException e) {
            log().error("Error creating Rrd4j file.", e);
        }
    }

    if (dbFile.exists()) {
        dbFile.delete();
    }

    log().debug("Persistence Adapter uses : " + dbFile.getAbsolutePath());
}

From source file:net.nicholaswilliams.java.licensing.encryption.TestFilePrivateKeyDataProvider.java

@Test
@Ignore("canRead()/canWrite() do not work on Win; setReadable()/setWritable() do not work on some Macs.")
public void testGetEncryptedPrivateKeyData02() throws IOException {
    final String fileName = "testGetEncryptedPrivateKeyData02.key";
    File file = new File(fileName);
    file = file.getCanonicalFile();

    if (file.exists())
        FileUtils.forceDelete(file);/*from w w  w .j a  va 2s  .  c o  m*/

    byte[] data = new byte[] { 0x01, 0x71, 0x33 };

    FileUtils.writeByteArrayToFile(file, data);

    try {
        assertTrue("Setting the file to not-readable should have succeeded.", file.setReadable(false, false));
        assertFalse("The file should not be readable.", file.canRead());
        assertTrue("The file should still be writable.", file.canWrite());

        FilePrivateKeyDataProvider provider = new FilePrivateKeyDataProvider(file);

        try {
            provider.getEncryptedPrivateKeyData();
            fail("Expected exception KeyNotFoundException.");
        } catch (KeyNotFoundException e) {
            assertNotNull("The cause should not be null.", e.getCause());
        }
    } finally {
        FileUtils.forceDelete(file);
    }
}

From source file:net.nicholaswilliams.java.licensing.encryption.TestFilePublicKeyDataProvider.java

@Test
@Ignore("canRead()/canWrite() do not work on Win; setReadable()/setWritable() do not work on some Macs.")
public void testGetEncryptedPublicKeyData02() throws IOException {
    final String fileName = "testGetEncryptedPublicKeyData02.key";
    File file = new File(fileName);
    file = file.getCanonicalFile();

    if (file.exists())
        FileUtils.forceDelete(file);//from  w w w .j a  va 2  s  .  c om

    byte[] data = new byte[] { 0x01, 0x71, 0x33 };

    FileUtils.writeByteArrayToFile(file, data);

    try {
        assertTrue("Setting the file to not-readable should have succeeded.", file.setReadable(false, false));
        assertFalse("The file should not be readable.", file.canRead());
        assertTrue("The file should still be writable.", file.canWrite());

        FilePublicKeyDataProvider provider = new FilePublicKeyDataProvider(file);

        try {
            provider.getEncryptedPublicKeyData();
            fail("Expected exception KeyNotFoundException.");
        } catch (KeyNotFoundException e) {
            assertNotNull("The cause should not be null.", e.getCause());
        }
    } finally {
        FileUtils.forceDelete(file);
    }
}

From source file:org.gradle.internal.resource.UriResource.java

private File canonicalise(File file) {
    try {//from  www. j a  v a 2s  .  c  o m
        return file.getCanonicalFile();
    } catch (IOException e) {
        return file.getAbsoluteFile();
    }
}

From source file:org.opendaylight.atrium.routingservice.config.ConfigReaderTest.java

/**
 * Tests whether the Config Reader is initialized
 *//*  www.  j  a v  a2 s  .com*/
@Test
public void testInitialize() throws MalformedURLException, IOException {
    File configFile = new File(DEFAULT_CONFIG_FILE);
    URL configFileUrl = configFile.getCanonicalFile().toURI().toURL();
    assertEquals(true, ConfigReader.initialize(configFileUrl));
}

From source file:org.mates.osb.ZipFile.java

/**
 * recursive scans directory/*  w  w w  .ja va  2s  .c om*/
 * 
 * @param aParent
 * @return
 * @throws IOException
 */
private List<File> getFiles(File aParent) throws IOException {
    List<File> files = new ArrayList<File>();
    for (File f : aParent.listFiles()) {
        if (f.isDirectory()) {
            files.addAll(getFiles(f));
        } else {
            files.add(f.getCanonicalFile());
        }
    }
    return files;
}

From source file:org.nuxeo.runtime.deploy.ConfigurationDeployer.java

public void deploy(RuntimeContext ctx, File file, boolean trackChanges) throws IOException {
    _deploy(ctx, file.getCanonicalFile().toURI().toURL(), file, trackChanges);
}

From source file:org.qedeq.base.io.IoUtility.java

/**
 * Copies a file to a different location.
 *
 * @param   from    Copy source.//  w w  w  . j  a  v a 2 s.  c  om
 * @param   to      Copy destination.
 * @throws  IOException File exception occurred.
 */
public static void copyFile(final File from, final File to) throws IOException {

    if (from.getCanonicalFile().equals(to.getCanonicalFile())) {
        return;
    }
    createNecessaryDirectories(to);
    FileInputStream in = null;
    FileOutputStream out = null;
    try {
        in = new FileInputStream(from);
        out = new FileOutputStream(to);

        byte[] data = new byte[8 * 1024];
        int length;
        while ((length = in.read(data)) != -1) {
            out.write(data, 0, length);
        }
    } finally {
        close(in);
        close(out);
    }
}

From source file:org.wso2.carbon.javaee.tomee.ASGlobalListenerSupport.java

/**
 * Borrowed from ClassloadingContextBuilder#getWebappFilePath private method
 * @return webapp file path/*from   ww  w . ja  va 2 s.com*/
 * @throws IOException
 */
private String getWebappFilePath(StandardContext ctx) throws IOException {
    String webappFilePath = null;

    //Value of the following variable depends on various conditions. Sometimes you get just the webapp directory
    //name. Sometime you get absolute path the webapp directory or war file.
    //        Context ctx = (Context) getContainer();
    String docBase = ctx.getDocBase();

    Host host = (Host) ctx.getParent();
    String appBase = host.getAppBase();
    File canonicalAppBase = new File(appBase);
    if (canonicalAppBase.isAbsolute()) {
        canonicalAppBase = canonicalAppBase.getCanonicalFile();
    } else {
        canonicalAppBase = new File(System.getProperty("carbon.home"), appBase).getCanonicalFile();
    }

    File webappFile = new File(docBase);
    if (webappFile.isAbsolute()) {
        webappFilePath = webappFile.getCanonicalPath();
    } else {
        webappFilePath = (new File(canonicalAppBase, docBase)).getPath();
    }
    return webappFilePath;
}