本文整理汇总了Java中org.openide.filesystems.FileUtil.createData方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.createData方法的具体用法?Java FileUtil.createData怎么用?Java FileUtil.createData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.filesystems.FileUtil
的用法示例。
在下文中一共展示了FileUtil.createData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateDefaultFormat
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
/**
* Checks that FileEntry.Format properly formats the template. Part of parameters is provided
* by the DataLoader while part is provided by the API caller.
*
* @throws Exception
*/
public void testCreateDefaultFormat() throws Exception {
MockServices.setServices(Pool.class);
FileObject root = FileUtil.createMemoryFileSystem().getRoot();
FileObject templ = FileUtil.createData(root, "simpleTemplate.prim");
String txt = "{a}{b}";
OutputStream os = templ.getOutputStream();
os.write(txt.getBytes());
os.close();
DataObject obj = DataObject.find(templ);
DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
Map m = new HashMap();
m.put("a", "eeee");
DataObject x = obj.createFromTemplate(folder, "nue", m);
assertEquals("eeeexxxx\n", x.getPrimaryFile().asText());
}
示例2: setUp
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
/**
* Sets up the testing environment by creating testing folders
* on the system file system.
*/
@Override
protected void setUp() throws Exception {
clearWorkDir();
MockLookup.setInstances(new Repository(TestUtilHid.createLocalFileSystem(getWorkDir(), new String[0])),
new Pool());
MyDL1 loader1 = MyDL1.getLoader(MyDL1.class);
MyDL2 loader2 = MyDL2.getLoader(MyDL2.class);
FileSystem dfs = FileUtil.getConfigRoot().getFileSystem();
dfs.refresh (true);
FileObject fo = FileUtil.createData (dfs.getRoot (), "a.ext1");
obj1 = DataObject.find (fo);
assertEquals ("The correct loader", loader1, obj1.getLoader ());
fo = FileUtil.createData (dfs.getRoot (), "b.ext2");
obj2 = DataObject.find (fo);
assertEquals ("The correct loader", loader2, obj2.getLoader ());
sfs = new PCL ();
dfs.addFileChangeListener (sfs);
}
示例3: createFileSystem
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
@Override
protected FileSystem[] createFileSystem(String testName, String[] resources) throws IOException {
setupWorkdir();
setupUserdir();
try {
repoinit();
} catch (Exception ex) {
throw new IOException(ex.getMessage());
}
FileObjectFactory.reinitForTests();
FileObject workFo = FileBasedFileSystem.getFileObject(getWorkDir());
assertNotNull(workFo);
List<File> files = new ArrayList<File>(resources.length);
for (int i = 0; i < resources.length; i++) {
String res = resources[i];
FileObject fo;
if (res.endsWith("/")) {
fo = FileUtil.createFolder(workFo,res);
assertNotNull(fo);
} else {
fo = FileUtil.createData(workFo,res);
assertNotNull(fo);
}
files.add(FileUtil.toFile(fo));
}
commit(files, testName);
return new FileSystem[]{workFo.getFileSystem()};
}
示例4: performTest
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private void performTest(String filePath, String sourceCode, String sourceLevel, final Task<WorkingCopy> task, final Validator validator, final boolean requireNoErrors) throws Exception {
FileObject root = makeScratchDir(this);
FileObject sourceDir = root.createFolder("src");
FileObject buildDir = root.createFolder("build");
FileObject cacheDir = root.createFolder("cache");
FileObject source = FileUtil.createData(sourceDir, filePath);
writeIntoFile(source, sourceCode);
SourceUtilsTestUtil.prepareTest(sourceDir, buildDir, cacheDir, new FileObject[0]);
SourceUtilsTestUtil.setSourceLevel(source, sourceLevel);
JavaSource js = JavaSource.forFileObject(source);
ModificationResult result = js.runModificationTask(task);
result.commit();
js.runUserActionTask(new CancellableTask<CompilationController>() {
public void cancel() {
}
public void run(CompilationController controller) throws Exception {
controller.toPhase(JavaSource.Phase.RESOLVED);
if (requireNoErrors) {
assertEquals(controller.getDiagnostics().toString(), 0, controller.getDiagnostics().size());
}
if (validator != null)
validator.validate(controller);
}
}, true);
}
示例5: testUnmodifyViaSetModified
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
public void testUnmodifyViaSetModified() throws IOException, BadLocationException {
FileObject fo = FileUtil.createData(FileUtil.getConfigRoot(), "test2.html");
assertNotNull(fo);
final DataObject obj = DataObject.find(fo);
assertNotNull(obj);
assertFalse(obj.isModified());
assertNull(obj.getLookup().lookup(SaveCookie.class));
final StyledDocument doc = obj.getLookup().lookup(EditorCookie.class).openDocument();
assertTrue(doc instanceof BaseDocument);
((BaseDocument) doc).runAtomic(new Runnable() {
@Override
public void run() {
try {
doc.insertString(0, "hello", null);
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
});
((BaseDocument) doc).runAtomic(new Runnable() {
@Override
public void run() {
assertTrue(obj.isModified());
}
});
assertNotNull(obj.getLookup().lookup(SaveCookie.class));
//some QE unit tests needs to silently discard the changed made to the editor document
obj.setModified(false);
assertFalse(obj.isModified());
assertNull(obj.getLookup().lookup(SaveCookie.class));
}
示例6: paneFor
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private JEditorPane paneFor(FileObject src, String fileName, String code) throws Exception, DataObjectNotFoundException, IOException {
FileObject fromFO = FileUtil.createData(src, fileName);
TestUtilities.copyStringToFile(fromFO, code);
DataObject od = DataObject.find(fromFO);
final EditorCookie.Observable ec = od.getCookie(EditorCookie.Observable.class);
final Exchanger<JEditorPane> exch = new Exchanger<>();
class L implements PropertyChangeListener {
@Override
public void propertyChange(PropertyChangeEvent evt) {
try {
if (!EditorCookie.Observable.PROP_OPENED_PANES.equals(evt.getPropertyName())) {
return;
}
// we are in AWT
JEditorPane[] panes = ec.getOpenedPanes();
if (panes == null) {
return;
}
exch.exchange(panes[0]);
} catch (InterruptedException ex) {
}
}
}
L listener = new L();
ec.addPropertyChangeListener(listener);
JEditorPane pane = null;
try {
ec.open();
ec.openDocument().putProperty(Language.class, JavaTokenId.language());
pane = exch.exchange(null, 5, TimeUnit.SECONDS);
} finally {
ec.removePropertyChangeListener(listener);
}
assertNotNull("Editor pane not opened", pane);
return pane;
}
示例7: createModuleInfo
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
@NonNull
private static FileObject createModuleInfo(
@NonNull final FileObject root,
@NonNull final String moduleName,
@NonNull final String... requiredModules) throws IOException {
final FileObject moduleInfo = FileUtil.createData(root, "module-info.java"); //NOI18N
try(PrintWriter out = new PrintWriter(new OutputStreamWriter(moduleInfo.getOutputStream()))) {
out.printf("module %s {%n", moduleName); //NOI18N
for (String requiredModule : requiredModules) {
out.printf(" requires %s;%n", requiredModule); //NOI18N
}
out.printf("}"); //NOI18N
}
return moduleInfo;
}
示例8: copyBuildNativeTemplate
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
static FileObject copyBuildNativeTemplate(@NonNull final Project project) throws IOException {
Parameters.notNull("project", project); //NOI18N
final FileObject buildExFoBack = project.getProjectDirectory().getFileObject(String.format(
"%s~", //NOI18N
EXTENSION_BUILD_SCRIPT_PATH));
if (buildExFoBack != null) {
closeInEditor(buildExFoBack);
buildExFoBack.delete();
}
FileObject buildExFo = project.getProjectDirectory().getFileObject(EXTENSION_BUILD_SCRIPT_PATH);
FileLock lock;
if (buildExFo != null) {
closeInEditor(buildExFo);
lock = buildExFo.lock();
try {
buildExFo.rename(
lock,
buildExFo.getName(),
String.format(
"%s~", //NOI18N
buildExFo.getExt()));
} finally {
lock.releaseLock();
}
}
buildExFo = FileUtil.createData(project.getProjectDirectory(), EXTENSION_BUILD_SCRIPT_PATH);
lock = buildExFo.lock();
try (final InputStream in = J2SEDeployProperties.class.getClassLoader().getResourceAsStream(BUILD_SCRIPT_PROTOTYPE);
final OutputStream out = buildExFo.getOutputStream(lock)) {
FileUtil.copy(in, out);
} finally {
lock.releaseLock();
}
return buildExFo;
}
示例9: saveXml
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
/**
* Save an XML config file to a named path.
* If the file does not yet exist, it is created.
*/
private static void saveXml(Document doc, FileObject dir, String path) throws IOException {
FileObject xml = FileUtil.createData(dir, path);
FileLock lock = xml.lock();
try {
OutputStream os = xml.getOutputStream(lock);
try {
XMLUtil.write(doc, os, "UTF-8"); // NOI18N
} finally {
os.close();
}
} finally {
lock.releaseLock();
}
}
示例10: testFindTestSourcesForSources
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
public void testFindTestSourcesForSources() throws Exception {
NbModuleProject p = generateStandaloneModule("p");
FileObject source = p.getSourceDirectory();
FileObject one = FileUtil.createData(source, "p/One.java");
FileObject r = FileUtil.createData(source, "p/r.png");
FileObject other = FileUtil.createData(source, "p/Other.java");
FileObject pkg = source.getFileObject("p");
FileObject third = FileUtil.createData(source, "p2/Third.java");
FileObject test = p.getTestSourceDirectory("unit");
FileObject oneTest = FileUtil.createData(test, "p/OneTest.java");
FileObject otherTest = FileUtil.createData(test, "p/OtherTest.java");
FileObject thirdTest = FileUtil.createData(test, "p2/ThirdTest.java");
ModuleActions a = new ModuleActions(p);
assertEquals("null", String.valueOf(a.findTestSourcesForSources(Lookup.EMPTY)));
assertEquals("unit:p/OneTest.java", String.valueOf(a.findTestSourcesForSources(Lookups.singleton(one))));
assertEquals("unit:p/OneTest.java,p/OtherTest.java", String.valueOf(a.findTestSourcesForSources(Lookups.fixed(one, other))));
assertEquals("unit:p/**", String.valueOf(a.findTestSourcesForSources(Lookups.singleton(pkg))));
assertEquals("null", String.valueOf(a.findTestSourcesForSources(Lookups.singleton(r))));
assertEquals("null", String.valueOf(a.findTestSourcesForSources(Lookups.fixed(one, r))));
assertEquals("null", String.valueOf(a.findTestSourcesForSources(Lookup.EMPTY)));
assertEquals("unit:p/OneTest.java", String.valueOf(a.findTestSourcesForSources(Lookups.singleton(one))));
assertEquals("unit:p/OneTest.java,p/OtherTest.java", String.valueOf(a.findTestSourcesForSources(Lookups.fixed(one, other))));
assertEquals("null", String.valueOf(a.findTestSourcesForSources(Lookups.singleton(r))));
assertEquals("null", String.valueOf(a.findTestSourcesForSources(Lookups.fixed(one, r))));
}
示例11: testFreeFileExtension
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
public void testFreeFileExtension() throws Exception {
FileObject root = FileUtil.createMemoryFileSystem().getRoot();
FileObject template = FileUtil.createData(root, "simple.pl");
OutputStream os = template.getOutputStream();
os.write("#!/usr/bin/perl\n# ${license}\n# ${name} in ${nameAndExt}\n".getBytes());
os.close();
template.setAttribute("template", true);
template.setAttribute("javax.script.ScriptEngine", "freemarker");
Map<String,Object> parameters = new HashMap<String,Object>();
parameters.put("license", "GPL");
parameters.put(CreateFromTemplateHandler.FREE_FILE_EXTENSION, true);
FileObject inst = DataObject.find(template).createFromTemplate(DataFolder.findFolder(root), "nue", parameters).getPrimaryFile();
assertEquals("#!/usr/bin/perl\n# GPL\n# nue in nue.pl\n", inst.asText());
assertEquals("nue.pl", inst.getPath());
/* XXX perhaps irrelevant since typical wizards disable Finish in this condition
inst = DataObject.find(template).createFromTemplate(DataFolder.findFolder(root), "nue", parameters).getPrimaryFile();
assertEquals("#!/usr/bin/perl\n# GPL\n# nue_1 in nue_1.pl\n", inst.asText());
assertEquals("nue_1.pl", inst.getPath());
*/
inst = DataObject.find(template).createFromTemplate(DataFolder.findFolder(root), "nue.cgi", parameters).getPrimaryFile();
assertEquals("#!/usr/bin/perl\n# GPL\n# nue in nue.cgi\n", inst.asText());
assertEquals("nue.cgi", inst.getPath());
/* XXX
inst = DataObject.find(template).createFromTemplate(DataFolder.findFolder(root), "nue.cgi", parameters).getPrimaryFile();
assertEquals("#!/usr/bin/perl\n# GPL\n# nue_1 in nue_1.cgi\n", inst.asText());
assertEquals("nue_1.cgi", inst.getPath());
*/
inst = DataObject.find(template).createFromTemplate(DataFolder.findFolder(root), "explicit.pl", parameters).getPrimaryFile();
assertEquals("#!/usr/bin/perl\n# GPL\n# explicit in explicit.pl\n", inst.asText());
assertEquals("explicit.pl", inst.getPath());
/* XXX
inst = DataObject.find(template).createFromTemplate(DataFolder.findFolder(root), "explicit.pl", parameters).getPrimaryFile();
assertEquals("#!/usr/bin/perl\n# GPL\n# explicit_1 in explicit_1.pl\n", inst.asText());
assertEquals("explicit_1.pl", inst.getPath());
*/
}
示例12: testUserHasPreferenceOverFSsButGeneratesAnEvent
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
public void testUserHasPreferenceOverFSsButGeneratesAnEvent() throws Exception {
FileObject fo1 = FileUtil.createData(fs1.getRoot(), "dir/file.txt");
fo1.setAttribute("one", 1);
write(fo1, "fileone");
FileObject fo2 = FileUtil.createData(fs2.getRoot(), "dir/file.txt");
fo2.setAttribute("two", 2);
write(fo2, "two");
events.clear();
MainLookup.register(fs1, this);
MainLookup.register(fs2, this);
assertFalse("not empty", events.isEmpty());
events.clear();
FileObject global = FileUtil.createData(FileUtil.getConfigRoot(), "dir/file.txt");
global.setAttribute("global", 3);
write(global, "global");
assertFalse("yet another set", events.isEmpty());
Enumeration<String> en = global.getAttributes();
TreeSet<String> t = new TreeSet<String>();
while (en.hasMoreElements()) {
t.add(en.nextElement());
}
assertEquals("three elements: " + t, 3, t.size());
assertTrue(t.contains("two"));
assertTrue(t.contains("one"));
assertTrue(t.contains("global"));
assertEquals(1, global.getAttribute("one"));
assertEquals(2, global.getAttribute("two"));
assertEquals(3, global.getAttribute("global"));
assertEquals("contains global", 6, global.getSize());
assertEquals("global", read(global));
}
示例13: testTreePathIsNotParsing
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
public void testTreePathIsNotParsing() throws Exception {
FileObject file = FileUtil.createData(sourceRoot, "test/test.java");
writeIntoFile(file, "package test; public class test {}");
writeIntoFile(FileUtil.createData(sourceRoot, "test/test2.java"), "package test; public class test2 {}");
JavaSource js = JavaSource.forFileObject(file);
SourceUtilsTestUtil.compileRecursively(sourceRoot);
js.runUserActionTask(new Task<CompilationController>() {
public void run(CompilationController parameter) throws Exception {
parameter.toPhase(Phase.RESOLVED);
TypeElement string = parameter.getElements().getTypeElement("test.test2");
SecurityManager old = System.getSecurityManager();
System.setSecurityManager(new SecMan());
TreePathHandle.create(string, parameter);
System.setSecurityManager(old);
}
}, true);
}
示例14: writeLastKnownIndexers
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private void writeLastKnownIndexers(Map<String, Set<IndexerInfo<T>>> lki) {
Properties props = new Properties();
for(String indexerName : lki.keySet()) {
Set<IndexerInfo<T>> iinfos = lki.get(indexerName);
int indexerVersion = -1;
Set<String> mimeTypes = new HashSet<String>();
for(IndexerInfo<T> iinfo : iinfos) {
if (indexerVersion == -1) {
indexerVersion = iinfo.getIndexerVersion();
} else if (indexerVersion != iinfo.getIndexerVersion()) {
LOG.warning(iinfo.getIndexerFactory() + " has different version then other instances of the same factory: version=" + iinfo.getIndexerVersion() + ", others=" + indexerVersion);
continue;
}
mimeTypes.addAll(iinfo.getMimeTypes());
}
StringBuilder sb = new StringBuilder();
sb.append(indexerVersion);
if (mimeTypes.size() > 0) {
sb.append(",");//NOI18N
for(Iterator<? extends String> i = mimeTypes.iterator(); i.hasNext(); ) {
String mimeType = i.next();
if (mimeType.length() == 0) {
sb.append("<all>"); //NOI18N
break;
} else {
sb.append(mimeType);
if (i.hasNext()) {
sb.append(","); //NOI18N
}
}
}
}
props.put(indexerName, sb.toString());
}
FileObject cacheFolder = CacheFolder.getCacheFolder();
try {
FileObject infoFile = FileUtil.createData(cacheFolder, infoFileName);
OutputStream os = infoFile.getOutputStream();
try {
props.store(os, "Last known indexer " + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(new Date())); //NOI18N
} finally {
os.close();
}
} catch (IOException ioe) {
LOG.log(Level.FINE, "Can't write " + infoFileName + " file in " + cacheFolder.getPath(), ioe); //NOI18N
}
}
示例15: initPopupMenu
import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private static void initPopupMenu (FileObject root, Language l) throws IOException {
List<Feature> actions = l.getFeatureList ().getFeatures("ACTION");
// Could probably use fixed anchor points if these positions settle down:
int selectInPos = findPositionOfDefaultPopupAction("org-netbeans-modules-editor-NbSelectInPopupAction.instance", 1000);
int increment = (findPositionOfDefaultPopupAction("org-openide-actions-CutAction.instance", 2000) - selectInPos) / (actions.size() + 3);
FileObject popup = FileUtil.createFolder (root, "Popup");
int pos = selectInPos + increment;
createSeparator(popup, "SeparatorAfterSelectInPopupAction", pos);
boolean actionAdded = false;
//if (l.getFeatureList ().getFeatures("SEMANTIC_USAGE").size() > 0) {
actionAdded = true;
pos += increment;
FileUtil.createData (popup, "org-netbeans-modules-languages-features-GoToDeclarationAction.instance").setAttribute("position", pos);
//}
if (l.getFeatureList ().getFeatures("INDENT").size() > 0) {
actionAdded = true;
pos += increment;
FileUtil.createData (popup, "format").setAttribute("position", pos);
}
for (Feature action : actions) {
if (action.getBoolean ("explorer", false))
continue;
actionAdded = true;
pos += increment;
String name = action.getSelector ().getAsString ();
String displayName= LocalizationSupport.localize (l, (String)action.getValue ("name"));
String performer = action.getMethodName ("performer");
String enabler = action.getMethodName ("enabled");
/* XXX disabled for now; could use numeric position key if desired:
String installAfter = (String) action.getValue ("install_after");
String installBefore = (String) action.getValue ("install_before");
*/
boolean separatorBefore = action.getBoolean ("separator_before", false);
boolean separatorAfter = action.getBoolean ("separator_after", false);
FileObject fobj = FileUtil.createData (popup, name + ".instance"); // NOI18N
fobj.setAttribute("instanceCreate", new ActionCreator (new Object[] {displayName, performer, enabler})); // NOI18N
fobj.setAttribute("instanceClass", "org.netbeans.modules.languages.features.GenericAction"); // NOI18N
fobj.setAttribute("position", pos);
if (separatorBefore) {
createSeparator(popup, name + "_separator_before", pos - increment / 3);
}
if (separatorAfter) {
createSeparator(popup, name + "_separator_after", pos + increment / 3);
}
}
//FileUtil.createData (popup, "org-netbeans-modules-languages-features-FormatAction.instance").setAttribute("position", ...);
if (actionAdded) {
createSeparator(popup, "SeparatorBeforeCut", pos + increment);
}
if (l.getFeatureList ().getFeatures("FOLD").size() > 0) {
FileUtil.createData (popup, "generate-fold-popup").setAttribute(
"position",
findPositionOfDefaultPopupAction("org-openide-actions-PasteAction.instance", 3000) + 50
);
}
// init actions
}