本文整理汇总了Java中javax.script.ScriptContext.setWriter方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptContext.setWriter方法的具体用法?Java ScriptContext.setWriter怎么用?Java ScriptContext.setWriter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.script.ScriptContext
的用法示例。
在下文中一共展示了ScriptContext.setWriter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runScript
import javax.script.ScriptContext; //导入方法依赖的package包/类
public static void runScript(Network network, Reader reader, Writer out) {
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine jsEngine = mgr.getEngineByName("js");
try {
ScriptContext context = new SimpleScriptContext();
context.setAttribute("network", network, ScriptContext.ENGINE_SCOPE);
if (out != null) {
context.setWriter(out);
}
jsEngine.eval(reader, context);
} catch (ScriptException e) {
throw new PowsyblException(e);
}
}
示例2: start
import javax.script.ScriptContext; //导入方法依赖的package包/类
protected void start(boolean console) {
ScriptContext context = engine.getContext();
OutputStream out = getOutputStream();
if (out != null) {
context.setWriter(new PrintWriter(out));
}
OutputStream err = getErrorStream();
if (err != null) {
context.setErrorWriter(new PrintWriter(err));
}
// load "sa.js" initialization file
loadInitFile();
// load "~/jsdb.js" (if found) to perform user specific
// initialization steps, if any.
loadUserInitFile();
JSJavaFactory fac = getJSJavaFactory();
JSJavaVM jvm = (fac != null)? fac.newJSJavaVM() : null;
// call "main" function from "sa.js" -- main expects
// 'this' object and jvm object
call("main", new Object[] { this, jvm });
// if asked, start read-eval-print console
if (console) {
processSource(null);
}
}
示例3: applyTo
import javax.script.ScriptContext; //导入方法依赖的package包/类
public void applyTo ( final ScriptContext scriptContext )
{
scriptContext.setWriter ( new PrintWriter ( new OutputStreamWriter ( this.writerStream ) ) );
scriptContext.setErrorWriter ( this.errorPrintWriter );
}