Class FileDescriptorByteChannel

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

public class FileDescriptorByteChannel extends Object implements ByteChannel
An implementation of ByteChannel that reads from and writes to a native unix file descriptor.
  • Constructor Details

    • FileDescriptorByteChannel

      public FileDescriptorByteChannel(Ruby runtime, int fd)
      Creates a new FileDescriptorByteChannel.
      Parameters:
      fd - The native unix fd to read/write.
  • Method Details

    • read

      public int read(ByteBuffer dst) throws IOException
      Reads data from the native unix file descriptor.
      Specified by:
      read in interface ReadableByteChannel
      Parameters:
      dst - The destination ByteBuffer to place read bytes in.
      Returns:
      The number of bytes read.
      Throws:
      IOException - If an error occurred during reading.
    • write

      public int write(ByteBuffer src) throws IOException
      Writes data to the native unix file descriptor.
      Specified by:
      write in interface WritableByteChannel
      Parameters:
      src - The source ByteBuffer to write to the file descriptor.
      Returns:
      The number of bytes written.
      Throws:
      IOException - If an error occurred during writing.
    • isOpen

      public boolean isOpen()
      Tests if the ByteChannel is open.
      Specified by:
      isOpen in interface Channel
      Returns:
      true if the Channel is still open
    • close

      public void close() throws IOException
      Closes the Channel.

      This closes the underlying native file descriptor.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Channel
      Specified by:
      close in interface Closeable
      Throws:
      IOException