本文整理匯總了Java中groovy.lang.GroovyClassLoader.close方法的典型用法代碼示例。如果您正苦於以下問題:Java GroovyClassLoader.close方法的具體用法?Java GroovyClassLoader.close怎麽用?Java GroovyClassLoader.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類groovy.lang.GroovyClassLoader
的用法示例。
在下文中一共展示了GroovyClassLoader.close方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildClosure
import groovy.lang.GroovyClassLoader; //導入方法依賴的package包/類
public static Closure<?> buildClosure(String... strings) throws IOException {
Closure<?> closure = null;
// Create a method returning a closure
StringBuilder sb = new StringBuilder("def closure() { { script -> ");
sb.append(StringUtils.join(strings, "\n"));
sb.append(" } }");
// Create an anonymous class for the method
GroovyClassLoader loader = new GroovyClassLoader();
Class<?> groovyClass = loader.parseClass(sb.toString());
try {
// Create an instance of the class
GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
// Invoke the object's method and thus obtain the closure
closure = (Closure<?>) groovyObject.invokeMethod("closure", null);
} catch (Throwable e) {
throw new RuntimeException(e);
} finally {
loader.close();
}
return closure;
}
示例2: QuotaHandler
import groovy.lang.GroovyClassLoader; //導入方法依賴的package包/類
public QuotaHandler(Quota config) {
super();
this.config = config;
GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
try {
scriptClass = groovyClassLoader.parseClass(config.getQuotaKeyFunction());
} finally {
try {
groovyClassLoader.close();
} catch (IOException e) {}
}
}