Package org.jruby.ext.ffi.io
Class FileDescriptorByteChannel
java.lang.Object
org.jruby.ext.ffi.io.FileDescriptorByteChannel
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ByteChannel
,Channel
,ReadableByteChannel
,WritableByteChannel
An implementation of ByteChannel that reads from and writes to a native unix
file descriptor.
-
Constructor Summary
ConstructorsConstructorDescriptionFileDescriptorByteChannel
(Ruby runtime, int fd) Creates a newFileDescriptorByteChannel
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes theChannel
.boolean
isOpen()
Tests if the ByteChannel is open.int
read
(ByteBuffer dst) Reads data from the native unix file descriptor.int
write
(ByteBuffer src) Writes data to the native unix file descriptor.
-
Constructor Details
-
FileDescriptorByteChannel
Creates a newFileDescriptorByteChannel
.- Parameters:
fd
- The native unix fd to read/write.
-
-
Method Details
-
read
Reads data from the native unix file descriptor.- Specified by:
read
in interfaceReadableByteChannel
- Parameters:
dst
- The destinationByteBuffer
to place read bytes in.- Returns:
- The number of bytes read.
- Throws:
IOException
- If an error occurred during reading.
-
write
Writes data to the native unix file descriptor.- Specified by:
write
in interfaceWritableByteChannel
- Parameters:
src
- The sourceByteBuffer
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. -
close
Closes theChannel
.This closes the underlying native file descriptor.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-