From 534d72746eeffb3e373d84b1a45a007024933e73 Mon Sep 17 00:00:00 2001 From: "t.lan" Date: Tue, 24 Dec 2024 11:03:29 +0800 Subject: [PATCH] aviator instance --- .../aviator/AviatorEvaluatorInstance.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/main/java/com/googlecode/aviator/AviatorEvaluatorInstance.java b/src/main/java/com/googlecode/aviator/AviatorEvaluatorInstance.java index bbdff43b..9628dfa3 100644 --- a/src/main/java/com/googlecode/aviator/AviatorEvaluatorInstance.java +++ b/src/main/java/com/googlecode/aviator/AviatorEvaluatorInstance.java @@ -555,6 +555,41 @@ public Expression compileScript(final String path) throws IOException { return this.compileScript(path, this.cachedExpressionByDefault); } + /** + * Compile a script into expression. + * + * @param cacheKey caching key when cached is true. + * @param in the script file's InputStream + * @param name source file name + * @return the compiled expression instance. + * @throws IOException + * @since 5.0.0 + */ + public Expression compileScript(final String cacheKey, final InputStream in, + final String name) + throws IOException { + return this.compileScript(cacheKey, in, name, this.cachedExpressionByDefault); + } + + /** + * Compile a script into expression. + * + * @param cacheKey caching key when cached is true. + * @param in the script file's InputStream + * @param name source file name + * @param cached whether to cache the expression instance by cacheKey. + * @return the compiled expression instance. + * @throws IOException + * @since 5.0.0 + */ + public Expression compileScript(final String cacheKey, final InputStream in, + final String name, final boolean cached) + throws IOException { + Reader reader = new InputStreamReader(in, Charset.forName("utf-8")); + return compile(cacheKey, Utils.readFully(reader), name, cached); + } + + /** * Returns the function missing handler, null if not set. *