protected void sysopenInternal(String path, ModeFlags modes, int perm) { if (path.startsWith("jar:")) path = path.substring(4); int umask = getUmaskSafe( getRuntime() ); perm = perm - (perm & umask); ChannelDescriptor descriptor = sysopen(path, modes, perm); openFile.setMainStream(fdopen(descriptor, modes)); }
protected void sysopenInternal(String path, ModeFlags modes, int perm) { if (path.startsWith("jar:")) path = path.substring(4); int umask = getUmaskSafe( getRuntime() ); perm = perm - (perm & umask); ChannelDescriptor descriptor = sysopen(path, modes, perm); openFile.setMainStream(fdopen(descriptor, modes)); }
protected void sysopenInternal19(String path, int oflags, int perm) { if (path.startsWith("jar:")) path = path.substring(4); int umask = getUmaskSafe( getRuntime() ); perm = perm - (perm & umask); ModeFlags modes = ModeFlags.createModeFlags(oflags); ChannelDescriptor descriptor = sysopen(path, modes, perm); openFile.setMainStream(fdopen(descriptor, modes)); }
protected void sysopenInternal19(String path, int oflags, int perm) { if (path.startsWith("jar:")) path = path.substring(4); int umask = getUmaskSafe( getRuntime() ); perm = perm - (perm & umask); ModeFlags modes = ModeFlags.createModeFlags(oflags); ChannelDescriptor descriptor = sysopen(path, modes, perm); openFile.setMainStream(fdopen(descriptor, modes)); }
public RubyIO(Ruby runtime, InputStream inputStream) { super(runtime, runtime.getIO()); if (inputStream == null) { throw runtime.newRuntimeError("Opening null stream"); } openFile = new OpenFile(); try { openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(Channels.newChannel(inputStream)))); } catch (InvalidValueException e) { throw getRuntime().newErrnoEINVALError(); } openFile.setMode(OpenFile.READABLE); }
public RubyIO(Ruby runtime, InputStream inputStream) { super(runtime, runtime.getIO()); if (inputStream == null) { throw runtime.newRuntimeError("Opening null stream"); } openFile = new OpenFile(); try { openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(Channels.newChannel(inputStream)))); } catch (InvalidValueException e) { throw getRuntime().newErrnoEINVALError(); } openFile.setMode(OpenFile.READABLE); }
public RubyIO(Ruby runtime, OutputStream outputStream, boolean autoclose) { super(runtime, runtime.getIO()); // We only want IO objects with valid streams (better to error now). if (outputStream == null) { throw runtime.newRuntimeError("Opening null stream"); } openFile = new OpenFile(); try { openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(Channels.newChannel(outputStream)), autoclose)); } catch (InvalidValueException e) { throw getRuntime().newErrnoEINVALError(); } openFile.setMode(OpenFile.WRITABLE | OpenFile.APPEND); }
public RubyIO(Ruby runtime, OutputStream outputStream, boolean autoclose) { super(runtime, runtime.getIO()); // We only want IO objects with valid streams (better to error now). if (outputStream == null) { throw runtime.newRuntimeError("Opening null stream"); } openFile = new OpenFile(); try { openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(Channels.newChannel(outputStream)), autoclose)); } catch (InvalidValueException e) { throw getRuntime().newErrnoEINVALError(); } openFile.setMode(OpenFile.WRITABLE | OpenFile.APPEND); }
protected void openInternal(String path, String modeString) { if (path.startsWith("jar:")) { path = path.substring(4); } MakeOpenFile(); IOOptions modes = newIOOptions(getRuntime(), modeString); openFile.setMode(modes.getModeFlags().getOpenFileFlags()); if (getRuntime().is1_9() && modes.getModeFlags().isBinary()) enc = ASCIIEncoding.INSTANCE; openFile.setPath(path); openFile.setMainStream(fopen(path, modes.getModeFlags())); }
protected void openInternal(String path, String modeString) { if (path.startsWith("jar:")) { path = path.substring(4); } MakeOpenFile(); IOOptions modes = newIOOptions(getRuntime(), modeString); openFile.setMode(modes.getModeFlags().getOpenFileFlags()); if (getRuntime().is1_9() && modes.getModeFlags().isBinary()) enc = ASCIIEncoding.INSTANCE; openFile.setPath(path); openFile.setMainStream(fopen(path, modes.getModeFlags())); }
public RubyFile(Ruby runtime, String path, InputStream in) { super(runtime, runtime.getFile()); MakeOpenFile(); this.path = path; try { this.openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(Channels.newChannel(in)))); this.openFile.setMode(openFile.getMainStreamSafe().getModes().getOpenFileFlags()); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } catch (InvalidValueException ex) { throw runtime.newErrnoEINVALError(); } }
public RubyFile(Ruby runtime, String path, InputStream in) { super(runtime, runtime.getFile()); MakeOpenFile(); this.path = path; try { this.openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(Channels.newChannel(in)))); this.openFile.setMode(openFile.getMainStreamSafe().getModes().getOpenFileFlags()); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } catch (InvalidValueException ex) { throw runtime.newErrnoEINVALError(); } }
protected void init_sock(Ruby runtime) { try { ModeFlags modes = newModeFlags(runtime, ModeFlags.RDWR); MakeOpenFile(); openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(channel, modes))); openFile.setPipeStream(openFile.getMainStreamSafe()); openFile.setMode(modes.getOpenFileFlags()); openFile.getMainStreamSafe().setSync(true); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } }
protected void init_sock(Ruby runtime) { try { ModeFlags modes = newModeFlags(runtime, ModeFlags.RDWR); MakeOpenFile(); openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(channel, modes))); openFile.setPipeStream(openFile.getMainStreamSafe()); openFile.setMode(modes.getOpenFileFlags()); openFile.getMainStreamSafe().setSync(true); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } }
protected void initSocket(Ruby runtime, ChannelDescriptor descriptor) { // continue with normal initialization MakeOpenFile(); try { openFile.setMainStream(ChannelStream.fdopen(runtime, descriptor, newModeFlags(runtime, ModeFlags.RDONLY))); openFile.setPipeStream(ChannelStream.fdopen(runtime, descriptor, newModeFlags(runtime, ModeFlags.WRONLY))); openFile.getPipeStream().setSync(true); } catch (org.jruby.util.io.InvalidValueException ex) { throw runtime.newErrnoEINVALError(); } openFile.setMode(OpenFile.READWRITE | OpenFile.SYNC); // see rsock_init_sock in MRI; sockets are initialized to binary setAscii8bitBinmode(); }
protected void initSocket(Ruby runtime, ChannelDescriptor descriptor) { // continue with normal initialization MakeOpenFile(); try { openFile.setMainStream(ChannelStream.fdopen(runtime, descriptor, newModeFlags(runtime, ModeFlags.RDONLY))); openFile.setPipeStream(ChannelStream.fdopen(runtime, descriptor, newModeFlags(runtime, ModeFlags.WRONLY))); openFile.getPipeStream().setSync(true); } catch (org.jruby.util.io.InvalidValueException ex) { throw runtime.newErrnoEINVALError(); } openFile.setMode(OpenFile.READWRITE | OpenFile.SYNC); // see rsock_init_sock in MRI; sockets are initialized to binary setAscii8bitBinmode(); }
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()); }
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()); }
public FileDescriptorIO(Ruby runtime, IRubyObject fd) { super(runtime, runtime.getModule("FFI").getClass(CLASS_NAME)); MakeOpenFile(); ModeFlags modes; try { modes = newModeFlags(runtime, ModeFlags.RDWR); int fileno = RubyNumeric.fix2int(fd); jnr.posix.FileStat stat = runtime.getPosix().fstat(fileno); java.nio.channels.ByteChannel channel; if (stat.isSocket()) { channel = new jnr.enxio.channels.NativeSocketChannel(fileno); } else if (stat.isBlockDev() || stat.isCharDev()) { channel = new jnr.enxio.channels.NativeDeviceChannel(fileno); } else { channel = new FileDescriptorByteChannel(runtime, fileno); } openFile.setMainStream(ChannelStream.open(getRuntime(), new ChannelDescriptor(channel, modes, FileDescriptorHelper.wrap(fileno)))); openFile.setPipeStream(openFile.getMainStreamSafe()); openFile.setMode(modes.getOpenFileFlags()); openFile.getMainStreamSafe().setSync(true); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } }
public FileDescriptorIO(Ruby runtime, IRubyObject fd) { super(runtime, runtime.getModule("FFI").getClass(CLASS_NAME)); MakeOpenFile(); ModeFlags modes; try { modes = newModeFlags(runtime, ModeFlags.RDWR); int fileno = RubyNumeric.fix2int(fd); jnr.posix.FileStat stat = runtime.getPosix().fstat(fileno); java.nio.channels.ByteChannel channel; if (stat.isSocket()) { channel = new jnr.enxio.channels.NativeSocketChannel(fileno); } else if (stat.isBlockDev() || stat.isCharDev()) { channel = new jnr.enxio.channels.NativeDeviceChannel(fileno); } else { channel = new FileDescriptorByteChannel(runtime, fileno); } openFile.setMainStream(ChannelStream.open(getRuntime(), new ChannelDescriptor(channel, modes, FileDescriptorHelper.wrap(fileno)))); openFile.setPipeStream(openFile.getMainStreamSafe()); openFile.setMode(modes.getOpenFileFlags()); openFile.getMainStreamSafe().setSync(true); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } }