本文整理汇总了Java中org.openide.filesystems.FileSystem.findResource方法的典型用法代码示例。如果您正苦于以下问题:Java FileSystem.findResource方法的具体用法?Java FileSystem.findResource怎么用?Java FileSystem.findResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.filesystems.FileSystem
的用法示例。
在下文中一共展示了FileSystem.findResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFolderLookupIsUpdatedQuicklyForSubfolders
import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
/** Test of the lookup method. Creates files under different levels of directory
* hierarchy and tries to lookup it. The objects should be immediatelly found.
*
*/
public void testFolderLookupIsUpdatedQuicklyForSubfolders () throws Exception {
String fsstruct [] = new String [] {
"AA/",
};
TestUtilHid.destroyLocalFileSystem (getName());
FileSystem lfs = TestUtilHid.createLocalFileSystem (getWorkDir(), fsstruct);
FileObject bb = lfs.findResource("/AA");
assertNotNull(bb + " not found", bb);
DataFolder folder = DataFolder.findFolder (bb);
Lookup lookup = new org.openide.loaders.FolderLookup (folder).getLookup ();
checkTheLookupForSubfolders (lookup, folder);
}
示例2: testFindResourceDoesNotRefresh
import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
public void testFindResourceDoesNotRefresh() throws Exception {
FileObject fileObject1 = testFolder.createData("fileObject1");
FileObject[] arr = testFolder.getChildren();
assertEquals("One child", 1, arr.length);
assertEquals("Right child", fileObject1, arr[0]);
File testFile = FileUtil.toFile(testFolder);
assertNotNull("Folder File found", testFile);
final String path = testFolder.getPath() + "/file1.txt";
final FileSystem fs = testFolder.getFileSystem();
File newCh = new File(testFile, "file1.txt");
newCh.createNewFile();
FileObject fromResource = fs.findResource(path);
FileObject fromToFO = FileUtil.toFileObject(newCh);
FileObject fromSndResource = fs.findResource(path);
assertNotNull("toFileObject does refresh", fromToFO);
assertNull("fromResource does not refresh", fromResource);
assertEquals("after refresh the result reflects reality", fromToFO, fromSndResource);
}
示例3: testProxyLookups
import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
/** Tests delegation stuff.
*/
public void testProxyLookups () throws Exception {
String fsstruct [] = new String [] {
"AA/",
};
TestUtilHid.destroyLocalFileSystem (getName());
FileSystem lfs = TestUtilHid.createLocalFileSystem (getWorkDir(), fsstruct);
FileObject bb = lfs.findResource("/AA");
DataFolder folder = DataFolder.findFolder (bb);
Lookup lookup = new org.openide.loaders.FolderLookup (folder).getLookup ();
addListener(lookup);
InstanceDataObject obj = InstanceDataObject.create (folder, null, ALkp.class);
if (lookup.lookup (Integer.class) == null) {
fail ("Integer not found in delegating lookup");
}
}
示例4: testHandleDataShadow
import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
public void testHandleDataShadow() throws Exception {
String fsstruct [] = new String [] {
"AA/",
"BB/",
"BB/java-io-IOException.instance"
};
TestUtilHid.destroyLocalFileSystem (getName());
FileSystem lfs = TestUtilHid.createLocalFileSystem (getWorkDir(), fsstruct);
FileObject aa = lfs.findResource("/AA");
FileObject bb = lfs.findResource("/BB");
DataFolder a = DataFolder.findFolder (aa);
DataFolder b = DataFolder.findFolder (bb);
b.createShadow(a);
FolderLookup fl = new FolderLookup(b);
IOException io = fl.getLookup().lookup(IOException.class);
assertNotNull("IO Exception found", io);
}
示例5: testLocalFileSystemEx133616
import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
/** Simulates deadlock issue 133616
* - create MultiFileSystem
* - create lookup to set our MultiFileSystem and system filesystem
* - create handler to manage threads
* - put test FileObject to 'potentialLock' set
* - call hasLocks
* - it call LocalFileSystemEx.getInvalid which ends in our DeadlockHandler
* - it starts lockingThread which calls FileObject.lock which locks our FileObject
* - when we in LocalFileSystemEx.lock, we notify main thread which continues
* in getInvalid and tries to accuire lock on FileObject and it dead locks
*/
public void testLocalFileSystemEx133616() throws Exception {
System.setProperty("workdir", getWorkDirPath());
clearWorkDir();
FileSystem lfs = TestUtilHid.createLocalFileSystem("mfs1" + getName(), new String[]{"/fold/file1"});
LocalFileSystemEx exfs = new LocalFileSystemEx();
exfs.setRootDirectory(FileUtil.toFile(lfs.getRoot()));
FileSystem xfs = TestUtilHid.createXMLFileSystem(getName(), new String[]{});
FileSystem mfs = new MultiFileSystem(exfs, xfs);
testedFS = mfs;
Lookup l = Lookup.getDefault();
if (!(l instanceof Lkp)) {
fail("Wrong lookup: " + l);
}
((Lkp)l).init();
final FileObject file1FO = mfs.findResource("/fold/file1");
File file1File = FileUtil.toFile(file1FO);
Logger.getLogger(LocalFileSystemEx.class.getName()).setLevel(Level.FINEST);
Logger.getLogger(LocalFileSystemEx.class.getName()).addHandler(new DeadlockHandler(file1FO));
LocalFileSystemEx.potentialLock(file1FO.getPath());
LocalFileSystemEx.hasLocks();
}
示例6: getSupportedMimeTypes
import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
private static List<String> getSupportedMimeTypes () {
List<String> result = new ArrayList<String> ();
FileSystem fs = Repository.getDefault ().getDefaultFileSystem ();
FileObject root = fs.findResource ("Editors");
Enumeration e1 = root.getChildren (false);
while (e1.hasMoreElements ()) {
FileObject f1 = (FileObject) e1.nextElement ();
if (f1.isData ()) continue;
Enumeration e2 = f1.getChildren (false);
while (e2.hasMoreElements ()) {
FileObject f2 = (FileObject) e2.nextElement ();
if (f2.isData ()) continue;
FileObject fo = f2.getFileObject ("language.nbs");
if (fo == null) continue;
result.add (f1.getName () + '/' + f2.getName ());
}
}
return result;
}
示例7: testFolderLookupIsUpdatedQuickly
import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
/** Test of the lookup method. Creates a file under Services directory
* and tries to lookup it. The object should be immediatelly found.
*
*/
public void testFolderLookupIsUpdatedQuickly () throws Exception {
String fsstruct [] = new String [] {
"AA/",
};
TestUtilHid.destroyLocalFileSystem (getName());
FileSystem lfs = TestUtilHid.createLocalFileSystem (getWorkDir(), fsstruct);
FileObject bb = lfs.findResource("/AA");
DataFolder folder = DataFolder.findFolder (bb);
Lookup lookup = new org.openide.loaders.FolderLookup (folder).getLookup ();
try {
checkTheLookup (lookup, folder);
} finally {
folder.delete ();
}
}
示例8: find
import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
static FileObject find(URL url) {
if (!SourceFilesCache.URL_PROTOCOL.equals(url.getProtocol())) {
return null;
}
String host = url.getHost();
if (host == null) {
return null;
}
Matcher m = HOST.matcher(host);
if (!m.matches()) {
return null;
}
Reference<FileSystem> r;
synchronized (filesystems) {
r = filesystems.get(Long.parseLong(m.group(1)));
}
if (r == null) {
return null;
}
FileSystem fs = r.get();
if (fs == null) {
return null;
}
String path = url.getPath().substring(1);
path = percentDecode(path);
return fs.findResource(path);
}
示例9: deleteImpl
import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
private void deleteImpl (FileObject mfo, FileSystem fsLayer) throws IOException {
FileObject fo = fsLayer.findResource (mfo.getPath());
if (fo != null) {
FileLock lock = null;
try {
lock = fo.lock ();
fo.delete (lock);
} finally {
if (lock != null)
lock.releaseLock ();
}
}
}
示例10: attachNotifier
import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
/**
* @param mfo FileObject from default file system
* @param layer the layer where notifier will be searched on
* @return true if attached notifier is the delegate FO
*/
private synchronized boolean attachNotifier (FileObject mfo, int layer) {
FileSystem fsLayer = getLayer (layer);
String fn = mfo.getPath();
FileObject fo = null;
boolean isDelegate = true;
if (fsLayer == null)
return false;
// find new notifier - the FileObject with closest match to getFile ()
while (fn.length () > 0 && null == (fo = fsLayer.findResource (fn))) {
int pos = fn.lastIndexOf ('/');
isDelegate = false;
if (-1 == pos)
break;
fn = fn.substring (0, pos);
}
if (fo == null)
fo = fsLayer.getRoot ();
if (fo != notifiers [layer]) {
// remove listener from existing notifier if any
if (notifiers [layer] != null)
notifiers [layer].removeFileChangeListener (weakL [layer]);
// create new listener and attach it to new notifier
weakL [layer] = FileUtil.weakFileChangeListener (this, fo);
fo.addFileChangeListener (weakL [layer]);
notifiers [layer] = fo;
}
return isDelegate;
}
示例11: testExternalFileReads
import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
public void testExternalFileReads() throws Exception {
Layer l = new Layer("<file name='x' url='x.txt'/>", Collections.singletonMap("x.txt", "stuff"));
FileSystem fs = l.read();
FileObject x = fs.findResource("x");
assertNotNull(x);
assertTrue(x.isData());
assertEquals(5L, x.getSize());
assertEquals("stuff", x.asText("UTF-8"));
assertEquals("x.txt", x.getAttribute("WritableXMLFileSystem.url"));
assertEquals("[" + l.f.toURL() + "]", Arrays.toString((URL[]) x.getAttribute("layers")));
fs = new Layer("<file name='x' url='subdir/x.txt'/>", Collections.singletonMap("subdir/x.txt", "more stuff")).read();
x = fs.findResource("x");
assertNotNull(x);
assertEquals("more stuff", x.asText("UTF-8"));
}
示例12: testURLAttr
import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
/** #150902 - test spaces in url attribute are escaped to get valid URL. */
public void testURLAttr() throws Exception {
FileSystem fs = new Layer("<file name='x' url='A B C.txt'/>", Collections.singletonMap("A B C.txt", "stuff")).read();
FileObject x = null;
try {
x = fs.findResource("x");
assertNotNull(x);
assertEquals(5L, x.getSize());
} catch (Exception e) {
e.printStackTrace();
fail("url attribute with spaces in path wrongly handled.");
}
}
示例13: testDeleteReplaceAttributes
import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
public void testDeleteReplaceAttributes() throws Exception {
Layer l = new Layer(
" <file name=\"x\">\n" +
" <attr name=\"foo\" stringvalue=\"bar\"/>\n" +
" </file>\n");
FileSystem fs = l.read();
FileObject x = fs.findResource("x");
x.setAttribute("foo", Boolean.TRUE);
assertEquals("replaced attr",
" <file name=\"x\">\n" +
" <attr name=\"foo\" boolvalue=\"true\"/>\n" +
" </file>\n",
l.write());
x.setAttribute("foo", null);
assertEquals("deleted attr",
" <file name=\"x\"/>\n",
l.write());
x.setAttribute("foo", null);
assertEquals("cannot delete attr twice",
" <file name=\"x\"/>\n",
l.write());
/* Now this stores x/y=false instead... OK?
fs.getRoot().createData("y");
fs.getRoot().setAttribute("x/y", Boolean.TRUE);
fs.getRoot().setAttribute("x/y", null);
assertEquals("deleted ordering attr",
" <file name=\"x\"/>\n" +
" <file name=\"y\"/>\n",
l.write());
*/
}
示例14: findFileObject
import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
@Deprecated
private static FileObject findFileObject(String path) {
for (FileSystem fileSystem : getFileSystems()) {
FileObject retval = fileSystem.findResource(path);
if (retval != null) {
return retval;
}
}
return null;
}
示例15: isOnLayer
import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
private boolean isOnLayer (FileObject mfo, int layer) {
FileSystem fsLayer = getLayer (layer);
return fsLayer == null ? false : null != fsLayer.findResource (mfo.getPath());
}