Top Description Fields Constructors Methods
org.jruby.ext.ffi.io

public Class FileDescriptorByteChannel

extends Object
implements ByteChannel
Class Inheritance
All Implemented Interfaces
java.nio.channels.ByteChannel, java.nio.channels.WritableByteChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.ReadableByteChannel
Imports
org.jruby.Ruby, jnr.posix.LibC, java.io.IOException, java.nio.ByteBuffer, java.nio.channels.ByteChannel

An implementation of ByteChannel that reads from and writes to a native unix file descriptor.

Field Summary

Modifier and TypeField and Description
private final int
private volatile boolean
private final LibC

Constructor Summary

AccessConstructor and Description
public
FileDescriptorByteChannel(Ruby runtime, int
The native unix fd to read/write.
fd
)

Creates a new FileDescriptorByteChannel.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.nio.channels.Channel.close.

Closes the Channel.

public boolean

Returns:

true if the Channel is still open
isOpen
()

Implements java.nio.channels.Channel.isOpen.

Tests if the ByteChannel is open.

private static LibC
libc(Ruby runtime)

public int

Returns:

The number of bytes read.
read
(ByteBuffer
The destination ByteBuffer to place read bytes in.
dst
)

Implements java.nio.channels.ReadableByteChannel.read.

Reads data from the native unix file descriptor.

public int

Returns:

The number of bytes written.
write
(ByteBuffer
The source ByteBuffer to write to the file descriptor.
src
)

Implements java.nio.channels.WritableByteChannel.write.

Writes data to the native unix file descriptor.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fdback to summary
private final int fd
isOpenback to summary
private volatile boolean isOpen
libcback to summary
private final LibC libc

Constructor Detail

FileDescriptorByteChannelback to summary
public FileDescriptorByteChannel(Ruby runtime, int fd)

Creates a new FileDescriptorByteChannel.

Parameters
fd:int

The native unix fd to read/write.

Method Detail

closeback to summary
public void close() throws IOException

Implements java.nio.channels.Channel.close.

Closes the Channel.

This closes the underlying native file descriptor.

Exceptions
IOException:

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

If an I/O error occurs

isOpenback to summary
public boolean isOpen()

Implements java.nio.channels.Channel.isOpen.

Tests if the ByteChannel is open.

Returns:boolean

true if the Channel is still open

libcback to summary
private static LibC libc(Ruby runtime)
readback to summary
public int read(ByteBuffer dst) throws IOException

Implements java.nio.channels.ReadableByteChannel.read.

Reads data from the native unix file descriptor.

Parameters
dst:ByteBuffer

The destination ByteBuffer to place read bytes in.

Returns:int

The number of bytes read.

Exceptions
IOException:
If an error occurred during reading.
writeback to summary
public int write(ByteBuffer src) throws IOException

Implements java.nio.channels.WritableByteChannel.write.

Writes data to the native unix file descriptor.

Parameters
src:ByteBuffer

The source ByteBuffer to write to the file descriptor.

Returns:int

The number of bytes written.

Exceptions
IOException:
If an error occurred during writing.