本文整理汇总了Java中org.openide.filesystems.FileObject.asText方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.asText方法的具体用法?Java FileObject.asText怎么用?Java FileObject.asText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.filesystems.FileObject
的用法示例。
在下文中一共展示了FileObject.asText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetAllMappings
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testGetAllMappings() throws IOException {
System.out.println("\nALL Mappings:");
FileObject grsm = getTestFile("sourcemaps/greeter.js.map");
SourceMap sm = SourceMap.parse(grsm.asText());
FileObject goldenDirectMappingFO = getTestFile("sourcemaps/greeter.dmapping");
String goldenDirectMapping = goldenDirectMappingFO.asText();
BufferedReader gdm = new BufferedReader(new StringReader(goldenDirectMapping));
for (int l = 0; l < 100; l++) {
List<Mapping> allLineMappings = sm.findAllMappings(l);
if (allLineMappings != null) {
for (Mapping m : allLineMappings) {
String map = l+","+m.getColumn()+"->"+m.getOriginalLine()+","+m.getOriginalColumn();
String line = gdm.readLine();
if (line == null) {
throw new IOException("Golden file finished prematurely when processing line "+l+" and mapping: "+map);
}
assertEquals(line, map);
}
}
}
assertNull(gdm.readLine());
}
示例2: testGetAllInverseMappings
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testGetAllInverseMappings() throws IOException {
System.out.println("\nALL Mappings:");
FileObject grsm = getTestFile("sourcemaps/greeter.js.map");
SourceMap sm = SourceMap.parse(grsm.asText());
FileObject goldenInverseMappingFO = getTestFile("sourcemaps/greeter.imapping");
String goldenInverseMapping = goldenInverseMappingFO.asText();
BufferedReader gim = new BufferedReader(new StringReader(goldenInverseMapping));
for (int l = 0; l < 100; l++) {
List<Mapping> allLineMappings = sm.findAllInverseMappings("greeter.ts", l);
if (allLineMappings != null) {
for (Mapping m : allLineMappings) {
String map = l+","+m.getColumn()+"->"+m.getOriginalLine()+","+m.getOriginalColumn();
String line = gim.readLine();
if (line == null) {
throw new IOException("Golden file finished prematurely when processing line "+l+" and mapping: "+map);
}
assertEquals(line, map);
}
}
}
assertNull(gim.readLine());
}
示例3: getContentLineShift
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
*
* @param url
* @param content
* @return a non-negative line shift of content of 'url' in 'content', or -1
* when content of 'url' is not a subset of 'content'.
*/
static int getContentLineShift(URL url, String content) {
String origContent;
FileObject fo = URLMapper.findFileObject(url);
if (fo != null) {
try {
origContent = fo.asText();
} catch (IOException ex) {
return 0;
}
} else {
return 0;
}
int index = content.indexOf(origContent);
if (index < 0) {
return -1;
}
String prep = content.substring(0, index);
return countNewLines(prep);
}
示例4: testWriteRecreatedFile
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testWriteRecreatedFile() throws Exception {
FileObject fo = root.getFileObject("testdir/mountdir4/file.ext");
assertNotNull("File found properly", fo);
String txt = fo.asText("UTF-8");
File f = FileUtil.toFile(fo);
f.delete();
fo.getParent().refresh();
assertFalse("No longer valid", fo.isValid());
f.createNewFile();
OutputStream os = fo.getOutputStream();
os.write("Ahoj".getBytes());
os.close();
String newTxt = fo.asText("UTF-8");
assertEquals("Text read even the file object is not valid anymore", "Ahoj", newTxt);
assertFalse("Still invalid", fo.isValid());
}
示例5: testReadWrite
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testReadWrite() throws Exception {
AnnoFoo foo = new AnnoFoo();
foo.setName("xxx");
DataFolder test = DataFolder.findFolder(FileUtil.getConfigRoot());
DataObject obj = InstanceDataObject.create(test, null, foo, null);
final FileObject pf = obj.getPrimaryFile();
final String content = pf.asText();
if (content.indexOf("<string>xxx</string>") == -1) {
fail(content);
}
obj.setValid(false);
DataObject newObj = DataObject.find(pf);
if (newObj == obj) {
fail("Strange, objects shall differ");
}
InstanceCookie ic = newObj.getLookup().lookup(InstanceCookie.class);
assertNotNull("Instance cookie found", ic);
Object read = ic.instanceCreate();
assertNotNull("Instance created", read);
assertEquals("Correct class", AnnoFoo.class, read.getClass());
AnnoFoo readFoo = (AnnoFoo)read;
assertEquals("property changed", "xxx", readFoo.getName());
}
示例6: replaceInFilePreserveCase
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
* Helper method - create file, write its content, find it, replace in it
* and return its new content.
*/
public String replaceInFilePreserveCase(String fileContent, String find,
String replace) throws IOException, InterruptedException,
InvocationTargetException {
BasicSearchCriteria bsc = new BasicSearchCriteria();
bsc.setTextPattern(find);
bsc.setMatchType(SearchPattern.MatchType.BASIC);
bsc.setReplaceExpr(replace);
bsc.setPreserveCase(true);
bsc.onOk();
FileObject fo = createTestFile(fileContent);
SearchScopeDefinition ss = new TempFileSearchScope(fo);
SearchInfo si = ss.getSearchInfo();
final SearchComposition<Def> sc =
new BasicComposition(si,
new DefaultMatcher(bsc.getSearchPattern()),
bsc, null);
EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
sc.getSearchResultsDisplayer().getVisualComponent(); // initialize model
final SearchTask st = new SearchTask(sc, true);
st.run();
}
});
ReplaceTask rt = new ReplaceTask(
((ResultDisplayer) sc.getSearchResultsDisplayer()).getResultModel().getMatchingObjects(),
null);
rt.run();
String result = fo.asText(TEST_FILE_ENC);
return result;
}
示例7: testReadWriteNotForSubclasses
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testReadWriteNotForSubclasses() throws Exception {
NotFoo foo = new NotFoo();
foo.setName("xxx");
DataFolder test = DataFolder.findFolder(FileUtil.getConfigRoot());
try {
DataObject obj = InstanceDataObject.create(test, null, foo, null);
final FileObject pf = obj.getPrimaryFile();
final String content = pf.asText();
fail(content);
} catch (NotSerializableException ex) {
// OK
}
}
示例8: testPerformance
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testPerformance() throws IOException {
FileObject file = getTestFile("testfiles/huge.html");
String content = file.asText();
TokenHierarchy hi = TokenHierarchy.create(content, HTMLTokenId.language());
ElementsParser parser = ElementsParser.forTokenIndex(content, hi.tokenSequence(HTMLTokenId.language()), 0);
long start = System.currentTimeMillis();
while (parser.hasNext()) {
parser.next();
}
long end = System.currentTimeMillis();
float diff1 = end - start;
System.out.println("first iteration took " + diff1 + "ms.");
//~2500ms
//second attempt
parser = ElementsParser.forTokenIndex(content, hi.tokenSequence(HTMLTokenId.language()), 0);
start = System.currentTimeMillis();
while (parser.hasNext()) {
parser.next();
}
end = System.currentTimeMillis();
float diff2 = end - start;
System.out.println("second iteration took " + diff2 + "ms.");
//~600ms
float ratio = diff1 / diff2;
System.out.println("first / second ratio = " + ratio);
}
示例9: assertFileDoesNotContain
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private static void assertFileDoesNotContain(File file, String text) throws IOException, PropertyVetoException {
LocalFileSystem lfs = new LocalFileSystem();
lfs.setRootDirectory(file.getParentFile());
FileObject fo = lfs.findResource(file.getName());
assertNotNull("file object for " + file + " found", fo);
String content = fo.asText();
if (content.contains(text)) {
fail("File " + file + " seems to contain '" + text + "'!");
}
}
示例10: testIssue238864
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testIssue238864() throws Exception {
FileObject testFile = getTestFile("testfiles/scss/large_empty.scss.txt");
String source = testFile.asText();
ExtCss3Lexer lexer = createLexer(source);
assertANTLRToken(null, Css3Lexer.NL, lexer.nextToken());
assertANTLRToken(null, Css3Lexer.EOF, lexer.nextToken());
}
示例11: assertMessage
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private String assertMessage(FileObject extensionXml) {
try {
return "Extension file:" + extensionXml.asText() + " is owned by " + FileOwnerQuery.getOwner(extensionXml) +
" but should be " + implementation.getOwningProject();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
return ex.getMessage();
}
}
示例12: testAcceptVisitorGeneric_speed
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testAcceptVisitorGeneric_speed() throws IOException {
FileObject file = getTestFile("testfiles/bootstrap.css");
String content = file.asText();
System.out.println("Testing performance on " + file.getNameExt() + " ... ");
long a = System.currentTimeMillis();
CssParserResult result = TestUtil.parse(content);
long b = System.currentTimeMillis();
System.out.println("file parsing took " + (b - a) + "ms.");
Model model = createModel(result);
long c = System.currentTimeMillis();
System.out.println("model creation took " + (c - b) + "ms.");
StyleSheet s = getStyleSheet(model);
assertNotNull(s);
ModelVisitor visitor = new ModelVisitor.Adapter() {
@Override
public void visitRule(Rule rule) {
//no-op
}
};
s.accept(visitor);
long d = System.currentTimeMillis();
System.out.println("visiting took " + (d - c) + "ms.");
}
示例13: testModeIsOK
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testModeIsOK() throws Exception {
FileObject set = FileUtil.getConfigFile("Windows2/Modes/output/my-tc.wstcref");
assertNotNull("Mode file found", set);
final String t = set.asText();
assertValidate(t);
assertEquals("not opened, no true in there", -1, t.indexOf("true"));
}
示例14: testFactoryModeIsOK
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testFactoryModeIsOK() throws Exception {
FileObject set = FileUtil.getConfigFile("Windows2/Modes/explorer/factory-tc.wstcref");
assertNotNull("Mode file found", set);
final String t = set.asText();
assertValidate(t);
assertTrue("opened, no true in there", t.indexOf("true") > 0);
}
示例15: computeIntroduceClass
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
String computeIntroduceClass(String className, FileObject fo) throws IOException {
String fileText = fo.asText();
StringBuilder textBuilder = new StringBuilder(fileText);
String classText = ((this.staticContext) ? "static " : "") + "class "+className+" {\n"+
"public "+className+"() {}\n"+
this.methodBodyCode+"\n}";
textBuilder.insert((int) this.classGeneratePosition, classText);
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Inserted class: '"+classText+"'");
LOG.fine("Updated full file content:\n'"+textBuilder.toString()+"'");
}
return textBuilder.toString();
}