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


Java Resources.newInputStreamSupplier方法代码示例

本文整理汇总了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("@(?:\\([^\\\\]*?\\))?", "");
  }

}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:20,代码来源:FunctionConverter.java

示例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;
    }

  }

}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:33,代码来源:FunctionConverter.java


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