本文整理了Java中org.openide.filesystems.FileUtil
类的一些代码示例,展示了FileUtil
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil
类的具体详情如下:
包路径:org.openide.filesystems.FileUtil
类名称:FileUtil
[英]Common utilities for handling files. This is a dummy class; all methods are static.
[中]处理文件的常用工具。这是一个虚拟类;所有方法都是静态的。
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
/**
* Returns a FileObject representing an archive file containing the
* FileObject given by the parameter.
* <strong>Remember</strong> that any path within the archive is discarded
* so you may need to check for non-root entries.
* @param fo a file in a JAR filesystem
* @return the file corresponding to the archive itself,
* or null if <code>fo</code> is not an archive entry
* @since 4.48
*/
public static FileObject getArchiveFile(FileObject fo) {
Parameters.notNull("fo", fo); //NOI18N
try {
FileSystem fs = fo.getFileSystem();
if (fs instanceof JarFileSystem) {
File jarFile = ((JarFileSystem) fs).getJarFile();
return toFileObject(jarFile);
}
} catch (FileStateInvalidException e) {
Exceptions.printStackTrace(e);
}
return null;
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
FileObject newUserDefinedFO = null;
try {
FileObject resolversFolder = FileUtil.getConfigFile(MIME_RESOLVERS_PATH);
if (resolversFolder == null) {
resolversFolder = FileUtil.createFolder(FileUtil.getConfigRoot(), MIME_RESOLVERS_PATH);
newUserDefinedFO = resolversFolder.createData(USER_DEFINED_MIME_RESOLVER, "xml"); //NOI18N
newUserDefinedFO.setAttribute(USER_DEFINED_MIME_RESOLVER, Boolean.TRUE);
newUserDefinedFO.setAttribute("position", USER_DEFINED_MIME_RESOLVER_POSITION); //NOI18N
os = newUserDefinedFO.getOutputStream();
XMLUtil.write(document, os, "UTF-8"); //NOI18N
} catch (IOException e) {
ERR.log(Level.SEVERE, "Cannot write resolver " + (newUserDefinedFO == null ? "" : FileUtil.toFile(newUserDefinedFO)), e); //NOI18N
} finally {
if (os != null) {
os.close();
} catch (IOException e) {
ERR.log(Level.SEVERE, "Cannot close OutputStream of file " + (newUserDefinedFO == null ? "" : FileUtil.toFile(newUserDefinedFO)), e); //NOI18N
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
void locateCurrent() {
FileObject oldCurrent = current;
currentF = FileUtil.normalizeFile(path);
while (true) {
current = FileUtil.toFileObject(currentF);
if (current != null) {
isOnTarget = path.equals(currentF);
break;
}
currentF = currentF.getParentFile();
if (currentF == null) {
// #47320: can happen on Windows in case the drive does not exist.
// (Inside constructor for Holder.) In that case skip it.
return;
}
}
assert current != null;
if (current != oldCurrent) {
if (oldCurrent != null) {
oldCurrent.removeFileChangeListener(this);
}
current.addFileChangeListener(this);
current.getChildren(); //to get events about children
}
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
private static FileSystem getDiskFileSystemFor(File... files) {
FileSystem fs = getDiskFileSystem();
if (fs == null) {
for (File file : files) {
FileObject fo = toFileObject(file);
fs = getDiskFileSystem();
if (fs != null) {
break;
}
}
}
return fs;
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
FileObject folderFo = FileUtil.toFileObject(folder);
assert folderFo != null : folder.getAbsolutePath();
final String relativePath = getRelativePath(folder, data);
try {
retval = FileUtil.createData(folderFo,relativePath);
} catch (IOException ex) {
if (retval == null || !retval.isValid()) {
folderFo.getFileSystem().refresh(false);
retval = FileUtil.createData(folderFo,relativePath);
代码示例来源:origin: nl.cloudfarming.client/import
@Override
public void run() {
LOGGER.log(Level.FINEST, "ImportWorker: starting import for selected file {0}", file.getAbsolutePath());
// search for available processor
for (ImportProcessor importProcessor : Lookup.getDefault().lookupAll(ImportProcessor.class)) {
FileObject fo = FileUtil.toFileObject(file);
if (fo != null && importProcessor.isSupported(fo)) {
LOGGER.log(Level.FINEST, "ImportWorker: Processor found for file {0}", importProcessor.toString());
try {
DataObject dataObject = DataObject.find(fo);
ImportSource source = dataObject.getLookup().lookup(ImportSource.class);
if (source != null) {
importProcessor.doImport(fo, context);
}else{
LOGGER.log(Level.FINEST, "Data object {0} for file {1} did not contain an import source", new Object[]{dataObject.toString(), fo.toString()});
}
} catch (DataObjectNotFoundException ex) {
Exceptions.printStackTrace(ex);
}
break;
}
}
}
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
private static Lookup[] computeDelegates(String p, List<FOItem> items, Lookup lkp) {
FileObject fo = FileUtil.getConfigFile(p);
List<Lookup> delegates = new LinkedList<Lookup>();
delegates.add(lkp);
if (fo != null) {
for (FileObject f : fo.getChildren()) {
if (f.isFolder()) {
delegates.add(new OverFiles(f.getPath()));
} else {
if (f.hasExt("shadow")) {
Object real = f.getAttribute("originalFile"); // NOI18N
if (real instanceof String) {
f = FileUtil.getConfigFile((String)real);
ClassLoader l = Lookup.getDefault().lookup(ClassLoader.class);
if (l == null) {
l = Thread.currentThread().getContextClassLoader();
代码示例来源:origin: org.gephi/desktop-recent-files
@Override
public void actionPerformed(ActionEvent e) {
FileObject fileObject = FileUtil.toFileObject(file);
if (fileObject.hasExt(GEPHI_EXTENSION)) {
ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
try {
pc.openProject(file);
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
} else {
ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
if (importController.getImportController().isFileSupported(file)) {
importController.importFile(fileObject);
}
}
}
});
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base
FileObject doCreateFromTemplate(FileObject template, JavaFileObject sourceFile) throws IOException {
FileObject scratchFolder = FileUtil.createMemoryFileSystem().getRoot();
String name = FileObjects.getName(sourceFile, false);
if (template == null) {
return FileUtil.createData(scratchFolder, name);
}
FileObjectFromTemplateCreator creator = Lookup.getDefault().lookup(FileObjectFromTemplateCreator.class);
if (creator == null) {
return FileUtil.createData(scratchFolder, name);
}
File pack = BaseUtilities.toFile(sourceFile.toUri()).getParentFile();
while (FileUtil.toFileObject(pack) == null) {
pack = pack.getParentFile();
}
FileObject targetFolder = FileUtil.toFileObject(pack);
scratchFolder.setAttribute(FileObjectFromTemplateCreator.ATTR_ORIG_FILE, targetFolder);
return creator.create(template, scratchFolder, name);
}
代码示例来源:origin: AlexFalappa/nb-springboot
@Override
public void readSettings(WizardDescriptor wiz) {
try {
final Project project = Templates.getProject(wiz);
NbMavenProject nbProj = project.getLookup().lookup(NbMavenProject.class);
final URI[] resources = nbProj.getResources(false);
File resourceFolder = FileUtil.normalizeFile(FileUtil.archiveOrDirForURL(resources[0].toURL()));
File addMeta = new File(resourceFolder, "META-INF/additional-spring-configuration-metadata.json");
if (addMeta.exists()) {
wiz.putProperty(WizardDescriptor.PROP_WARNING_MESSAGE, "Existing additional metadata file will be overwritten!");
}
} catch (Exception ex) {
Exceptions.printStackTrace(Exceptions.attachSeverity(ex, Level.WARNING));
}
getComponent().read(wiz);
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
/** Converts the file to be writable.
* The file has to be locked!
*
* @return file object (new leader) that is writable
* @exception IOException if the object cannot be writable
*/
private FileObject writable(boolean copyContents) throws IOException {
MultiFileSystem fs = getMultiFileSystem();
FileSystem single = fs.createWritableOn(getPath());
if (single != leader.getFileSystem()) {
// if writing to a file that is not on writable fs =>
// copy it
if (leader.isFolder()) {
leader = FileUtil.createFolder(root(single), getPath());
} else {
FileObject folder = FileUtil.createFolder(root(single), getParent().getPath());
if (copyContents) {
leader = leader.copy(folder, leader.getName(), leader.getExt());
} else {
leader = folder.createData(leader.getNameExt());
}
}
MfLock l = ((lock == null) ? null : lock.get());
if (l != null) {
// update the lock
l.addLock(leader);
}
}
return leader;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-makeproject
public static FileProxy createAbsolute(Project project, String path) {
FileObject projectFO = project.getProjectDirectory();
File projectFile = FileUtil.toFile(projectFO);
if (projectFile == null) {
try {
return new FileProxyFileObject(projectFO.getFileSystem().getRoot(), path);
} catch (FileStateInvalidException ex) {
Exceptions.printStackTrace(ex);
// I don't know how this is possible; but to avoid NPE let's return FileProxyFile
return new FileProxyFile(new File(path));
}
} else {
return new FileProxyFile(new File(path));
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-grailsproject
@Override
protected boolean enable(Node[] activatedNodes) {
if (activatedNodes.length == 0) {
return false;
}
DataObject dataObject = activatedNodes[0].getLookup().lookup(DataObject.class);
if (dataObject == null || dataObject.getFolder() == null) {
return false;
}
Project prj = FileOwnerQuery.getOwner(dataObject.getFolder().getPrimaryFile());
if (prj == null) {
return false;
}
FileObject domainDir = prj.getProjectDirectory().getFileObject(DOMAIN_DIR);
if (domainDir == null) {
return false;
}
return FileUtil.isParentOf(domainDir, dataObject.getPrimaryFile());
}
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-project-ui
@Override public String getName() {
if (parent != null) {
DataObject d = getLookup().lookup(DataObject.class);
if (d != null) {
final String relName = FileUtil.getRelativePath(parent.getPrimaryFile(), d.getPrimaryFile());
//Null after DO move.
if (relName != null) {
return relName.replace('/', '.'); //NOI18N
}
}
}
return super.getName();
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-refactoring
private String getTargetPackageName(FileObject fo){
String newPackageName = RefactoringUtil.getPackageName(move.getTarget().lookup(URL.class));
String postfix = FileUtil.getRelativePath(this.folder.getParent(), fo).replace('/', '.');
if (newPackageName.length() == 0){
return postfix;
}
if (postfix.length() == 0){
return newPackageName;
}
return newPackageName + "." + postfix;
}
代码示例来源:origin: dcaoyuan/nbscala
private static boolean isJ2SEProject(File dir) {
FileObject projdir = FileUtil.toFileObject(FileUtil.normalizeFile(dir));
try {
Project proj = ProjectManager.getDefault().findProject(projdir);
if (proj != null) {
// Check if it is a J2SEProject.
return proj.getLookup().lookup(J2SEProject.class) != null;
}
} catch (IOException e) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
}
return false;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-form-refactoring
private void saveFormForUndo() {
if (!formDataObject.isValid()) {
// 210787: Refresh formDataObject if it became obsolete
FileObject fob = formDataObject.getPrimaryFile();
if (!fob.isValid()) {
File file = FileUtil.toFile(fob);
fob = FileUtil.toFileObject(file);
}
try {
formDataObject = (FormDataObject)DataObject.find(fob);
} catch (DataObjectNotFoundException ex) {
Exceptions.printStackTrace(ex);
}
}
saveForUndo(formDataObject.getFormFile());
// java file is backed up by java refactoring
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-project
private EditorCookie getEditorCookie(TmpLocalFile tmpFile) throws IOException {
FileObject fileObject = FileUtil.toFileObject(new File(tmpFile.getAbsolutePath()));
assert fileObject != null : "Fileobject for tmp local file not found: " + tmpFile;
DataObject dataObject = DataObject.find(fileObject);
return dataObject.getLookup().lookup(EditorCookie.class);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-hudson-ant
public JobCreator(Project project, Configuration config) {
this.project = project;
this.config = config;
this.shar = project.getLookup().lookup(ProjectSharability.class);
scm = Helper.prepareSCM(FileUtil.toFile(project.getProjectDirectory()));
checkboxen = initComponents();
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
createFolder(fo, name);
} else {
FileObject fd = createData(fo, name);
FileLock lock = fd.lock();
OutputStream os = fd.getOutputStream(lock);
copy(jis, os);
} finally {
os.close();
String prefix = fo.isRoot() ? dirName : (fo.getPath() + '/' + dirName);
String orig = (String) files.next();
String fn = prefix + orig;
FileObject obj = fo.getFileSystem().findResource(fn);
内容来源于网络,如有侵权,请联系作者删除!