本文整理汇总了Java中com.google.common.io.Resources.newInputStreamSupplier方法的典型用法代码示例。如果您正苦于以下问题:Java Resources.newInputStreamSupplier方法的具体用法?Java Resources.newInputStreamSupplier怎么用?Java Resources.newInputStreamSupplier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.io.Resources
的用法示例。
在下文中一共展示了Resources.newInputStreamSupplier方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClassBody
import com.google.common.io.Resources; //导入方法依赖的package包/类
private String getClassBody(Class<?> c) throws CompileException, IOException{
String path = c.getName();
path = path.replaceFirst("\\$.*", "");
path = path.replace(".", FileUtils.separator);
path = "/" + path + ".java";
URL u = Resources.getResource(c, path);
InputSupplier<InputStream> supplier = Resources.newInputStreamSupplier(u);
try (InputStream is = supplier.getInput()) {
if (is == null) {
throw new IOException(String.format("Failure trying to located source code for Class %s, tried to read on classpath location %s", c.getName(), path));
}
String body = IO.toString(is);
//TODO: Hack to remove annotations so Janino doesn't choke. Need to reconsider this problem...
//return body.replaceAll("@(?:Output|Param|Workspace|Override|SuppressWarnings\\([^\\\\]*?\\)|FunctionTemplate\\([^\\\\]*?\\))", "");
return body.replaceAll("@(?:\\([^\\\\]*?\\))?", "");
}
}
示例2: get
import com.google.common.io.Resources; //导入方法依赖的package包/类
private CompilationUnit get(Class<?> c) throws IOException{
String path = c.getName();
path = path.replaceFirst("\\$.*", "");
path = path.replace(".", FileUtils.separator);
path = "/" + path + ".java";
CompilationUnit cu = functionUnits.get(path);
if(cu != null) {
return cu;
}
URL u = Resources.getResource(c, path);
InputSupplier<InputStream> supplier = Resources.newInputStreamSupplier(u);
try (InputStream is = supplier.getInput()) {
if (is == null) {
throw new IOException(String.format("Failure trying to located source code for Class %s, tried to read on classpath location %s", c.getName(), path));
}
String body = IO.toString(is);
//TODO: Hack to remove annotations so Janino doesn't choke. Need to reconsider this problem...
body = body.replaceAll("@\\w+(?:\\([^\\\\]*?\\))?", "");
try{
cu = new Parser(new Scanner(null, new StringReader(body))).parseCompilationUnit();
functionUnits.put(path, cu);
return cu;
} catch (CompileException e) {
logger.warn("Failure while parsing function class:\n{}", body, e);
return null;
}
}
}