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


Java ResourceGroovyMethods.readLines方法代码示例

本文整理汇总了Java中org.codehaus.groovy.runtime.ResourceGroovyMethods.readLines方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceGroovyMethods.readLines方法的具体用法?Java ResourceGroovyMethods.readLines怎么用?Java ResourceGroovyMethods.readLines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.groovy.runtime.ResourceGroovyMethods的用法示例。


在下文中一共展示了ResourceGroovyMethods.readLines方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCustomClassTemplate

import org.codehaus.groovy.runtime.ResourceGroovyMethods; //导入方法依赖的package包/类
public void testCustomClassTemplate() throws Exception {
    executeTarget("testCustomClassTemplate");

    final File testfilesPackageDir = new File(tmpDir, "org/codehaus/groovy/tools/groovydoc/testfiles");
    System.err.println("testfilesPackageDir = " + testfilesPackageDir);
    final String[] list = testfilesPackageDir.list(new FilenameFilter() {
        public boolean accept(File file, String name) {
            return name.equals("DocumentedClass.html");
        }
    });

    assertNotNull("Dir not found: " + testfilesPackageDir.getAbsolutePath(), list);
    assertEquals(1, list.length);
    File documentedClassHtmlDoc = new File(testfilesPackageDir, list[0]);

    List<String> lines = ResourceGroovyMethods.readLines(documentedClassHtmlDoc);
    assertTrue("\"<title>DocumentedClass</title>\" not in: " + lines, lines.contains("<title>DocumentedClass</title>"));
    assertTrue("\"This is a custom class template.\" not in: " + lines, lines.contains("This is a custom class template."));
}
 
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:GroovyDocTest.java

示例2: asCollection

import org.codehaus.groovy.runtime.ResourceGroovyMethods; //导入方法依赖的package包/类
public static Collection asCollection(Object value) {
    if (value == null) {
        return Collections.EMPTY_LIST;
    } else if (value instanceof Collection) {
        return (Collection) value;
    } else if (value instanceof Map) {
        Map map = (Map) value;
        return map.entrySet();
    } else if (value.getClass().isArray()) {
        return arrayAsCollection(value);
    } else if (value instanceof MethodClosure) {
        MethodClosure method = (MethodClosure) value;
        IteratorClosureAdapter adapter = new IteratorClosureAdapter(method.getDelegate());
        method.call(adapter);
        return adapter.asList();
    } else if (value instanceof String || value instanceof GString) {
        return StringGroovyMethods.toList((CharSequence) value);
    } else if (value instanceof File) {
        try {
            return ResourceGroovyMethods.readLines((File) value);
        } catch (IOException e) {
            throw new GroovyRuntimeException("Error reading file: " + value, e);
        }
    } else if (value instanceof Class && ((Class) value).isEnum()) {
        Object[] values = (Object[]) InvokerHelper.invokeMethod(value, "values", EMPTY_OBJECT_ARRAY);
        return Arrays.asList(values);
    } else {
        // let's assume it's a collection of 1
        return Collections.singletonList(value);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:32,代码来源:DefaultTypeTransformation.java


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