當前位置: 首頁>>代碼示例>>Java>>正文


Java FileUtil類代碼示例

本文整理匯總了Java中org.openide.filesystems.FileUtil的典型用法代碼示例。如果您正苦於以下問題:Java FileUtil類的具體用法?Java FileUtil怎麽用?Java FileUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FileUtil類屬於org.openide.filesystems包,在下文中一共展示了FileUtil類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testFindResourceDoesNotRefresh

import org.openide.filesystems.FileUtil; //導入依賴的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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:ExternalTouchTest.java

示例2: actionPerformed

import org.openide.filesystems.FileUtil; //導入依賴的package包/類
public void actionPerformed(ActionEvent e) {
    if ( browseButton == e.getSource() ) {
        FileObject fo=null;
        // Show the browse dialog 
        if (getPanel().getSourceGroups()!=null) fo = BrowseFolders.showDialog(
                getPanel().getSourceGroups(),
                org.openide.loaders.DataFolder.class,
                folderTextField.getText().replace( File.separatorChar, '/' ) );
        else {                 
            Sources sources = ProjectUtils.getSources(getPanel().getProject());
            fo = BrowseFolders.showDialog( sources.getSourceGroups( 
                    Sources.TYPE_GENERIC ),DataFolder.class,
                    folderTextField.getText().replace( File.separatorChar, '/' ) );
        }
        
        if ( fo != null && fo.isFolder() ) {
            FileObject root = ((LocationItem)locationCB.getSelectedItem()).
                getFileObject();
            folderTextField.setText( FileUtil.getRelativePath( root, fo ) );
        }
                    
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:TargetChooserPanelGUI.java

示例3: testFullCodeTemplatesLegacyLayout

import org.openide.filesystems.FileUtil; //導入依賴的package包/類
public void testFullCodeTemplatesLegacyLayout() throws Exception {
    String [] files = new String [] {
        "Editors/Defaults/abbreviations.xml",
        "Editors/abbreviations.xml",
    };
    
    LocatorTest.createOrderedFiles(files, CT_CONTENTS);
    
    FileObject baseFolder = FileUtil.getConfigFile("Editors");
    Map<String, List<Object []>> results = new HashMap<String, List<Object []>>();
    LocatorTest.scan(CodeTemplatesStorage.ID, baseFolder, null, null, true, true, true, results);
    
    assertNotNull("Scan results should not null", results);
    assertEquals("Wrong number of profiles", 1, results.size());
    
    List<Object []> profileFiles = results.get(null);
    LocatorTest.checkProfileFiles(files, null, profileFiles, null);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:CodeTemplatesLocatorTest.java

示例4: testFailTwice

import org.openide.filesystems.FileUtil; //導入依賴的package包/類
public void testFailTwice() throws Exception {
    FileObject template = FileUtil.createData(root, "some.txt");
    OutputStream os = template.getOutputStream();
    String txt = "<html><h1>${unknown}</h1></html>";
    os.write(txt.getBytes());
    os.close();

    StringWriter w1 = new StringWriter();
    TestFailTemplateExceptionHandler tfeh1 = new TestFailTemplateExceptionHandler();
    apply(template, w1, tfeh1);

    StringWriter w2 = new StringWriter();
    TestFailTemplateExceptionHandler tfeh2 = new TestFailTemplateExceptionHandler();
    apply(template, w2, tfeh2);

    String expText = "Expression unknown is undefined on line 1, column 13 in some.txt.";
    String exp = "<html><h1>"+expText+"</h1></html>";
    assertEquals(exp, w1.toString());
    assertEquals(exp, w2.toString());

    assertNotNull("An expected exception was reported:", tfeh1.getExceptions());
    assertEquals("Just two exception reported:", 2, tfeh1.getExceptions().size());
    assertEquals("The expected exception was reported:", expText, tfeh1.getExceptions().get(0).getMessage());
    assertEquals("The expected exception was reported:", expText, tfeh1.getExceptions().get(1).getMessage());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:ProcessorTest.java

示例5: testFindCommonPathObject

import org.openide.filesystems.FileUtil; //導入依賴的package包/類
public void testFindCommonPathObject() throws IOException {
        
        FileObject root = FileUtil.createMemoryFileSystem().getRoot();
        
        FileObject a = root.createFolder("a");
        FileObject b = a.createFolder("b");
        FileObject c = b.createData("c");
        
        FileObject b1 = a.createFolder("b1");
        FileObject b1c = b1.createData("b1c");
        
//        SpecialSearchGroup.CommonSearchRoot csr = new SpecialSearchGroup.CommonSearchRoot(1);
//
//        csr.update(c);
//        csr.update(b1c);
//
//        assertEquals(a, csr.getFileObject());
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:SpecialSearchGroupTest.java

示例6: testOperationActions

import org.openide.filesystems.FileUtil; //導入依賴的package包/類
public void testOperationActions() throws Exception { // #72397
    final NbModuleProject project = generateStandaloneModule("module");
    cgpi.setProject(project);
    DialogDisplayerImpl dd = (DialogDisplayerImpl) Lookup.getDefault().lookup(DialogDisplayer.class);
    FileObject lock = FileUtil.createData(project.getProjectDirectory(), "build/testuserdir/lock");
    RandomAccessFile raf = new RandomAccessFile(FileUtil.toFile(lock), "rw");
    FileLock lck = raf.getChannel().lock();
    EventQueue.invokeAndWait(new Runnable() {
        @Override public void run() {
            ((ContextAwareAction) CommonProjectActions.deleteProjectAction()).createContextAwareInstance(Lookups.singleton(project)).actionPerformed(null);
        }
    });
    assertNotNull("warning message emitted", dd.getLastNotifyDescriptor());
    assertEquals("warning message emitted", dd.getLastNotifyDescriptor().getMessage(),
            Bundle.ERR_ModuleIsBeingRun());
    dd.reset();
    lck.release();
    raf.close();
    lock.delete();
    EventQueue.invokeAndWait(new Runnable() {
        @Override public void run() {
            CommonProjectActions.deleteProjectAction().actionPerformed(null);
        }
    });
    assertNull("no warning message", dd.getLastNotifyDescriptor());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:ModuleOperationsTest.java

示例7: setUp

import org.openide.filesystems.FileUtil; //導入依賴的package包/類
@Override
protected void setUp() throws Exception {
    super.setUp();
    MockMimeLookup.setLookup(MimePath.get(MIME),
        Lookups.fixed(
            new FooEmbeddingProviderFactory(),
            new FooParserFactory()));
    FileUtil.setMIMEType(EXT, MIME);
    file1 = FileUtil.toFileObject(TestFileUtils.writeFile(
        new File(getWorkDir(),"test1.foo"),  //NOI18N
        FILE_CONTENT));
    file2 = FileUtil.toFileObject(TestFileUtils.writeFile(
        new File(getWorkDir(),"test2.foo"),  //NOI18N
        FILE_CONTENT+FILE_CONTENT));
    setBigFileSize(FILE_CONTENT.length());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:SnapshotSizeTest.java

示例8: getOrderedResolvers

import org.openide.filesystems.FileUtil; //導入依賴的package包/類
/** Lists registered MIMEResolver instances in reverse order,
 * i.e. first are ones with lower priority (position attribute higher)
 * and last are ones with highest prority (position attribute lower).
 * @return list of all registered MIMEResolver instances in reverse order
 */
public static Collection<? extends FileObject> getOrderedResolvers() {
    // scan resolvers and order them to be able to assign extension to mime type from resolver with the lowest position
    FileObject[] resolvers = FileUtil.getConfigFile(MIME_RESOLVERS_PATH).getChildren();
    TreeMap<Integer, FileObject> orderedResolvers = new TreeMap<Integer, FileObject>(Collections.reverseOrder());
    for (FileObject mimeResolverFO : resolvers) {
        Integer position = (Integer) mimeResolverFO.getAttribute("position");  //NOI18N
        if (position == null) {
            position = Integer.MAX_VALUE;
        }
        while (orderedResolvers.containsKey(position)) {
            position--;
        }
        orderedResolvers.put(position, mimeResolverFO);
    }
    return orderedResolvers.values();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:MIMEResolverImpl.java

示例9: browseButtonActionPerformed

import org.openide.filesystems.FileUtil; //導入依賴的package包/類
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    String command = evt.getActionCommand();
    if ("BROWSE".equals(command)) {
        JFileChooser chooser = new JFileChooser();
        FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
        chooser.setDialogTitle("Select Project Location");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        String path = this.projectLocationTextField.getText();
        if (path.length() > 0) {
            File f = new File(path);
            if (f.exists()) {
                chooser.setSelectedFile(f);
            }
        }
        if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
            File projectDir = chooser.getSelectedFile();
            projectLocationTextField.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath());
        }
        panel.fireChangeEvent();
    }

}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:23,代碼來源:ExampleBotProjectPanelVisual.java

示例10: setUp

import org.openide.filesystems.FileUtil; //導入依賴的package包/類
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    dir = FileUtil.toFileObject(getWorkDir());
    f1 = dir.createData("f1.java");
    f2 = dir.createData("f2.java");
    f3 = dir.createData("f3.properties");
    f4 = dir.createData("f4.xml");          
    d1 = DataObject.find(f1);
    d2 = DataObject.find(f2);
    d3 = DataObject.find(f3);
    d4 = DataObject.find(f4);
    
    my = new MyHandler();
    Logger.getLogger("org.netbeans.ui.actions").addHandler(my);
    Logger.getLogger("org.netbeans.ui.actions").setLevel(Level.FINE);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:LookupSensitiveActionUILogTest.java

示例11: create

import org.openide.filesystems.FileUtil; //導入依賴的package包/類
private HashSet<DependencyWrapper> create(Set<Artifact> arts, boolean longLiving, Function<Artifact, Boolean> accept) {
    HashSet<DependencyWrapper> lst = new HashSet<>();
    for (Artifact a : arts) {
        if (accept.apply(a)) {
            URL url = FileUtil.urlForArchiveOrDir(a.getFile());
            String name = url != null ? SourceUtils.getModuleName(url) : null;
            if(name != null) {
                LOG.log(Level.FINE, "Artifact {0} has module name ''{1}''", new Object[]{url, name}); // NOI18N
                lst.add(new DependencyWrapper(a, longLiving, () -> moduleInfoSupport != null ? moduleInfoSupport.canAddToModuleInfo(name) : false));
            } else {
                LOG.log(Level.WARNING, "Could not determine module name for artifact {0}", new Object[]{url}); // NOI18N
            }
        }
    }
    return lst;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:DependenciesNode.java

示例12: testFullFontsColorsLegacyLayout

import org.openide.filesystems.FileUtil; //導入依賴的package包/類
public void testFullFontsColorsLegacyLayout() throws Exception {
    String [] files = new String [] {
        "Editors/NetBeans/Defaults/defaultColoring.xml",
        "Editors/NetBeans/Defaults/coloring.xml",
        "Editors/NetBeans/Defaults/editorColoring.xml",
        "Editors/NetBeans/coloring.xml",
        "Editors/NetBeans/editorColoring.xml",
    };
    
    createOrderedFiles(files, FC_CONTENTS);
    
    FileObject baseFolder = FileUtil.getConfigFile("Editors");
    Map<String, List<Object []>> results = new HashMap<>();
    scan(ColoringStorage.ID, baseFolder, null, null, true, true, true, results);
    
    assertNotNull("Scan results should not null", results);
    assertEquals("Wrong number of profiles", 1, results.size());
    
    List<Object []> profileFiles = results.get("NetBeans");
    checkProfileFiles(files, null, profileFiles, "NetBeans");
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:LocatorTest.java

示例13: takeHeapdumpHit

import org.openide.filesystems.FileUtil; //導入依賴的package包/類
private String takeHeapdumpHit(long time) {
        try {
            File heapdumpFile = constructHeapDumpFile(time);

            if (heapdumpFile.exists()) {
                File fixedHeapdumpFile = constructHeapDumpFile(Utils.getTimeInMillis(time));
                heapdumpFile.renameTo(fixedHeapdumpFile);
                FileObject folder = FileUtil.toFileObject(fixedHeapdumpFile.getParentFile());
                SnapshotsWindow.instance().refreshFolder(folder, true);
//                if (ProfilerControlPanel2.hasDefault())
//                    ProfilerControlPanel2.getDefault().refreshSnapshotsList();

                return fixedHeapdumpFile.toURI().toURL().toExternalForm();
            }
        } catch (IOException ex) {
            ErrorManager.getDefault().notify(ErrorManager.ERROR, ex);

            return Bundle.TakeSnapshotProfilingPoint_NoDataAvailableMsg();
        }

        return Bundle.TakeSnapshotProfilingPoint_NoDataAvailableMsg();
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:TakeSnapshotProfilingPoint.java

示例14: saveAs

import org.openide.filesystems.FileUtil; //導入依賴的package包/類
@Override
public void saveAs(FileObject folder, String fileName) throws IOException {
    String fn = FileUtil.getFileDisplayName(folder) + File.separator + fileName; 
    File existingFile = FileUtil.normalizeFile(new File(fn));
    if (existingFile.exists()) {
        NotifyDescriptor confirm = new NotifyDescriptor.Confirmation(
                NbBundle.getMessage(SQLEditorSupport.class,
                "MSG_ConfirmReplace", fileName),
                NbBundle.getMessage(SQLEditorSupport.class,
                "MSG_ConfirmReplaceFileTitle"),
                NotifyDescriptor.YES_NO_OPTION);
        DialogDisplayer.getDefault().notify(confirm);
        if (!confirm.getValue().equals(NotifyDescriptor.YES_OPTION)) {
            return;
        }
    }
    if (isConsole()) {
        // #166370 - if console, need to save document before copying
        saveDocument();
    }
    super.saveAs(folder, fileName);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:SQLEditorSupport.java

示例15: testAutomaticDependenciesUnused

import org.openide.filesystems.FileUtil; //導入依賴的package包/類
public void testAutomaticDependenciesUnused() throws Exception {
    List<URL> urls = new ArrayList<URL>();
    for (FileObject kid : FileUtil.getConfigFile("ModuleAutoDeps").getChildren()) {
        urls.add(kid.toURL());
    }
    StringBuilder problems = new StringBuilder();
    AutomaticDependencies ad = AutomaticDependencies.parse(urls.toArray(new URL[urls.size()]));
    for (Manifest m : loadManifests()) {
        String cnb = findCNB(m);
        AutomaticDependencies.Report r = ad.refineDependenciesAndReport(cnb,
                Dependency.create(Dependency.TYPE_MODULE, m.getMainAttributes().getValue("OpenIDE-Module-Module-Dependencies")));
        if (r.isModified()) {
            problems.append('\n').append(r);
        }
    }
    if (problems.length() > 0) {
        fail("Some modules need to upgrade their dependencies" + problems);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:ValidateModulesTest.java


注:本文中的org.openide.filesystems.FileUtil類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。