Java Code Examples for org.openide.filesystems.FileObject#getCanonicalFileObject()

The following examples show how to use org.openide.filesystems.FileObject#getCanonicalFileObject() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: netbeans   File: FileObjSymlinkTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test getCanonicalFileObject method.
 *
 * Use this directory tree:
 * <pre>
 * - workdir
 *   - a
 *     - data.dat
 *   - b
 *     - link.lnk (symlink to data.dat)
 *   - c
 *     - link2.lnk (symlink to link.link)
 *   - d
 *     - folderLink (symlink to c)
 * </pre>
 * @throws java.io.IOException
 */
public void testGetRealFileObject() throws IOException {
    if (!checkSymlinksSupported()) {
        return;
    }
    File dir = getWorkDir();
    File a = new File(dir, "a");
    File dataDat = new File(a, "data.dat");
    File b = new File(dir, "b");
    File linkLnk = new File(b, "link.lnk");
    File c = new File(dir, "c");
    File link2Lnk = new File(c, "link2.lnk");
    File d = new File(dir, "d");
    File folderLink = new File(d, "folderLink");
    a.mkdir();
    dataDat.createNewFile();
    b.mkdir();
    Files.createSymbolicLink(linkLnk.toPath(), dataDat.toPath());
    c.mkdir();
    Files.createSymbolicLink(link2Lnk.toPath(), linkLnk.toPath());
    d.mkdir();
    Files.createSymbolicLink(folderLink.toPath(), c.toPath());
    FileObject dirFO = FileUtil.toFileObject(dir);
    dirFO.refresh();
    FileObject fo = dirFO.getFileObject("d/folderLink/link2.lnk");
    assertNotNull(fo);
    FileObject realFO = fo.getCanonicalFileObject();
    assertNotNull(realFO);
    assertTrue(realFO.getPath().endsWith("a/data.dat"));
}
 
Example 2
Source Project: netbeans   File: FileObjectCrawler.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isSameFile(
        @NonNull final FileObject check,
        @NonNull final FileObject other) throws IOException {
    if (check.isSymbolicLink()) {
        FileObject otherReslved = other.getCanonicalFileObject();
        if (otherReslved == null) {
            otherReslved = other;
        }
        return otherReslved.equals(check.getCanonicalFileObject());
    }
    return false;
}