本文整理汇总了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."));
}
示例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);
}
}