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:com.adaptris.core.fs.FsProducer.java

protected void addProducerMetadata(AdaptrisMessage msg, File destFile) throws IOException {
    File canonicalFile = destFile.getCanonicalFile();
    msg.addMetadata(PRODUCED_NAME_KEY, canonicalFile.getName());
    if (canonicalFile.getParentFile() != null) {
        msg.addMetadata(FS_PRODUCE_DIRECTORY, canonicalFile.getParentFile().getCanonicalPath());
    }/*from w  ww.  j a  v a 2s .c  o m*/
}

From source file:net.sf.fakenames.fddemo.BaseDirLayout.java

public void init() throws IOException {
    home = getBaseDir();/*w  ww  .  j av a  2s. c  o  m*/

    mountInfo = MountsSingleton.get(os);

    final HashMap<File, String> pathNameMap = new HashMap<>();

    File systemRoot = Environment.getRootDirectory();
    try {
        systemRoot = systemRoot.getCanonicalFile();
    } catch (IOException ignore) {
        // ok
    }
    pathNameMap.put(systemRoot, "Android system root");

    File filesDir = getFilesDir();
    try {
        filesDir = filesDir.getCanonicalFile();
    } catch (IOException ignore) {
        // ok
    }
    pathNameMap.put(filesDir, "Internal private storage");

    File[] external = ContextCompat.getExternalFilesDirs(this, null);
    for (int i = 0; i < external.length; ++i) {
        File resolved = external[i];

        if (resolved == null)
            continue;

        try {
            resolved = resolved.getCanonicalFile();
        } catch (IOException ignore) {
            // ok
        }
        pathNameMap.put(resolved, "External storage " + i);
    }

    List<StorageVolume> volumes = new ArrayList<>();
    if (Build.VERSION.SDK_INT >= 24) {
        final StorageManager sm = (StorageManager) getSystemService(STORAGE_SERVICE);
        volumes.addAll(sm.getStorageVolumes());
    }

    final Lock lock = mountInfo.getLock();
    lock.lock();
    try {
        parseMounts(pathNameMap, volumes);
    } finally {
        lock.unlock();
    }

}

From source file:uk.ac.ebi.aamtool.Helper.java

protected File generateImage(String canonicalRootPath, IReaction mappedReaction, String reactionID)
        throws Exception {
    File file = new File(canonicalRootPath);
    new ImageGenerator().drawLeftToRightReactionLayout(file, mappedReaction, reactionID);
    return new File(file.getCanonicalFile(), reactionID + ".png");
}

From source file:uk.ac.ebi.aamtool.Helper.java

protected File generateAAMImage(String canonicalRootPath, IReaction mappedReaction, String reactionID)
        throws Exception {
    File file = new File(canonicalRootPath);
    new ImageGenerator().drawTopToBottomReactionLayout(file, mappedReaction, reactionID);
    return new File(file.getCanonicalFile(), reactionID + ".png");
}

From source file:org.sonatype.nexus.proxy.storage.local.fs.DefaultFSLocalRepositoryStorageTest.java

@Test
public void getFileFromBaseOk() throws Exception {
    final File fileFromBase = subject.getFileFromBase(repository, new ResourceStoreRequest("/foo/bar"));
    assertThat(fileFromBase.getCanonicalFile(), equalTo(new File(baseDir, "foo/bar")));
}

From source file:org.openmrs.module.ModuleUtil.java

/**
 * Utility method to convert a {@link File} object to a local URL.
 *
 * @param file a file object// w w w .java2s.c  om
 * @return absolute URL that points to the given file
 * @throws MalformedURLException if file can't be represented as URL for some reason
 */
public static URL file2url(final File file) throws MalformedURLException {
    if (file == null) {
        return null;
    }
    try {
        return file.getCanonicalFile().toURI().toURL();
    } catch (MalformedURLException mue) {
        throw mue;
    } catch (IOException ioe) {
        throw new MalformedURLException("Cannot convert: " + file.getName() + " to url");
    } catch (NoSuchMethodError nsme) {
        throw new MalformedURLException("Cannot convert: " + file.getName() + " to url");
    }
}

From source file:org.debian.maven.plugin.InstallMojoTest.java

/**
 * Checks if the actual file is a link to the expected file.
 *//*from ww w  .j a  va 2 s . c o  m*/
private void assertSameFile(File expected, File actual) throws IOException {
    if (!System.getProperty("os.name").contains("Windows")) {
        assertEquals(expected, actual.getCanonicalFile());
    }
}

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

/**
 * scans directory and creates file with all files in directory
 * /*from w w  w.  ja  v  a 2  s .co m*/
 * @param aTarget
 * @param aParentDir
 * @throws IOException
 */
public void createZipFile(File aTarget, File aParentDir) throws IOException {
    ZipOutputStream zous = null;
    try {
        FileOutputStream fous = new FileOutputStream(aTarget);
        zous = new ZipOutputStream(fous);
        List<File> files = getFiles(aParentDir.getCanonicalFile());
        int dirLengh = aParentDir.getCanonicalPath().length();
        for (File file : files) {
            String substring = file.getPath().substring(dirLengh);
            /*
             * remove leading \ or /
             */
            if (substring.charAt(0) == '\\' || substring.charAt(0) == '/') {
                substring = substring.substring(1);
            }
            ZipEntry zipEntry = new ZipEntry(substring);
            zous.putNextEntry(zipEntry);
            FileInputStream fin = null;
            try {
                fin = new FileInputStream(file);
                IOUtils.copy(fin, zous);
            } finally {
                IOUtils.closeQuietly(fin);
            }
        }
    } finally {
        IOUtils.closeQuietly(zous);
    }
}

From source file:org.geoserver.opensearch.rest.CollectionLayerTest.java

@Before
public void setupTestCollectionAndProduct() throws IOException, Exception {
    // create the collection
    createTest123Collection();/* w w  w .  j a v  a  2s  .c om*/

    // create the product
    MockHttpServletResponse response = postAsServletResponse("rest/oseo/collections/TEST123/products",
            getTestData("/test123-product.json"), MediaType.APPLICATION_JSON_VALUE);
    assertEquals(201, response.getStatus());
    assertEquals("http://localhost:8080/geoserver/rest/oseo/collections/TEST123/products/TEST123_P1",
            response.getHeader("location"));

    // setup the base granule location
    File file = new File("./src/test/resources");
    resourceBase = file.getCanonicalFile().getAbsolutePath();
}

From source file:org.nuxeo.ecm.webengine.WebEngineComponent.java

@Override
public void activate(ComponentContext context) throws Exception {
    super.activate(context);

    String webDir = Framework.getProperty("org.nuxeo.ecm.web.root");
    File root = null;
    if (webDir != null) {
        root = new File(webDir);
    } else {//from  w w w  . ja  v  a  2 s . c  o  m
        root = new File(Framework.getRuntime().getHome(), "web");
    }
    root = root.getCanonicalFile();
    log.info("Using web root: " + root);

    engine = new WebEngine(new File(root, "root.war"));

    engine.start();
}