Java Code Examples for org.openide.filesystems.FileObject.toURI()

The following are Jave code examples for showing how to use toURI() of the org.openide.filesystems.FileObject class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: QueriesCache.java   View Source Code Vote up 6 votes
@NonNull
@Override
protected List<? extends URI> getRootURIs() {
    final List<URI> result = new ArrayList<>(roots.length);
    for (FileObject root : roots) {
        final URI uri = root.toURI();
        if (uri != null) {
            result.add(uri);
        } else {
            LOG.log(
                Level.WARNING,
                "Cannot convert: {0} to URI.",  //NOI18N
                FileUtil.getFileDisplayName(root));
        }
    }
    return Collections.unmodifiableList(result);
}
 
Example 2
Project: incubator-netbeans   File: ProfileSupport.java   View Source Code Vote up 6 votes
@CheckForNull
Key createKey(@NonNull final URL rootURL) {
    final URL fileURL = FileUtil.getArchiveFile(rootURL);
    if (fileURL == null) {
        //Not an archive
        return null;
    }
    final FileObject fileFo = URLMapper.findFileObject(fileURL);
    if (fileFo == null) {
        return null;
    }
    return new Key(
        fileFo.toURI(),
        fileFo.lastModified().getTime(),
        fileFo.getSize());
}
 
Example 3
Project: incubator-netbeans   File: SimpleFileOwnerQueryImplementation.java   View Source Code Vote up 6 votes
/** @see FileOwnerQuery#markExternalOwner */
public static void markExternalOwnerTransient(URI root, Project owner) {
    externalRootsIncludeNonFolders |= !root.getPath().endsWith("/");
    if (owner != null) {
        FileObject fo = owner.getProjectDirectory();
        URI foUri = owner == FileOwnerQuery.UNOWNED ? UNOWNED_URI : fo.toURI();
        synchronized (cacheLock) {
            cacheInvalid = true;
            externalOwners.put(root, foUri);
            deserializedExternalOwners.remove(root);
        }
    } else {
        synchronized (cacheLock) {
            cacheInvalid = true;
            externalOwners.remove(root);
        }
    }
}
 
Example 4
Project: incubator-netbeans   File: SimpleFileOwnerQueryImplementation.java   View Source Code Vote up 5 votes
private static boolean hasRoot(
        @NonNull final Set<URI> extRoots,
        @NonNull final FileObject file,
        final boolean folder,
        @NonNull final URI[] furi) {
    if (extRoots.isEmpty() || !(folder || externalRootsIncludeNonFolders)) {
        return false;
    }
    furi[0] = file.toURI();
    return extRoots.contains(furi[0]);
}
 
Example 5
Project: incubator-netbeans   File: DataShadowTranslateTest.java   View Source Code Vote up 5 votes
/**
 * Checks that file with just regular characters in name is translated OK
 * @throws Exception 
 */
public void testRegularURI() throws Exception {
    
    FileObject fo = FileUtil.getConfigRoot();
    
    FileObject origDir = fo.createFolder("origFolder");
    FileObject newFile = origDir.createData("regularFileName.txt");
    
    final FileObject d = fo.createFolder("subfolder");
    OutputStream ostm = d.createAndOpen("regularShadowURI.shadow");
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(ostm));
    
    URI uri = newFile.toURI();
    String urlString = newFile.toURI().toString();
    bw.write(urlString + ".old");
    bw.newLine();
    bw.newLine();
    bw.close();
    
    FileObject fob = d.getFileObject("regularShadowURI.shadow");
    DataObject dd = DataObject.find(fob);
    
    assertTrue("Shadow must be translated, not broken", dd instanceof DataShadow);
    
    DataShadow ds = (DataShadow)dd;
    assertEquals("Shadow's original must be on the translated location", newFile, ds.getOriginal().getPrimaryFile());
}