本文整理汇总了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);
}
示例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 ) );
}
}
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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();
}
示例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();
}
}
示例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);
}
示例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;
}
示例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");
}
示例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();
}
示例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);
}
示例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);
}
}