@Override public void setReader(Reader reader) { context.setReader(reader); }
@Override public void setStdinReader(ConsoleInputReader reader) { this.engine.getContext().setReader(new BufferedReader(reader)); }
@Override public void setStdIn( Reader reader ) { if( !( reader instanceof BufferedReader ) ) { reader = new BufferedReader( reader ); } engine.getContext().setReader( reader ); }
public void testReadlines() throws ScriptException { final String testString = "Holy Smokes Batman!\nBIF!\r\n\nKAPOW!!!\rTHE END."; pythonEngine.getContext().setReader(new StringReader(testString)); assertNull(pythonEngine.eval("import sys")); final Object o = pythonEngine.eval("''.join(sys.stdin.readlines())"); assertEquals("Holy Smokes Batman!\nBIF!\n\nKAPOW!!!\nTHE END.\n", o); }
public void testReadline() throws ScriptException { final String testString = "Shazaam Batman!\n"; pythonEngine.getContext().setReader(new StringReader(testString)); assertNull(pythonEngine.eval("import sys")); assertEquals(testString, pythonEngine.eval("sys.stdin.readline()")); }
public EmbeddedScriptEngine(String name, ScriptEngine engine) { this.name = name; this.engine = engine; this.ctx = new SimpleScriptContext(); ctx.setWriter(new StringWriter()); ctx.setErrorWriter(new StringWriter()); ctx.setReader(new StringReader("")); }
protected ScriptContext getScriptContext(Bindings bindings) { if (bindings == null) { throw new NullPointerException("null bindings in engine scope"); } ScriptContext newContext = new SimpleScriptContext(); newContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE); Bindings global = getBindings(ScriptContext.GLOBAL_SCOPE); if (global != null) { newContext.setBindings(global, ScriptContext.GLOBAL_SCOPE); } newContext.setReader(context.getReader()); newContext.setWriter(context.getWriter()); newContext.setErrorWriter(context.getErrorWriter()); return newContext; }
protected ScriptContext getScriptContext(Bindings bindings) { if (bindings == null) { throw new NullPointerException("null bindings in engine scope"); } ScriptContext newContext = new SimpleScriptContext(); newContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE); Bindings global = getBindings(ScriptContext.GLOBAL_SCOPE); if (global != null) { newContext.setBindings(global, ScriptContext.GLOBAL_SCOPE); } newContext.setReader(context.getReader()); newContext.setWriter(context.getWriter()); newContext.setErrorWriter(context.getErrorWriter()); return newContext; }
protected ScriptContext getScriptContext(Bindings bindings) { if (bindings == null) { throw new NullPointerException("null bindings in engine scope"); } ScriptContext newContext = new SimpleScriptContext(); newContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE); Bindings global = getBindings(ScriptContext.GLOBAL_SCOPE); if (global != null) { newContext.setBindings(global, ScriptContext.GLOBAL_SCOPE); } newContext.setReader(context.getReader()); newContext.setWriter(context.getWriter()); newContext.setErrorWriter(context.getErrorWriter()); return newContext; }
protected ScriptContext getScriptContext(Bindings bindings) { if (bindings == null) { throw new NullPointerException("null bindings in engine scope"); } ScriptContext newContext = new SimpleScriptContext(); newContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE); Bindings global = getBindings(ScriptContext.GLOBAL_SCOPE); if (global != null) { newContext.setBindings(global, ScriptContext.GLOBAL_SCOPE); } newContext.setReader(context.getReader()); newContext.setWriter(context.getWriter()); newContext.setErrorWriter(context.getErrorWriter()); return newContext; }
/** * Returns a {@link SimpleScriptContext} which: * <ul> * <li>uses the specified {@link Bindings} as the {@link ScriptEngine#ENGINE_SCOPE}</li> * <li>has the same GLOBAL_SCOPE Bindings as the current context</li> * <li>uses the same Reader, Writer and Error Writer as the current context</li> * </ul> * * @param bindings the bindings to be associated with ENGINE_SCOPE * @return an instance of SimpleScriptContext * * @throws NullPointerException if bindings is <tt>null</tt> */ protected ScriptContext getScriptContext(Bindings bindings){ if (bindings == null) { throw new NullPointerException("ENGINE_SCOPE bindings cannot be null"); } ScriptContext scriptContext = new SimpleScriptContext(); scriptContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE); scriptContext.setBindings(this.getBindings(ScriptContext.GLOBAL_SCOPE), ScriptContext.GLOBAL_SCOPE); scriptContext.setReader(this.context.getReader()); scriptContext.setWriter(this.context.getWriter()); scriptContext.setErrorWriter(this.context.getErrorWriter()); return scriptContext; }
ctx.setReader(new LazyReader());
protected ScriptContext getScriptContext(Bindings bindings) { ScriptContext result = new SimpleScriptContext(); if (bindings != null) { result.setBindings(bindings, ScriptContext.ENGINE_SCOPE); } if (context.getBindings(ScriptContext.GLOBAL_SCOPE) != null) { result.setBindings(context.getBindings(ScriptContext.GLOBAL_SCOPE), ScriptContext.GLOBAL_SCOPE); } result.setReader(context.getReader()); result.setWriter(context.getWriter()); result.setErrorWriter(context.getErrorWriter()); return result; } }
scriptContext.setReader(currentReader);
ScriptContext oldContext = getEngine().getContext(); context.setBindings(oldContext.getBindings(ScriptContext.GLOBAL_SCOPE), ScriptContext.GLOBAL_SCOPE); context.setReader(oldContext.getReader()); context.setWriter(oldContext.getWriter()); context.setErrorWriter(oldContext.getErrorWriter());