org.jruby.ext.ffi.io
Class FileDescriptorByteChannel

java.lang.Object
  extended by org.jruby.ext.ffi.io.FileDescriptorByteChannel
All Implemented Interfaces:
java.io.Closeable, java.nio.channels.ByteChannel, java.nio.channels.Channel, java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel

public class FileDescriptorByteChannel
extends java.lang.Object
implements java.nio.channels.ByteChannel

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


Constructor Summary
FileDescriptorByteChannel(Ruby runtime, int fd)
          Creates a new FileDescriptorByteChannel.
 
Method Summary
 void close()
          Closes the Channel.
 boolean isOpen()
          Tests if the ByteChannel is open.
 int read(java.nio.ByteBuffer dst)
          Reads data from the native unix file descriptor.
 int write(java.nio.ByteBuffer src)
          Writes data to the native unix file descriptor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileDescriptorByteChannel

public FileDescriptorByteChannel(Ruby runtime,
                                 int fd)
Creates a new FileDescriptorByteChannel.

Parameters:
fd - The native unix fd to read/write.
Method Detail

read

public int read(java.nio.ByteBuffer dst)
         throws java.io.IOException
Reads data from the native unix file descriptor.

Specified by:
read in interface java.nio.channels.ReadableByteChannel
Parameters:
dst - The destination ByteBuffer to place read bytes in.
Returns:
The number of bytes read.
Throws:
java.io.IOException - If an error occurred during reading.

write

public int write(java.nio.ByteBuffer src)
          throws java.io.IOException
Writes data to the native unix file descriptor.

Specified by:
write in interface java.nio.channels.WritableByteChannel
Parameters:
src - The source ByteBuffer to write to the file descriptor.
Returns:
The number of bytes written.
Throws:
java.io.IOException - If an error occurred during writing.

isOpen

public boolean isOpen()
Tests if the ByteChannel is open.

Specified by:
isOpen in interface java.nio.channels.Channel
Returns:
true if the Channel is still open

close

public void close()
           throws java.io.IOException
Closes the Channel.

This closes the underlying native file descriptor.

Specified by:
close in interface java.io.Closeable
Specified by:
close in interface java.nio.channels.Channel
Throws:
java.io.IOException


Copyright © 2002-2009 JRuby Team. All Rights Reserved.