aboutsummaryrefslogtreecommitdiff
path: root/java/src/main
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2018-09-08 14:59:18 -0400
committerPaul Duncan <pabs@pablotron.org>2018-09-08 14:59:18 -0400
commitfc93b32955b3a30ad884e4a9b14ebe052b86f120 (patch)
treece5cceb4b92a0cc1684279035a9d27991bf512c8 /java/src/main
parent7798c9eff73a6650f2aa91a905ebfd773090425d (diff)
downloadluigi-template-fc93b32955b3a30ad884e4a9b14ebe052b86f120.tar.bz2
luigi-template-fc93b32955b3a30ad884e4a9b14ebe052b86f120.zip
java: replace ResultHandler with Appendable interface
Diffstat (limited to 'java/src/main')
-rw-r--r--java/src/main/java/org/pablotron/luigi/Cache.java11
-rw-r--r--java/src/main/java/org/pablotron/luigi/ResultHandler.java13
-rw-r--r--java/src/main/java/org/pablotron/luigi/Template.java31
3 files changed, 22 insertions, 33 deletions
diff --git a/java/src/main/java/org/pablotron/luigi/Cache.java b/java/src/main/java/org/pablotron/luigi/Cache.java
index b93d564..65849fa 100644
--- a/java/src/main/java/org/pablotron/luigi/Cache.java
+++ b/java/src/main/java/org/pablotron/luigi/Cache.java
@@ -2,6 +2,7 @@ package org.pablotron.luigi;
import java.util.Map;
import java.util.HashMap;
+import java.io.IOException;
import org.pablotron.luigi.Filter;
import org.pablotron.luigi.Template;
@@ -54,7 +55,7 @@ public final class Cache {
public String run(
final String key,
final Map<String, String> args
- ) throws LuigiError {
+ ) throws LuigiError, IOException {
// run template with args
return get(key).run(args);
}
@@ -65,17 +66,17 @@ public final class Cache {
*
* @param key Template key.
* @param args Template arguments map.
- * @param rh Result handler.
+ * @param out Appendable output interface.
*
* @throws UnknownTemplateError if the given template does not exist.
*/
public void run(
final String key,
final Map<String, String> args,
- final ResultHandler rh
- ) throws LuigiError {
+ final Appendable out
+ ) throws LuigiError, IOException {
// run template with args and result handler
- get(key).run(args, rh);
+ get(key).run(args, out);
}
/**
diff --git a/java/src/main/java/org/pablotron/luigi/ResultHandler.java b/java/src/main/java/org/pablotron/luigi/ResultHandler.java
deleted file mode 100644
index 65654e9..0000000
--- a/java/src/main/java/org/pablotron/luigi/ResultHandler.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package org.pablotron.luigi;
-
-/**
- * Result handler for streamed results from template runs.
- */
-public interface ResultHandler {
- /**
- * Called during template run with each chunk of the result.
- *
- * @param chunk Chunk of result.
- */
- public abstract void append(final String chunk);
-};
diff --git a/java/src/main/java/org/pablotron/luigi/Template.java b/java/src/main/java/org/pablotron/luigi/Template.java
index 73eb89d..5c40f3c 100644
--- a/java/src/main/java/org/pablotron/luigi/Template.java
+++ b/java/src/main/java/org/pablotron/luigi/Template.java
@@ -1,6 +1,7 @@
package org.pablotron.luigi;
import java.util.Map;
+import java.io.IOException;
import org.pablotron.luigi.Parser;
import org.pablotron.luigi.Filter;
@@ -66,11 +67,11 @@ public final class Template {
}
/**
- * Run this template with given arguments, and pass each result chunks
- * to the given result handler.
+ * Run this template with given arguments, and pass each chunk of
+ # the result to the given output object.
*
* @param args Template arguments.
- * @param rh Result handler.
+ * @param out Appendable output interface.
*
* @throws UnknownKeyError If a key specified in the template does not exist.
* @throws UnknownFilterError If a filter specified in the template does not exist.
@@ -78,10 +79,10 @@ public final class Template {
*/
public void run(
final Map<String, String> args,
- final ResultHandler r
- ) throws LuigiError {
+ final Appendable out
+ ) throws LuigiError, IOException {
for (Action a: this.actions) {
- r.append(a.run(this.filters, args));
+ out.append(a.run(this.filters, args));
}
}
@@ -127,9 +128,9 @@ public final class Template {
public static void run(
final String template,
final Map<String, String> args,
- final ResultHandler rh
- ) throws LuigiError {
- run(template, args, Filter.FILTERS, rh);
+ final Appendable out
+ ) throws LuigiError, IOException {
+ run(template, args, Filter.FILTERS, out);
}
/**
@@ -156,13 +157,13 @@ public final class Template {
}
/**
- * Create and run template with given arguments, filters, and result
- * handler.
+ * Create and run template with given arguments, filters, and
+ * appendable.
*
* @param template Template string.
* @param args Template arguments.
* @param filters Template filters.
- * @param rh Result handler that result chunks are passed to.
+ * @param out Appendable output interface.
*
* @throws UnknownKeyError If a key specified in the template does not exist.
* @throws UnknownFilterError If a filter specified in the template does not exist.
@@ -172,9 +173,9 @@ public final class Template {
final String template,
final Map<String, String> args,
final Map<String, Filter.Handler> filters,
- final ResultHandler rh
- ) throws LuigiError {
+ final Appendable out
+ ) throws LuigiError, IOException {
final Template t = new Template(template, filters);
- t.run(args, rh);
+ t.run(args, out);
}
};