本文整理汇总了Java中javax.tools.FileObject.openReader方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.openReader方法的具体用法?Java FileObject.openReader怎么用?Java FileObject.openReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.tools.FileObject
的用法示例。
在下文中一共展示了FileObject.openReader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertClass
import javax.tools.FileObject; //导入方法依赖的package包/类
/**
* Convert the given Class to an HTML.
*
* @param te the class to convert.
* @param outputdir the name of the directory to output to
* @throws DocFileIOException if there is a problem generating the output file
* @throws SimpleDocletException if there is a problem reading the source file
*/
public void convertClass(TypeElement te, DocPath outputdir)
throws DocFileIOException, SimpleDocletException {
if (te == null) {
return;
}
FileObject fo = utils.getFileObject(te);
if (fo == null)
return;
try {
Reader r = fo.openReader(true);
int lineno = 1;
String line;
relativePath = DocPaths.SOURCE_OUTPUT
.resolve(DocPath.forPackage(utils, te))
.invert();
Content body = getHeader();
Content pre = new HtmlTree(HtmlTag.PRE);
try (LineNumberReader reader = new LineNumberReader(r)) {
while ((line = reader.readLine()) != null) {
addLineNo(pre, lineno);
addLine(pre, line, lineno);
lineno++;
}
}
addBlankLines(pre);
Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre);
body.addContent((configuration.allowTag(HtmlTag.MAIN)) ? HtmlTree.MAIN(div) : div);
writeToFile(body, outputdir.resolve(DocPath.forClass(utils, te)));
} catch (IOException e) {
String message = configuration.resources.getText("doclet.exception.read.file", fo.getName());
throw new SimpleDocletException(message, e);
}
}
示例2: SimpleResourceReader
import javax.tools.FileObject; //导入方法依赖的package包/类
public SimpleResourceReader(FileObject fileObject) throws IOException {
this.fileObject = fileObject;
this.foReader = new BufferedReader(fileObject.openReader(true));
}
示例3: convertClass
import javax.tools.FileObject; //导入方法依赖的package包/类
/**
* Convert the given Class to an HTML.
*
* @param cd the class to convert.
* @param outputdir the name of the directory to output to.
*/
public void convertClass(ClassDoc cd, DocPath outputdir) {
if (cd == null) {
return;
}
try {
SourcePosition sp = cd.position();
if (sp == null)
return;
Reader r;
// temp hack until we can update SourcePosition API.
if (sp instanceof com.sun.tools.javadoc.SourcePositionImpl) {
FileObject fo = ((com.sun.tools.javadoc.SourcePositionImpl) sp).fileObject();
if (fo == null)
return;
r = fo.openReader(true);
} else {
File file = sp.file();
if (file == null)
return;
r = new FileReader(file);
}
LineNumberReader reader = new LineNumberReader(r);
int lineno = 1;
String line;
relativePath = DocPaths.SOURCE_OUTPUT
.resolve(DocPath.forPackage(cd))
.invert();
Content body = getHeader();
Content pre = new HtmlTree(HtmlTag.PRE);
try {
while ((line = reader.readLine()) != null) {
addLineNo(pre, lineno);
addLine(pre, line, lineno);
lineno++;
}
} finally {
reader.close();
}
addBlankLines(pre);
Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre);
body.addContent(div);
writeToFile(body, outputdir.resolve(DocPath.forClass(cd)));
} catch (IOException e) {
e.printStackTrace();
}
}