public void setErr(final PrintStream value) { _interpreter.setErr(value); }
public void setErr(final PrintStream value) { _interpreter.setErr(value); }
/** De-serialization setup. Default out and err streams to stdout, stderr if they are null. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); // set transient fields setOut( System.out ); setErr( System.err ); }
/** De-serialization setup. Default out and err streams to stdout, stderr if they are null. */ private void readObject(ObjectInputStream stream) throws java.io.IOException, ClassNotFoundException { stream.defaultReadObject(); // set transient fields if ( console != null ) { setOut( console.getOut() ); setErr( console.getErr() ); } else { setOut( System.out ); setErr( System.err ); } }
/** Attach a console Note: this method is incomplete. */ public void setConsole( ConsoleInterface console ) { this.console = console; setu( "bsh.console", console ); // redundant with constructor setOut( console.getOut() ); setErr( console.getErr() ); // need to set the input stream - reinit the parser? }
/** Attempt the release of open resources. * @throws IOException */ public void close() throws IOException { EOF = true; if ( null != getErr() ) { if ( !getErr().equals(System.err) ) getErr().close(); setErr(null); } if ( null != getOut() ) { if ( !getOut().equals(System.out) ) getOut().close(); setOut(null); } if ( null != getIn() ) { getIn().close(); console.setIn(null); } }
engine.setErr( scriptOutput ); engine.setOut( scriptOutput );
protected void setup() { final ScriptContext context = getContext(); final Reader reader = context.getReader(); if (reader != null) { log().warn("Beanshell does not support redirecting the input"); } final Writer writer = context.getWriter(); if (writer != null) interpreter.setOut(new PrintStream( new WriterOutputStream(writer))); final Writer errorWriter = context.getErrorWriter(); if (errorWriter != null) interpreter.setErr(new PrintStream( new WriterOutputStream(errorWriter))); }
localInterpreter.console.setIn(null); localInterpreter.setOut(null); localInterpreter.setErr(null); } catch (IOException ioe) { throw new EvalError("Sourced file: "+sourceFileInfo+" "
private Object evalSource(Object source, ScriptContext scriptContext) throws ScriptException { try ( Interpreter bsh = getInterpreter() ) { NameSpace contextNameSpace = getEngineNameSpace(scriptContext); bsh.setNameSpace(contextNameSpace); bsh.setOut(toPrintStream(scriptContext.getWriter())); bsh.setErr(toPrintStream(scriptContext.getErrorWriter())); if (source instanceof Reader) { return bsh.eval((Reader) source); } else { return bsh.eval((String) source); } } catch (ParseException e) { // explicit parsing error throw new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber()); } catch (TargetError e) { // The script threw an application level exception ScriptException se = new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber()); se.initCause(e.getTarget()); throw se; } catch (EvalError e) { // The script couldn't be evaluated properly throw new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber()); } catch (IOException e) { throw new ScriptException(e.toString()); } }
private Object evalSource(Object source, ScriptContext scriptContext) throws ScriptException { bsh.NameSpace contextNameSpace = getEngineNameSpace(scriptContext); Interpreter bsh = getInterpreter(); bsh.setNameSpace(contextNameSpace); bsh.setOut(toPrintStream(scriptContext.getWriter())); bsh.setErr(toPrintStream(scriptContext.getErrorWriter())); try { if (source instanceof Reader) { return bsh.eval((Reader) source); } else { return bsh.eval((String) source); } //} catch (ParseException e) { // explicit parsing error TODO how to handle parse exception ? //throw new ScriptException(e.toString()); //e.getErrorSourceFile(), e.getErrorLineNumber()); } catch (TargetError e) { // The script threw an application level exception // set it as the cause ? ScriptException se = new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber()); se.initCause(e.getTarget()); throw se; } catch (EvalError e) { // The script couldn't be evaluated properly throw new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber()); } catch (InterpreterError e) { // The interpreter had a fatal problem throw new ScriptException(e.toString()); } }