本文整理匯總了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 );
}