Top Description Inners Fields Constructors Methods
org.jruby.util

public abstract Class IOChannel

extends Object
implements Channel
Class Inheritance
All Implemented Interfaces
java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
org.jruby.util.IOChannel.IOReadableByteChannel, org.jruby.util.IOChannel.IOWritableByteChannel, org.jruby.util.IOChannel.IOReadableWritableByteChannel
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.channels.Channel, .ReadableByteChannel, .WritableByteChannel, org.jruby.Ruby, .RubyFixnum, .RubyString, org.jruby.exceptions.ReadPartialBufferOverflowException, org.jruby.runtime.CallSite, .ThreadContext, .MethodIndex, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.callsite.CacheEntry, .FunctionalCachingCallSite, .RespondToCallSite

Wrap an IO object in a Channel.
See Also
IOReadableByteChannel, IOWritableByteChannel, IOReadableWritableByteChannel

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
IOChannel.IOReadableByteChannel

A ReadableByteChannel wrapper around an IO-like Ruby object.

public static class
public static class
IOChannel.IOWritableByteChannel

A WritableByteChannel wrapper around an IO-like Ruby object.

Field Summary

Modifier and TypeField and Description
private final CallSite
protected final IRubyObject
private final CallSite
private final RespondToCallSite
protected final Ruby

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.nio.channels.Channel.close.

Closes this channel.

protected FunctionalCachingCallSite
initReadSite(String readMethod)

protected FunctionalCachingCallSite
public boolean
isOpen()

Implements java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

protected static int
protected static int

Returns:

the amount of data reported written by the dynamic `write` call
write
(Ruby
the current runtime
runtime
,
IRubyObject
the target IO-like object
io
,
FunctionalCachingCallSite
the call site for making dynamic `write` calls
write
,
ByteBuffer
the data to write
src
)

Perform a write to the given IO-like object, using the given call site, and passing the contents of the given buffer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closeAdapterback to summary
private final CallSite closeAdapter
ioback to summary
protected final IRubyObject io
isClosedAdapterback to summary
private final CallSite isClosedAdapter
respondToClosedback to summary
private final RespondToCallSite respondToClosed
runtimeback to summary
protected final Ruby runtime

Constructor Detail

IOChannelback to summary
protected IOChannel(final IRubyObject io)

Method Detail

closeback to summary
public void close() throws IOException

Implements java.nio.channels.Channel.close.

Doc from java.nio.channels.Channel.close.

Closes this channel.

After a channel is closed, any further attempt to invoke I/O operations upon it will cause a ClosedChannelException to be thrown.

If this channel is already closed then invoking this method has no effect.

This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.

Exceptions
IOException:
If an I/O error occurs
initReadSiteback to summary
protected FunctionalCachingCallSite initReadSite(String readMethod)
initWriteSiteback to summary
protected FunctionalCachingCallSite initWriteSite()
isOpenback to summary
public boolean isOpen()

Implements java.nio.channels.Channel.isOpen.

Doc from java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

Returns:boolean

true if, and only if, this channel is open

readback to summary
protected static int read(Ruby runtime, IRubyObject io, FunctionalCachingCallSite read, ByteBuffer dst) throws IOException
writeback to summary
protected static int write(Ruby runtime, IRubyObject io, FunctionalCachingCallSite write, ByteBuffer src)

Perform a write to the given IO-like object, using the given call site, and passing the contents of the given buffer. The buffer and its contents should not be referenced beyond the method's return.

Parameters
runtime:Ruby

the current runtime

io:IRubyObject

the target IO-like object

write:FunctionalCachingCallSite

the call site for making dynamic `write` calls

src:ByteBuffer

the data to write

Returns:int

the amount of data reported written by the dynamic `write` call

org.jruby.util back to summary

public Class IOChannel.IOReadableByteChannel

extends IOChannel
implements ReadableByteChannel
Class Inheritance
All Implemented Interfaces
java.nio.channels.ReadableByteChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable

A ReadableByteChannel wrapper around an IO-like Ruby object.

Field Summary

Modifier and TypeField and Description
private final FunctionalCachingCallSite
Inherited from org.jruby.util.IOChannel:
ioruntime

Constructor Summary

AccessConstructor and Description
public
public
IOReadableByteChannel(final IRubyObject io, final String readMethod)

Method Summary

Modifier and TypeMethod and Description
public int
read(ByteBuffer
The buffer into which bytes are to be transferred
dst
)

Implements java.nio.channels.ReadableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

Inherited from org.jruby.util.IOChannel:
closeinitReadSiteinitWriteSiteisOpenreadwrite

Field Detail

readback to summary
private final FunctionalCachingCallSite read

Constructor Detail

IOReadableByteChannelback to summary
public IOReadableByteChannel(final IRubyObject io)
IOReadableByteChannelback to summary
public IOReadableByteChannel(final IRubyObject io, final String readMethod)

Method Detail

readback to summary
public int read(ByteBuffer dst) throws IOException

Implements java.nio.channels.ReadableByteChannel.read.

Doc from java.nio.channels.ReadableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

An attempt is made to read up to r bytes from the channel, where r is the number of bytes remaining in the buffer, that is, dst.remaining(), at the moment this method is invoked.

Suppose that a byte sequence of length n is read, where 0 <= n <= r. This byte sequence will be transferred into the buffer so that the first byte in the sequence is at index p and the last byte is at index p + n - 1, where p is the buffer's position at the moment this method is invoked. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

A read operation might not fill the buffer, and in fact it might not read any bytes at all. Whether or not it does so depends upon the nature and state of the channel. A socket channel in non-blocking mode, for example, cannot read any more bytes than are immediately available from the socket's input buffer; similarly, a file channel cannot read any more bytes than remain in the file. It is guaranteed, however, that if a channel is in blocking mode and there is at least one byte remaining in the buffer then this method will block until at least one byte is read.

This method may be invoked at any time. If another thread has already initiated a read operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Parameters
dst:ByteBuffer

The buffer into which bytes are to be transferred

Returns:int

The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

Exceptions
IOException:
If some other I/O error occurs
org.jruby.util back to summary

public Class IOChannel.IOReadableWritableByteChannel

extends IOChannel
implements ReadableByteChannel, WritableByteChannel
Class Inheritance
All Implemented Interfaces
java.nio.channels.WritableByteChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.ReadableByteChannel

A ReadableByteChannel and WritableByteChannel wrapper around an IO-like Ruby object.

Field Summary

Modifier and TypeField and Description
private final FunctionalCachingCallSite
private final FunctionalCachingCallSite
Inherited from org.jruby.util.IOChannel:
ioruntime

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
read(ByteBuffer
The buffer into which bytes are to be transferred
dst
)

Implements java.nio.channels.ReadableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

public int
write(ByteBuffer
The buffer from which bytes are to be retrieved
src
)

Implements java.nio.channels.WritableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

Inherited from org.jruby.util.IOChannel:
closeinitReadSiteinitWriteSiteisOpenreadwrite

Field Detail

readback to summary
private final FunctionalCachingCallSite read
writeback to summary
private final FunctionalCachingCallSite write

Constructor Detail

IOReadableWritableByteChannelback to summary
public IOReadableWritableByteChannel(final IRubyObject io)

Method Detail

readback to summary
public int read(ByteBuffer dst) throws IOException

Implements java.nio.channels.ReadableByteChannel.read.

Doc from java.nio.channels.ReadableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

An attempt is made to read up to r bytes from the channel, where r is the number of bytes remaining in the buffer, that is, dst.remaining(), at the moment this method is invoked.

Suppose that a byte sequence of length n is read, where 0 <= n <= r. This byte sequence will be transferred into the buffer so that the first byte in the sequence is at index p and the last byte is at index p + n - 1, where p is the buffer's position at the moment this method is invoked. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

A read operation might not fill the buffer, and in fact it might not read any bytes at all. Whether or not it does so depends upon the nature and state of the channel. A socket channel in non-blocking mode, for example, cannot read any more bytes than are immediately available from the socket's input buffer; similarly, a file channel cannot read any more bytes than remain in the file. It is guaranteed, however, that if a channel is in blocking mode and there is at least one byte remaining in the buffer then this method will block until at least one byte is read.

This method may be invoked at any time. If another thread has already initiated a read operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Parameters
dst:ByteBuffer

The buffer into which bytes are to be transferred

Returns:int

The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

Exceptions
IOException:
If some other I/O error occurs
writeback to summary
public int write(ByteBuffer src) throws IOException

Implements java.nio.channels.WritableByteChannel.write.

Doc from java.nio.channels.WritableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

An attempt is made to write up to r bytes to the channel, where r is the number of bytes remaining in the buffer, that is, src.remaining(), at the moment this method is invoked.

Suppose that a byte sequence of length n is written, where 0 <= n <= r. This byte sequence will be transferred from the buffer starting at index p, where p is the buffer's position at the moment this method is invoked; the index of the last byte written will be p + n - 1. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

Unless otherwise specified, a write operation will return only after writing all of the r requested bytes. Some types of channels, depending upon their state, may write only some of the bytes or possibly none at all. A socket channel in non-blocking mode, for example, cannot write any more bytes than are free in the socket's output buffer.

This method may be invoked at any time. If another thread has already initiated a write operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Parameters
src:ByteBuffer

The buffer from which bytes are to be retrieved

Returns:int

The number of bytes written, possibly zero

Exceptions
IOException:
If some other I/O error occurs
org.jruby.util back to summary

public Class IOChannel.IOWritableByteChannel

extends IOChannel
implements WritableByteChannel
Class Inheritance
All Implemented Interfaces
java.nio.channels.WritableByteChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable

A WritableByteChannel wrapper around an IO-like Ruby object.

Field Summary

Modifier and TypeField and Description
private final FunctionalCachingCallSite
Inherited from org.jruby.util.IOChannel:
ioruntime

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
write(ByteBuffer
The buffer from which bytes are to be retrieved
src
)

Implements java.nio.channels.WritableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

Inherited from org.jruby.util.IOChannel:
closeinitReadSiteinitWriteSiteisOpenreadwrite

Field Detail

writeback to summary
private final FunctionalCachingCallSite write

Constructor Detail

IOWritableByteChannelback to summary
public IOWritableByteChannel(final IRubyObject io)

Method Detail

writeback to summary
public int write(ByteBuffer src) throws IOException

Implements java.nio.channels.WritableByteChannel.write.

Doc from java.nio.channels.WritableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

An attempt is made to write up to r bytes to the channel, where r is the number of bytes remaining in the buffer, that is, src.remaining(), at the moment this method is invoked.

Suppose that a byte sequence of length n is written, where 0 <= n <= r. This byte sequence will be transferred from the buffer starting at index p, where p is the buffer's position at the moment this method is invoked; the index of the last byte written will be p + n - 1. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

Unless otherwise specified, a write operation will return only after writing all of the r requested bytes. Some types of channels, depending upon their state, may write only some of the bytes or possibly none at all. A socket channel in non-blocking mode, for example, cannot write any more bytes than are free in the socket's output buffer.

This method may be invoked at any time. If another thread has already initiated a write operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Parameters
src:ByteBuffer

The buffer from which bytes are to be retrieved

Returns:int

The number of bytes written, possibly zero

Exceptions
IOException:
If some other I/O error occurs