/** * Is this IO closed * * @return true if closed */ public boolean isClosed() { return (openFile.getMainStream() == null && openFile.getPipeStream() == null); }
myOpenFile.checkReadable(runtime); myOpenFile.setReadBuffered(); waitReadable(myOpenFile.getMainStream());
/** * Is this IO closed * * @return true if closed */ public boolean isClosed() { return (openFile.getMainStream() == null && openFile.getPipeStream() == null); }
myOpenFile.checkReadable(runtime); myOpenFile.setReadBuffered(); waitReadable(myOpenFile.getMainStream());
private void SET_BINARY_MODE() { openFile.getMainStream().setBinmode(); }
public boolean writeDataBuffered() { return openFile.getMainStream().writeDataBuffered(); }
private void SET_BINARY_MODE() { openFile.getMainStream().setBinmode(); }
public boolean writeDataBuffered() { return openFile.getMainStream().writeDataBuffered(); }
/** * Replaces a standard input by a specified reader * * @param reader is a reader to be set */ public void setReader(Reader reader) { if (reader == null) { return; } Map map = getAttributeMap(); if (map.containsKey(AttributeName.READER)) { Reader old = (Reader) map.get(AttributeName.READER); if (old == reader) { return; } } map.put(AttributeName.READER, reader); InputStream istream = new ReaderInputStream(reader); Ruby runtime = provider.getRuntime(); RubyIO io = new RubyIO(runtime, istream); io.getOpenFile().getMainStream().setSync(true); runtime.defineVariable(new InputGlobalVariable(runtime, "$stdin", io), GlobalVariable.Scope.GLOBAL); runtime.getObject().storeConstant("STDIN", io); }
/** * Replaces a standard input by a specified reader * * @param reader is a reader to be set */ public void setReader(Reader reader) { if (reader == null) { return; } Map map = getAttributeMap(); if (map.containsKey(AttributeName.READER)) { Reader old = (Reader) map.get(AttributeName.READER); if (old == reader) { return; } } map.put(AttributeName.READER, reader); InputStream istream = new ReaderInputStream(reader); Ruby runtime = provider.getRuntime(); RubyIO io = new RubyIO(runtime, istream); io.getOpenFile().getMainStream().setSync(true); runtime.defineVariable(new InputGlobalVariable(runtime, "$stdin", io), GlobalVariable.Scope.GLOBAL); runtime.getObject().storeConstant("STDIN", io); }
private void setErrorStream(PrintStream error) { if (error == null) { return; } Ruby runtime = provider.getRuntime(); RubyIO io = new RubyIO(runtime, error); io.getOpenFile().getMainStream().setSync(true); runtime.defineVariable(new OutputGlobalVariable(runtime, "$stderr", io), GlobalVariable.Scope.GLOBAL); runtime.getObject().storeConstant("STDERR", io); runtime.getGlobalVariables().alias("$deferr", "$stderr"); }
private void setErrorStream(PrintStream error) { if (error == null) { return; } Ruby runtime = provider.getRuntime(); RubyIO io = new RubyIO(runtime, error); io.getOpenFile().getMainStream().setSync(true); runtime.defineVariable(new OutputGlobalVariable(runtime, "$stderr", io), GlobalVariable.Scope.GLOBAL); runtime.getObject().storeConstant("STDERR", io); runtime.getGlobalVariables().alias("$deferr", "$stderr"); }
private void setOutputStream(PrintStream pstream) { if (pstream == null) { return; } Ruby runtime = provider.getRuntime(); RubyIO io = new RubyIO(runtime, pstream); io.getOpenFile().getMainStream().setSync(true); runtime.defineVariable(new OutputGlobalVariable(runtime, "$stdout", io), GlobalVariable.Scope.GLOBAL); runtime.getObject().storeConstant("STDOUT", io); runtime.getGlobalVariables().alias("$>", "$stdout"); runtime.getGlobalVariables().alias("$defout", "$stdout"); }
public RubyIO(Ruby runtime, Channel channel) { super(runtime, runtime.getIO()); // We only want IO objects with valid streams (better to error now). if (channel == null) { throw runtime.newRuntimeError("Opening null channel"); } openFile = new OpenFile(); try { openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(channel))); } catch (InvalidValueException e) { throw getRuntime().newErrnoEINVALError(); } openFile.setMode(openFile.getMainStream().getModes().getOpenFileFlags()); }
mainStream = ChannelStream.open(runtime, descriptor); openFile.setMainStream(mainStream); openFile.getMainStream().setSync(true); break; case ERR: mainStream = ChannelStream.open(runtime, descriptor); openFile.setMainStream(mainStream); openFile.getMainStream().setSync(true); break; openFile.setMode(openFile.getMainStream().getModes().getOpenFileFlags());
mainStream = ChannelStream.open(runtime, descriptor); openFile.setMainStream(mainStream); openFile.getMainStream().setSync(true); break; case ERR: mainStream = ChannelStream.open(runtime, descriptor); openFile.setMainStream(mainStream); openFile.getMainStream().setSync(true); break; openFile.setMode(openFile.getMainStream().getModes().getOpenFileFlags());
public RubyIO(Ruby runtime, Channel channel) { super(runtime, runtime.getIO()); // We only want IO objects with valid streams (better to error now). if (channel == null) { throw runtime.newRuntimeError("Opening null channel"); } openFile = new OpenFile(); try { openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(channel))); } catch (InvalidValueException e) { throw getRuntime().newErrnoEINVALError(); } openFile.setMode(openFile.getMainStream().getModes().getOpenFileFlags()); }
private void setOutputStream(PrintStream pstream) { if (pstream == null) { return; } Ruby runtime = provider.getRuntime(); RubyIO io = new RubyIO(runtime, pstream); io.getOpenFile().getMainStream().setSync(true); runtime.defineVariable(new OutputGlobalVariable(runtime, "$stdout", io), GlobalVariable.Scope.GLOBAL); runtime.getObject().storeConstant("STDOUT", io); runtime.getGlobalVariables().alias("$>", "$stdout"); runtime.getGlobalVariables().alias("$defout", "$stdout"); }
@Override public IRubyObject inspect() { Ruby runtime = getRuntime(); if (!runtime.is1_9()) return super.inspect(); if (openFile == null) return super.inspect(); Stream stream = openFile.getMainStream(); String className = getMetaClass().getRealClass().getName(); String path = openFile.getPath(); String status = ""; if (path == null) { if (stream == null) { path = ""; status = "(closed)"; } else { path = "fd " + runtime.getFileno(stream.getDescriptor()); } } else if (!openFile.isOpen()) { status = " (closed)"; } String inspectStr = "#<" + className + ":" + path + status + ">"; return runtime.newString(inspectStr); }
@Override public IRubyObject inspect() { Ruby runtime = getRuntime(); if (!runtime.is1_9()) return super.inspect(); if (openFile == null) return super.inspect(); Stream stream = openFile.getMainStream(); String className = getMetaClass().getRealClass().getName(); String path = openFile.getPath(); String status = ""; if (path == null) { if (stream == null) { path = ""; status = "(closed)"; } else { path = "fd " + runtime.getFileno(stream.getDescriptor()); } } else if (!openFile.isOpen()) { status = " (closed)"; } String inspectStr = "#<" + className + ":" + path + status + ">"; return runtime.newString(inspectStr); }