本文整理匯總了Java中org.openide.filesystems.FileUtil.runAtomicAction方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtil.runAtomicAction方法的具體用法?Java FileUtil.runAtomicAction怎麽用?Java FileUtil.runAtomicAction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openide.filesystems.FileUtil
的用法示例。
在下文中一共展示了FileUtil.runAtomicAction方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: registerDrivers
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private static void registerDrivers(final String newLocation) {
try {
// registering the drivers in an atomic action so the Drivers node
// is refreshed only once
FileUtil.runAtomicAction(new FileSystem.AtomicAction() {
@Override
public void run() {
registerDriver(DRIVER_NAME_NET, DRIVER_DISP_NAME_NET, DRIVER_CLASS_NET,
new String[]{DRIVER_PATH_NET, DRIVER_PATH_EMBEDDED}, newLocation);
registerDriver(DRIVER_NAME_EMBEDDED, DRIVER_DISP_NAME_EMBEDDED,
DRIVER_CLASS_EMBEDDED, new String[]{DRIVER_PATH_EMBEDDED}, newLocation);
}
});
} catch (IOException e) {
Exceptions.printStackTrace(e);
}
}
示例2: doDestroy
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private void doDestroy(final Node[] sel) {
try {
FileUtil.runAtomicAction(new FileSystem.AtomicAction() {
public void run() throws IOException {
for (int i = 0; i <
sel.length; i++) {
try {
sel[i].destroy();
}
catch (IOException e) {
Exceptions.printStackTrace(e);
}
}
}
});
} catch (IOException ioe) {
throw (IllegalStateException) new IllegalStateException(ioe.toString()).initCause(ioe);
}
}
示例3: refreshModuleList
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private static void refreshModuleList () {
// XXX: the modules list should be refresh automatically when config/Modules/ changes
final FileObject modulesRoot = FileUtil.getConfigFile(MODULES);
LOG.log (Level.FINE,
"It\'s a hack: Call refresh on " + modulesRoot +
" file object.");
if (modulesRoot != null) {
try {
FileUtil.runAtomicAction (new FileSystem.AtomicAction () {
@Override
public void run () throws IOException {
modulesRoot.getParent ().refresh ();
modulesRoot.refresh ();
}
});
} catch (IOException ex) {
Exceptions.printStackTrace (ex);
}
}
}
示例4: testCreatedShadowFoundInParent
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
public void testCreatedShadowFoundInParent() throws Exception {
class R implements FileSystem.AtomicAction {
@Override
public void run() throws IOException {
DataObject[] old = folder.getChildren();
assertEquals("No children yet", 0, old.length);
DataShadow ds = original.createShadow(folder);
assertEquals("Parent is OK", folder, ds.getFolder());
DataObject[] arr = folder.getChildren();
List<DataObject> all = Arrays.asList(arr);
assertTrue("Newly created " + ds + " shall be in list of children", all.contains(ds));
}
}
R action = new R();
FileUtil.runAtomicAction(action);
}
示例5: registerLibraryTypeProvider
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
public static void registerLibraryTypeProvider (final Class<? extends LibraryTypeProvider> provider) throws Exception {
final MockLibraryTypeRegistry mr = Lookup.getDefault().lookup(MockLibraryTypeRegistry.class);
if (mr != null) {
mr.register(provider.newInstance());
return;
}
FileObject root = FileUtil.getConfigRoot();
StringTokenizer tk = new StringTokenizer("org-netbeans-api-project-libraries/LibraryTypeProviders","/");
while (tk.hasMoreElements()) {
String pathElement = tk.nextToken();
FileObject tmp = root.getFileObject(pathElement);
if (tmp == null) {
tmp = root.createFolder(pathElement);
}
root = tmp;
}
final FileObject rootFin = root;
if (root.getChildren().length == 0) {
FileUtil.runAtomicAction(new FileSystem.AtomicAction() {
@Override
public void run() throws IOException {
FileObject inst = rootFin.createData("TestLibraryTypeProvider","instance");
inst.setAttribute("instanceClass", getBinaryName(provider));
}
});
}
}
示例6: runAtomic
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private void runAtomic(@NonNull final Runnable r) {
FileUtil.runAtomicAction(new Runnable() {
@Override
public void run() {
ProjectManager.mutex().writeAccess(new Runnable() {
@Override
public void run() {
r.run();
}
});
}
});
}
示例7: testFilesScannedAferSourceRootCreatedDeleted
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
public void testFilesScannedAferSourceRootCreatedDeleted() throws Exception {
final TestHandler handler = new TestHandler();
final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests");
logger.setLevel (Level.FINEST);
logger.addHandler(handler);
final File srcRoot1File = FileUtil.toFile(srcRoot1);
final ClassPath cp1 = ClassPathSupport.createClassPath(FileUtil.urlForArchiveOrDir(srcRoot1File));
globalPathRegistry_register(SOURCES,new ClassPath[]{cp1});
assertTrue (handler.await());
indexerFactory.indexer.setExpectedFile(new URL[0], new URL[0], new URL[0]);
eindexerFactory.indexer.setExpectedFile(new URL[0], new URL[0], new URL[0]);
assertTrue(indexerFactory.indexer.awaitDeleted(TIME));
assertTrue(eindexerFactory.indexer.awaitDeleted());
assertTrue(indexerFactory.indexer.awaitIndex(TIME));
assertTrue(eindexerFactory.indexer.awaitIndex());
indexerFactory.indexer.setExpectedFile(new URL[0], new URL[0], new URL[0]);
eindexerFactory.indexer.setExpectedFile(new URL[0], new URL[0], new URL[0]);
srcRoot1.delete();
final File a = new File(srcRoot1File,"folder/a.foo");
final File b = new File(srcRoot1File,"folder/b.emb");
indexerFactory.indexer.setExpectedFile(new URL[]{org.openide.util.Utilities.toURI(a).toURL()}, new URL[0], new URL[0]);
eindexerFactory.indexer.setExpectedFile(new URL[]{org.openide.util.Utilities.toURI(b).toURL()}, new URL[0], new URL[0]);
FileUtil.runAtomicAction(new FileSystem.AtomicAction() {
@Override
public void run() throws IOException {
FileUtil.createFolder(srcRoot1File);
FileUtil.createData(a);
FileUtil.createData(b);
}
});
assertTrue(indexerFactory.indexer.awaitDeleted(TIME));
assertTrue(eindexerFactory.indexer.awaitDeleted());
assertTrue(indexerFactory.indexer.awaitIndex(TIME));
assertTrue(eindexerFactory.indexer.awaitIndex());
}
示例8: load
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
@Override
public void load(final List<Module> modules) {
FileUtil.runAtomicAction(new Runnable() {
@Override
public void run() {
loadImpl(modules);
}
});
}
示例9: unload
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
@Override
public void unload(final List<Module> modules) {
FileUtil.runAtomicAction(new Runnable() {
@Override
public void run() {
unloadImpl(modules);
}
});
}
示例10: refreshFromGetter
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private void refreshFromGetter(final FileObject parent,boolean asyncFire) {
try {
if (asyncFire) {
FileUtil.runAtomicAction(new AsyncRefreshAtomicAction(parent));
} else {
parent.refresh();
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
示例11: testFiredFromManyAtomicActions
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
public void testFiredFromManyAtomicActions() throws Exception {
final File workDir = getWorkDir();
final FileObject workDirFo = FileUtil.toFileObject(workDir);
final MyAtomicAction myAtomicAction = new MyAtomicAction();
MyFileChangeListener myChangeListener = new MyFileChangeListener(myAtomicAction);
FileUtil.addRecursiveListener(myChangeListener, workDir);
assertEquals("files before", 0, workDir.list().length);
for (int i = 0; i < RUNS; ++i) {
final int j = i;
myAtomicAction.runnable = new Runnable() {
@Override
public void run() {
try {
FileUtil.createData(workDirFo, FILE_PREFIX + j);
} catch (IOException ex) {
// checked later
}
}
};
FileUtil.runAtomicAction(myAtomicAction);
}
assertEquals("files after", RUNS, workDir.list().length);
assertEquals(printEvents(myChangeListener.notFromAtomicAction), 0, myChangeListener.notFromAtomicAction.size());
assertEquals("events", RUNS, myChangeListener.events.get());
}
示例12: testFiredFromOneAtomicAction
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
public void testFiredFromOneAtomicAction() throws Exception {
final File workDir = getWorkDir();
final FileObject workDirFo = FileUtil.toFileObject(workDir);
final AtomicAction myAtomicAction = new AtomicAction() {
@Override
public void run() throws IOException {
try {
for (int i = 0; i < RUNS; ++i) {
FileUtil.createData(workDirFo, FILE_PREFIX + i);
}
} catch (IOException ex) {
// checked later
}
}
};
MyFileChangeListener myChangeListener = new MyFileChangeListener(myAtomicAction);
FileUtil.addRecursiveListener(myChangeListener, workDir);
assertEquals("files before", 0, workDir.list().length);
FileUtil.runAtomicAction(myAtomicAction);
assertEquals("files after", RUNS, workDir.list().length);
assertEquals(printEvents(myChangeListener.notFromAtomicAction), 0, myChangeListener.notFromAtomicAction.size());
assertEquals("events", RUNS, myChangeListener.events.get());
}
示例13: handleDrop
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
/**
* Perform the drop operation.
*
* @return True if the drop has been successful.
*/
private boolean handleDrop( final Transferable t ) {
final boolean[] res = { false };
FileUtil.runAtomicAction(new Runnable() {
@Override
public void run() {
res[0] = handleDropImpl(t);
}
});
return res[0];
}
示例14: getBookFile
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
public static File getBookFile(File dataDir, File workDir) throws IOException {
final File source = new File(dataDir, "sample.book");
final File target = new File(workDir, "sample.book");
if (target.exists()) {
return target;
}
FileUtil.runAtomicAction(new FileSystem.AtomicAction() {
@Override
public void run() throws IOException {
BufferedInputStream is = new BufferedInputStream(new FileInputStream(source));
try {
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(target));
try {
FileUtil.copy(is, os);
} finally {
os.close();
}
} finally {
is.close();
}
}
});
FileUtil.refreshFor(target);
return target;
}
示例15: saveThisEntry
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
/** Helper method. Saves this entry. */
private void saveThisEntry() throws IOException {
FileSystem.AtomicAction aa = new SaveImpl(this);
FileUtil.runAtomicAction(aa);
// super.saveDocument();
// #32777 - it can happen that save operation was interrupted
// and file is still modified. Mark it unmodified only when it is really
// not modified.
if (!env.isModified()) {
myEntry.setModified(false);
}
}