当前位置: 首页>>代码示例>>Java>>正文


Java FileSystem.getRoot方法代码示例

本文整理汇总了Java中org.openide.filesystems.FileSystem.getRoot方法的典型用法代码示例。如果您正苦于以下问题:Java FileSystem.getRoot方法的具体用法?Java FileSystem.getRoot怎么用?Java FileSystem.getRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openide.filesystems.FileSystem的用法示例。


在下文中一共展示了FileSystem.getRoot方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testGetInputStream

import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
/**
 * Test of getInputStream method, of class org.netbeans.modules.masterfs.filebasedfs.fileobjects.FolderObj.
 */
public void testGetInputStream() {
    File f = testFile;
    FileSystem fs = FileBasedFileSystem.getInstance();
    
    FileObject root = fs.getRoot();
    assertNotNull(root);
    
    Enumeration<? extends FileObject> en = root.getFolders(true);
    for (int i = 0; i < 10 && en.hasMoreElements(); i++) {
        FileObject fo = (FileObject) en.nextElement();
        assertTrue(fo.isFolder());
        assertFalse(fo.isData());
        try {
            fo.getInputStream();
            fail ();
        } catch (FileNotFoundException e) {
            
        }

    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:FolderObjTest.java

示例2: testGetOutputStream

import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
/**
 * Test of getOutputStream method, of class org.netbeans.modules.masterfs.filebasedfs.fileobjects.FolderObj.
 */
public void testGetOutputStream() {
    File f = testFile;
    FileSystem fs = FileBasedFileSystem.getInstance();
    
    FileObject root = fs.getRoot();
    assertNotNull(root);
    
    Enumeration<? extends FileObject> en = root.getFolders(true);
    for (int i = 0; i < 10 && en.hasMoreElements(); i++) {
        FileObject fo = (FileObject) en.nextElement();
        assertTrue(fo.isFolder());
        assertFalse(fo.isData());
        try {
            fo.getOutputStream(fo.lock());
            fail ();
        } catch (IOException e) {
            
        } finally {
            
        }

    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:FolderObjTest.java

示例3: testNaturalComparator

import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
private void testNaturalComparator(String[] fileNames,
        String[] expectedOrder) throws IOException {
    FolderComparator c = new FolderComparator(FolderComparator.NATURAL);
    FileSystem fs = FileUtil.createMemoryFileSystem();
    FileObject root = fs.getRoot();
    List<DataObject> list = new ArrayList<DataObject>();
    for (String n : fileNames) {
        FileObject fo = root.createData(n);
        assertNotNull(fo);
        list.add(DataObject.find(fo));
    }

    Collections.sort(list, c);
    for (int i = 0; i < expectedOrder.length; i++) {
        assertEquals(expectedOrder[i], list.get(i).getName());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:FolderComparatorTest.java

示例4: testFolderOrder

import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
public void testFolderOrder() throws Exception {
    Layer l = new Layer("");
    FileSystem fs = l.read();
    FileObject r = fs.getRoot();
    FileObject a = r.createData("a");
    FileObject b = r.createData("b");
    FileObject f = r.createFolder("f");
    FileObject c = f.createData("c");
    FileObject d = f.createData("d");
    FileObject e = f.createData("e");
    DataFolder.findFolder(r).setOrder(new DataObject[] {DataObject.find(a), DataObject.find(b)});
    DataFolder.findFolder(f).setOrder(new DataObject[] {DataObject.find(c), DataObject.find(d), DataObject.find(e)});
    assertEquals("correct ordering XML",
            "    <file name=\"a\">\n" +
            "        <attr name=\"position\" intvalue=\"100\"/>\n" +
            "    </file>\n" +
            "    <file name=\"b\">\n" +
            "        <attr name=\"position\" intvalue=\"200\"/>\n" +
            "    </file>\n" +
            "    <folder name=\"f\">\n" +
            "        <file name=\"c\">\n" +
            "            <attr name=\"position\" intvalue=\"100\"/>\n" +
            "        </file>\n" +
            "        <file name=\"d\">\n" +
            "            <attr name=\"position\" intvalue=\"200\"/>\n" +
            "        </file>\n" +
            "        <file name=\"e\">\n" +
            "            <attr name=\"position\" intvalue=\"300\"/>\n" +
            "        </file>\n" +
            "    </folder>\n",
            l.write());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:WritableXMLFileSystemTest.java

示例5: testRemoveAttr

import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
public void testRemoveAttr() throws Exception { // #199189
    Layer l = new Layer("");
    FileSystem fs = l.read();
    FileObject r = fs.getRoot();
    FileObject f = r.createData("f");
    f.setAttribute("a", "v");
    assertEquals("    <file name=\"f\">\n        <attr name=\"a\" stringvalue=\"v\"/>\n    </file>\n", l.write());
    FileSystem mfs = new MultiFileSystem(fs);
    f = mfs.findResource("f");
    f.setAttribute("a", null);
    assertEquals("    <file name=\"f\"/>\n", l.write());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:WritableXMLFileSystemTest.java

示例6: prepareTest

import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
private void prepareTest(String code) throws Exception {
    FileSystem fs = FileUtil.createMemoryFileSystem();
    FileObject root = fs.getRoot();
    testFile = FileUtil.createData(root, "test/test.java");
    
    TestUtilities.copyStringToFile(testFile, code);
    
    DataObject od = DataObject.find(testFile);
    
    ces = (CloneableEditorSupport) od.getCookie(EditorCookie.class);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:ModificationResultTest.java

示例7: init

import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
final void init(FileSystem systemFileSystem) throws IOException {
    if (Boolean.getBoolean("org.netbeans.core.startup.ModuleSystem.CULPRIT")) Thread.dumpStack(); // NOI18N
    PropertyChangeListener l = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
            if (ModuleManager.PROP_CLASS_LOADER.equals(ev.getPropertyName())) {
                org.netbeans.core.startup.MainLookup.systemClassLoaderChanged(mgr.getClassLoader());
            }
        }
    };
    mgr.addPropertyChangeListener(l);
    
    // now initialize to core/* classloader, later we reassign to all modules
    org.netbeans.core.startup.MainLookup.systemClassLoaderChanged(installer.getClass ().getClassLoader ());
    // #28465: initialize module lookup early
    org.netbeans.core.startup.MainLookup.moduleLookupReady(mgr.getModuleLookup());
    if (systemFileSystem.isReadOnly()) {
        list = null;
    } else {
        FileObject root = systemFileSystem.getRoot();
        FileObject modulesFolder = root.getFileObject("Modules"); // NOI18N
        if (modulesFolder == null) {
            modulesFolder = root.createFolder("Modules"); // NOI18N
        }
        list = new ModuleList(mgr, modulesFolder, ev);
        installer.registerList(list);
        installer.registerManager(mgr);
    }
    ev.log(Events.CREATED_MODULE_SYSTEM);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:ModuleSystem.java

示例8: 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:FileStateManager.java

示例9: testOneItemList

import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
public void testOneItemList() throws IOException {
    FileSystem fs = FileUtil.createMemoryFileSystem();
    FileObject fsRoot = fs.getRoot();
    
    FileObject dir = fsRoot.createFolder("dir");
    dir.createData("a", DummyDataLoader.dummyExt);
    dir.createData("b", DummyDataLoader.dummyExt);
    dir.createData("c", DummyDataLoader.dummyExt);
    DataFolder folder = DataFolder.findFolder(dir);
    
    
    SearchInfo refSearchInfo;
    SearchInfo testSearchInfo;
    Iterator refIt;
    Iterator testIt;

    Set testSet = new HashSet();
    
    refSearchInfo = new SimpleSearchInfo(folder, false, null);
    testSearchInfo = new CompoundSearchInfo(new SearchInfo[] {refSearchInfo});
    assertTrue(testSearchInfo.canSearch());
    
    for(testIt = testSearchInfo.objectsToSearch(); testIt.hasNext();){
        testSet.add(testIt.next());
    }
    refIt = refSearchInfo.objectsToSearch();
    while (refIt.hasNext()) {
        assertTrue(testSet.remove(refIt.next()));
    }
    assertTrue(testSet.isEmpty());

    refSearchInfo = new SimpleSearchInfo(folder, false, null) {
        public boolean canSearch() {
            return false;
        }
    };
    testSearchInfo = new CompoundSearchInfo(new SearchInfo[] {refSearchInfo});
    assertEquals(refSearchInfo.canSearch(), testSearchInfo.canSearch());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:CompoundSearchInfoTest.java

示例10: testOneItemFilesList

import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
public void testOneItemFilesList() throws IOException {
    FileSystem fs = FileUtil.createMemoryFileSystem();
    FileObject fsRoot = fs.getRoot();

    FileObject dir = fsRoot.createFolder("dir");
    dir.createData("a", DummyDataLoader.dummyExt);
    dir.createData("b", DummyDataLoader.dummyExt);
    dir.createData("c", DummyDataLoader.dummyExt);
    DataFolder folder = DataFolder.findFolder(dir);

    SearchInfo.Files refSearchInfo;
    SearchInfo.Files testSearchInfo;
    Iterator refIt;
    Iterator testIt;
    Set testSet = new HashSet();

    refSearchInfo = new SimpleSearchInfo(folder, false, null);
    testSearchInfo = new CompoundSearchInfo(new SearchInfo[] {refSearchInfo});
    assertTrue(testSearchInfo.canSearch());

    for(testIt = testSearchInfo.filesToSearch(); testIt.hasNext();){
        testSet.add(testIt.next());
    }
    refIt = refSearchInfo.filesToSearch();
    while (refIt.hasNext()) {
        assertTrue(testSet.remove(refIt.next()));
    }
    assertTrue(testSet.isEmpty());

    refSearchInfo = new SimpleSearchInfo(folder, false, null) {
        public boolean canSearch() {
            return false;
        }
    };
    testSearchInfo = new CompoundSearchInfo(new SearchInfo[] {refSearchInfo});
    assertEquals(refSearchInfo.canSearch(), testSearchInfo.canSearch());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:CompoundSearchInfoTest.java

示例11: createDocuments

import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
protected Document[] createDocuments(String... fileName) {
    try {
        List<Document> docs = new ArrayList<>();
        FileSystem memFS = FileUtil.createMemoryFileSystem();
        for (String fName : fileName) {

            //we may also create folders
            StringTokenizer items = new StringTokenizer(fName, "/");
            FileObject fo = memFS.getRoot();
            while(items.hasMoreTokens()) {
                String item = items.nextToken();
                if(items.hasMoreTokens()) {
                    //folder
                    fo = fo.createFolder(item);
                } else {
                    //last, create file
                    fo = fo.createData(item);
                }
                assertNotNull(fo);
            }
            
            DataObject dobj = DataObject.find(fo);
            assertNotNull(dobj);

            EditorCookie cookie = dobj.getCookie(EditorCookie.class);
            assertNotNull(cookie);

            Document document = (Document) cookie.openDocument();
            assertEquals(0, document.getLength());

            docs.add(document);

        }
        return docs.toArray(new Document[]{});
    } catch (Exception ex) {
        throw new IllegalStateException("Error setting up tests", ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:TestBase.java

示例12: testDuplicateRandomTest

import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
public void testDuplicateRandomTest() throws IOException {
    if (!RUN_RANDOM_TESTS) {
        return;
    }
    final FileSystem fs = FileUtil.createMemoryFileSystem();
    String[] paths = generateRandomTree(TREE_DEPTH,TREE_CHILD_COUNT);
    FileObject root = fs.getRoot();
    populateFolderStructure(root, paths);
    Random r = new Random(System.currentTimeMillis());
    for (int runCount=0; runCount<TEST_COUNT; runCount++) {
        System.out.println("Run: " + runCount);
        final Set<FileObject> testSet = new HashSet<FileObject>();
        while (testSet.size() < SINGLE_TEST_SET_SIZE) {
            final String s = paths[r.nextInt(paths.length)];
            FileObject fo = root.getFileObject(s);
            final int shift = r.nextInt(TREE_DEPTH);
            for (int i = 0; i<shift; i++) {
                fo = fo.getParent();
            }
            testSet.add(fo);
        }
        FileObjectCrawler crawler = new FileObjectCrawler(
            root,
            testSet.toArray(new FileObject[testSet.size()]),
            EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE),
            null,
            CR,
            SuspendSupport.NOP);
        assertCollectedFiles(
                "Wrong files collected for: " + testSet,
                crawler.getResources(),
                crawl(testSet, root));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:FileObjectCrawlerTest.java

示例13: findFileObjectsInRepository

import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
private FileObject[] findFileObjectsInRepository(File f) {
    if (!f.equals(FileUtil.normalizeFile(f))) {
        throw new IllegalArgumentException(
            "Parameter file was not " + // NOI18N
            "normalized. Was " + f + " instead of " + FileUtil.normalizeFile(f)
        ); // NOI18N
    }

    @SuppressWarnings("deprecation") // keep for backward compatibility w/ NB 3.x
    Enumeration<? extends FileSystem> en = Repository.getDefault().getFileSystems();
    List<FileObject> list = new LinkedList<FileObject>();
    String fileName = f.getAbsolutePath();

    while (en.hasMoreElements()) {
        FileSystem fs = en.nextElement();
        String rootName = null;
        FileObject fsRoot = fs.getRoot();
        File root = findFileInRepository(fsRoot);

        if (root == null) {
            Object rootPath = fsRoot.getAttribute("FileSystem.rootPath"); //NOI18N

            if ((rootPath != null) && (rootPath instanceof String)) {
                rootName = (String) rootPath;
            } else {
                continue;
            }
        }

        if (rootName == null) {
            rootName = root.getAbsolutePath();
        }

        /**root is parent of file*/
        if (fileName.indexOf(rootName) == 0) {
            String res = fileName.substring(rootName.length()).replace(File.separatorChar, '/');
            FileObject fo = fs.findResource(res);
            File file2Fo = (fo != null) ? findFileInRepository(fo) : null;
            if ((fo != null) && (file2Fo != null) && f.equals(file2Fo)) {
                list.add(fo);
            }
        }
    }
    FileObject[] results = new FileObject[list.size()];
    list.toArray(results);
    return results;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:48,代码来源:BinaryUsagesTest.java


注:本文中的org.openide.filesystems.FileSystem.getRoot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。