当前位置: 首页>>代码示例>>Java>>正文


Java FileSystem.runAtomicAction方法代码示例

本文整理汇总了Java中org.openide.filesystems.FileSystem.runAtomicAction方法的典型用法代码示例。如果您正苦于以下问题:Java FileSystem.runAtomicAction方法的具体用法?Java FileSystem.runAtomicAction怎么用?Java FileSystem.runAtomicAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openide.filesystems.FileSystem的用法示例。


在下文中一共展示了FileSystem.runAtomicAction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCreateLibraryUnderFSAtomicAction

import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
public void testCreateLibraryUnderFSAtomicAction() throws Exception {
    final LibraryManager mgr = LibraryManager.forLocation(new URL(base, "libraries.properties"));
    final Map<String,List<URI>> content = new HashMap<String,List<URI>>();
    content.put("classpath", Arrays.asList(new URI("jh.jar!/"), new URI("jh-search.jar!/")));
    content.put("javadoc", Arrays.asList(new URI("jh-api/")));

    FileSystem fs = projdir.getFileSystem();
    fs.runAtomicAction(new FileSystem.AtomicAction() {
        public void run() throws IOException {
            Library lib = mgr.createURILibrary("j2se", "javahelp", content);
            assertEquals("j2se", lib.getType());
            assertEquals("javahelp", lib.getName());
            assertEquals(content.get("classpath"), lib.getURIContent("classpath"));
            assertEquals(content.get("javadoc"), lib.getURIContent("javadoc"));
            try {
                setLibraryContent(lib, "src", new URL(base, "separate/jgraph-src/").toURI(), new URL(base, "jgraph-other-src/").toURI());
            } catch (Exception e) {
                throw new IOException(e.toString());
            }
        }});
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:ProjectLibraryProviderTest.java

示例2: extractZip

import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
private static void extractZip(final FileObject fo, final InputStream is)
throws IOException {
    FileSystem fs = fo.getFileSystem();

    fs.runAtomicAction(
        new FileSystem.AtomicAction() {
            public @Override void run() throws IOException {
                extractZipImpl(fo, is);
            }
        }
    );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:GsfUtilities.java

示例3: saveChanges

import org.openide.filesystems.FileSystem; //导入方法依赖的package包/类
/**
 * attempts to save the document model to disk.
 * if model is in transaction, the transaction is ended first,
 * then dataobject's SaveCookie is called.
 *
 * @param model
 * @throws java.io.IOException if saving fails.
 */
public static void saveChanges(AbstractDocumentModel<?> model) throws IOException {
    if (model.isIntransaction()) {
        // the ISE thrown from endTransction is handled in performPOMModelOperations.
        model.endTransaction();
    }
    model.sync();
    DataObject dobj = model.getModelSource().getLookup().lookup(DataObject.class);
    if (dobj == null) {
        final Document doc = model.getModelSource().getLookup().lookup(Document.class);
        final File file = model.getModelSource().getLookup().lookup(File.class);
        logger.log(Level.FINE, "saving changes in {0}", file);
        File parent = file.getParentFile();
        FileObject parentFo = FileUtil.toFileObject(parent);
        if (parentFo == null) {
            parent.mkdirs();
            FileUtil.refreshFor(parent);
            parentFo = FileUtil.toFileObject(parent);
        }
        final FileObject fParentFo = parentFo;
        if (fParentFo != null) {
            FileSystem fs = parentFo.getFileSystem();
            fs.runAtomicAction(new FileSystem.AtomicAction() {
                public @Override void run() throws IOException {
                    String text;
                    try {
                        text = doc.getText(0, doc.getLength());
                    } catch (BadLocationException x) {
                        throw new IOException(x);
                    }
                    FileObject fo = fParentFo.getFileObject(file.getName());
                    if (fo == null) {
                        fo = fParentFo.createData(file.getName());
                    }
                    OutputStream os = fo.getOutputStream();
                    try {
                        os.write(text.getBytes("UTF-8"));
                    } finally {
                        os.close();
                    }
                }
            });
        } else {
            //TODO report
        }
    } else {
        SaveCookie save = dobj.getLookup().lookup(SaveCookie.class);
        if (save != null) {
            logger.log(Level.FINE, "saving changes in {0}", dobj);
            save.save();
        } else {
            logger.log(Level.FINE, "no changes in {0} where modified={1}", new Object[] {dobj, dobj.isModified()});
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:63,代码来源:Utilities.java


注:本文中的org.openide.filesystems.FileSystem.runAtomicAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。