本文整理汇总了Java中org.openide.filesystems.FileObject.refresh方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.refresh方法的具体用法?Java FileObject.refresh怎么用?Java FileObject.refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.filesystems.FileObject
的用法示例。
在下文中一共展示了FileObject.refresh方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
@Override
public void run() {
FileObject fo;
do {
synchronized (lock) {
// let's be fair - get 1-st object
Iterator<FileObject> iterator = objectsToRefresh.iterator();
if (iterator.hasNext()) {
fo = iterator.next();
objectsToRefresh.remove(fo);
} else {
fo = null;
}
}
if (fo != null) {
fo.refresh();
}
} while (fo != null);
}
示例2: refreshAll
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
* For {@link HudsonInstanceImpl} to refresh after the workspace has been synchronized.
*/
@Override
public void refreshAll() {
LOG.log(Level.FINE, "refreshing files in {0}", baseURL);
synchronized (nonDirs) {
nonDirs.clear();
lastModified.clear();
size.clear();
headers.clear();
}
for (FileObject f : NbCollections.iterable(existingFileObjects(getRoot()))) {
if (Thread.interrupted()) {
return;
}
LOG.log(Level.FINER, " refreshing {0}", f.getPath());
f.refresh();
}
}
示例3: testCachedIsDirectoryChangedForFileFO
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testCachedIsDirectoryChangedForFileFO() throws IOException {
VCSFileProxy proxy = getFileProxy("something"+ System.currentTimeMillis());
assertNotNull(proxy);
assertFalse(proxy.isDirectory());
assertTrue(proxy.isFile());
// delete file ...
File f = proxy.toFile();
assertTrue(f.exists());
assertTrue(f.isFile());
FileObject fo = FileUtil.toFileObject(f);
f.delete();
assertFalse(f.exists());
// ... and recreate as folder
f.mkdirs();
assertTrue(f.exists());
assertTrue(f.isDirectory());
fo.refresh();
assertTrue(proxy.isDirectory());
assertFalse(proxy.isFile());
}
示例4: testCachedIsDirectoryChangedForFolderFO
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testCachedIsDirectoryChangedForFolderFO() throws IOException {
VCSFileProxy proxy = getFolderProxy("something"+ System.currentTimeMillis());
assertNotNull(proxy);
assertTrue(proxy.isDirectory());
assertFalse(proxy.isFile());
// delete folder ...
File f = proxy.toFile();
assertTrue(f.exists());
assertTrue(f.isDirectory());
FileObject fo = FileUtil.toFileObject(f);
f.delete();
assertFalse(f.exists());
// ... and recreate as file
f.createNewFile();
assertTrue(f.exists());
assertTrue(f.isFile());
fo.refresh();
assertFalse(proxy.isDirectory());
assertTrue(proxy.isFile());
}
示例5: getCrc32
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/** Find (maybe cached) CRC for a file. Will open its own input stream. */
private static String getCrc32(FileObject fo) throws IOException {
URL u = fo.toURL();
fo.refresh();
long footprint = fo.lastModified().getTime() ^ fo.getSize();
String crc = findCachedCrc32(u, footprint);
if (crc == null) {
InputStream is = fo.getInputStream();
try {
crc = computeCrc32(new BufferedInputStream(is));
cacheCrc32(crc, u, footprint);
} finally {
is.close();
}
}
return crc;
}
示例6: hasSnapshotsFor
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public boolean hasSnapshotsFor(Lookup.Provider project) {
try {
FileObject snapshotsFolder = ProfilerStorage.getProjectFolder(project, false);
FileObject[] children;
if (snapshotsFolder == null) {
return false;
}
snapshotsFolder.refresh();
children = snapshotsFolder.getChildren();
for (FileObject child : children) {
if (child.getExt().equalsIgnoreCase(SNAPSHOT_EXTENSION)) return true;
if (checkHprofFile(FileUtil.toFile(child))) return true;
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, Bundle.ResultsManager_ObtainSavedSnapshotsFailedMsg(e.getMessage()), e);
}
return false;
}
示例7: testChangeFileToDir
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
* Check that fix for bug 240156 {@link #testRefreshAfterCaseChange()}
* doens't break anything.
*
* @throws IOException
*/
public void testChangeFileToDir() throws IOException {
File dir = new File(getWorkDir(), "dir");
dir.mkdir();
FileObject dirFO = FileUtil.toFileObject(dir);
File fileOrDir = new File(dir, "fileOrDir");
fileOrDir.createNewFile();
FileObject fileOrDirFO = FileUtil.toFileObject(fileOrDir);
assertTrue(fileOrDirFO.isData());
dirFO.refresh();
fileOrDir.delete();
dirFO.refresh();
fileOrDir.mkdir();
dirFO.refresh();
fileOrDirFO = FileUtil.toFileObject(fileOrDir);
assertTrue(fileOrDirFO.isFolder());
}
示例8: testCreatedExternally
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testCreatedExternally() throws IOException {
FileObject fo = FileUtil.toFileObject(getWorkDir());
FileObject[] children = fo.getChildren(); // scan folder
FileObject folder = fo.createFolder("folder");
iListener.clear();
assertEquals(0, iListener.implsCreatedExternallyCalls);
File f = new File(FileUtil.toFile(fo), "file");
f.createNewFile();
assertEquals(0, iListener.implsCreatedExternallyCalls);
fo.refresh();
assertEquals(1, iListener.implsCreatedExternallyCalls);
}
示例9: testFileTypeNotRemembered
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testFileTypeNotRemembered() throws Exception {
String newFileName = "test";
FileObject parent = root.getFileObject("testdir/mountdir10");
assertNotNull(parent);
assertTrue(parent.isFolder());
parent.getChildren();
// create a folder
assertTrue(parent.createFolder(newFileName).isFolder());
File parentFile = FileUtil.toFile(parent);
assertNotNull(parentFile);
assertTrue(parentFile.getAbsolutePath(),parentFile.exists());
File newFile = new File(parentFile, newFileName);
assertTrue(newFile.getAbsolutePath(), newFile.exists());
// externally delete the folder
assertTrue(newFile.getAbsolutePath(), newFile.delete());
assertFalse(newFile.exists());
// create a file with the same name as the deleted folder
assertTrue(newFile.getAbsolutePath(), new File(parentFile, newFileName).createNewFile());
assertTrue(newFile.exists());
parent.refresh();
FileObject fo = FileUtil.toFileObject(newFile);
assertTrue(newFile.getAbsolutePath(), fo.isData());
}
示例10: testEventsAfterCreatedFiles55550
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
@RandomlyFails // NB-Core-Build #7927 (from FileBasedFileSystemWithUninitializedExtensionsTest): Didn't receive a FileEvent on the parent.
public void testEventsAfterCreatedFiles55550() throws Exception {
FileObject parent = root.getFileObject("testdir/mountdir8");
assertNotNull(parent);
assertTrue(parent.isFolder());
parent.getChildren();
File parentFile = FileUtil.toFile(parent);
assertNotNull(parentFile);
assertTrue(parentFile.getAbsolutePath(),parentFile.exists());
File newFile = new File(parentFile, "sun-web.xml");
assertFalse(newFile.getAbsolutePath(),newFile.exists());
class FCLImpl extends FileChangeAdapter {
boolean created;
@Override
public void fileDataCreated(FileEvent e) {
created = true;
synchronized(BaseFileObjectTestHid.this) {
BaseFileObjectTestHid.this.notifyAll();
}
}
}
FCLImpl fl = new FCLImpl();
parent.addFileChangeListener(fl);
assertTrue(newFile.getAbsolutePath(), newFile.createNewFile());
assertTrue(newFile.exists());
// !!!! This is the source of the problem !!!
// ask for the new file
// remove this line ans the test passes
FileUtil.toFileObject(newFile);
parent.refresh();
synchronized(this) {
wait(1000);
}
parent.removeFileChangeListener(fl);
assertTrue("Didn't receive a FileEvent on the parent.", fl.created);
}
示例11: run
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
@Override
public void run() {
for (int loop = 0; loop < 10; loop++) {
// XXX: the modules list should be refresh automatically when config/Modules/ changes
Map<File,Long> modifiedFiles = NbCollections.checkedMapByFilter(
(Map)ev.getNewValue(),
File.class, Long.class, true
);
long now = System.currentTimeMillis();
for (Map.Entry<File,Long> e : modifiedFiles.entrySet()) {
touch(e.getKey(), Math.max(e.getValue(), now));
}
FileObject modulesRoot = FileUtil.getConfigFile(ModuleDeactivator.MODULES);
if (modulesRoot != null) {
/* XXX: uncomment when #205120 fixed.
LOG.fine("Refreshing Modules directory"); // NOI18N
modulesRoot.refresh();
LOG.fine("Done refreshing Modules directory"); // NOI18N
*/
LOG.fine("Refreshing whole MFS"); // NOI18N
modulesRoot.refresh();
try {
FileUtil.getConfigRoot().getFileSystem().refresh(true);
} catch (FileStateInvalidException ex) {
Exceptions.printStackTrace(ex);
}
LOG.fine("Done refreshing MFS"); // NOI18N
}
boolean ok = true;
for (File file : modifiedFiles.keySet()) {
String rel = relativePath(file, new StringBuilder());
if (rel == null) {
continue;
}
FileObject fo = FileUtil.getConfigFile(rel);
if (fo == null) {
LOG.log(loop < 5 ? Level.FINE : Level.WARNING, "Cannot find " + rel);
ok = false;
continue;
}
LOG.fine("Refreshing " + fo);
fo.refresh();
}
if (ok) {
LOG.log(loop < 5 ? Level.FINE : Level.INFO, "All was OK on " + loop + " th iteration");
break;
}
}
}
示例12: includes
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
* Check whether a file is included in this entry.
* @param file a file inside @{link #getRoot}
* @return true if it is {@link FilteringPathResourceImplementation#includes included}
* @throws IllegalArgumentException in case the argument is not beneath {@link #getRoot}, or {@link #getRoot} is null
* @since org.netbeans.api.java/1 1.13
*/
public boolean includes(FileObject file) {
if (!file.isValid()) {
//Invalid FileObject is not included
return false;
}
FileObject r = getRoot();
if (r == null) {
file.refresh();
if (!file.isValid()) {
return false;
} else {
throw new IllegalArgumentException("no root in " + url);
}
}
String path = FileUtil.getRelativePath(r, file);
if (path == null) {
if (!file.isValid()) {
//Already tested above, but re-test if still valid
return false;
}
StringBuilder sb = new StringBuilder();
sb.append(file).append(" (valid: ").append(file.isValid()).append(") not in "). // NOI18N
append(r).append(" (valid: ").append(r.isValid()).append(")"); // NOI18N
if (file.getPath().startsWith(r.getPath())) {
while (file.getPath().length() > r.getPath().length()) {
file = file.getParent();
sb.append("\nChildren of ").append(file).
append(" (valid: ").append(file.isValid()).append(")").
append(" are:\n ").append(Arrays.toString(file.getChildren()));
}
} else {
sb.append("\nRoot path is not prefix"); // NOI18N
}
throw new IllegalArgumentException(sb.toString());
}
if (file.isFolder()) {
path += "/"; // NOI18N
}
return filter == null || filter.includes(url, path);
}
示例13: listSavedHeapdumps
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public FileObject[] listSavedHeapdumps(Lookup.Provider project, File directory) {
try {
FileObject snapshotsFolder = null;
if (project == null && directory != null) {
snapshotsFolder = FileUtil.toFileObject(directory);
} else {
snapshotsFolder = ProfilerStorage.getProjectFolder(project, false);
}
if (snapshotsFolder == null) {
return new FileObject[0];
}
snapshotsFolder.refresh();
FileObject[] children = snapshotsFolder.getChildren();
ArrayList /*<FileObject>*/ files = new ArrayList /*<FileObject>*/();
for (int i = 0; i < children.length; i++) {
FileObject child = children[i];
if (checkHprofFile(FileUtil.toFile(children[i])))
files.add(child);
}
Collections.sort(files,
new Comparator() {
public int compare(Object o1, Object o2) {
FileObject f1 = (FileObject) o1;
FileObject f2 = (FileObject) o2;
return f1.getName().compareTo(f2.getName());
}
});
return (FileObject[])files.toArray(new FileObject[0]);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, Bundle.ResultsManager_ObtainSavedSnapshotsFailedMsg(e.getMessage()), e);
return new FileObject[0];
}
}
示例14: testRefreshDoesNotMultiplyFileObjects_89059
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testRefreshDoesNotMultiplyFileObjects_89059 () throws Exception {
FileObject fo = FileBasedFileSystem.getFileObject(testFile);
fo.getChildren();
FileSystem fs = fo.getFileSystem();
FileChangeListener fcl = new FileChangeAdapter();
OutputStream os = null;
fs.addFileChangeListener(fcl);
fo.addFileChangeListener(fcl);
try {
//no change
int foInstancesInCache = Statistics.fileObjects();
fs.refresh(false);
assertTrue(foInstancesInCache >= Statistics.fileObjects());
//internal change
File ff = new File(testFile,"a/b/c/d/aa.txt");//NOI18N
FileUtil.createData(ff);
foInstancesInCache = Statistics.fileObjects();
fs.refresh(false);
assertTrue(foInstancesInCache >= Statistics.fileObjects());
//external change
FileObject ffObject = FileBasedFileSystem.getFileObject(ff);
foInstancesInCache = Statistics.fileObjects();
os = new java.io.FileOutputStream(ff);
os.write("dsdopsdsd".getBytes());//NOI18N
os.close();
fs.refresh(false);
assertTrue(foInstancesInCache >= Statistics.fileObjects());
assertTrue(new File(testFile,"nfile").createNewFile());//NOI18N
fs.refresh(false);
fo.refresh(false);
assertTrue(foInstancesInCache+1 >= Statistics.fileObjects());
foInstancesInCache = Statistics.fileObjects();
assertTrue(new File(testFile,"aa/bb/cc").mkdirs());//NOI18N
fs.refresh(false);
fo.refresh(false);
assertTrue(foInstancesInCache+3 >= Statistics.fileObjects());
} finally {
if (os != null) {
os.close();
}
fs.removeFileChangeListener(fcl);
fo.removeFileChangeListener(fcl);
}
}
示例15: test218795
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
* Test that symbolic links are handled correctly, without infinite
* recursion.
*
* Let's use the following data structure:
* <pre>
* f1
* f2
* f3
* f4
* f5 (symbolic link with target = f1)
* </pre>
*
* @throws java.io.IOException
*/
public void test218795() throws IOException {
File rootF = getWorkDir();
createDirTreeWithChangingNames(rootF, 5);
FileObject rootFO = FileUtil.toFileObject(rootF);
assertNotNull(rootFO);
assertEquals(rootF, FileUtil.toFile(rootFO));
rootFO.refresh();
assertEquals(4, countRecursiveChildren(rootFO));
}