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.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFileDescriptorByteChannel(Ruby runtime, int fd) Creates a new FileDescriptorByteChannel. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the Channel.booleanisOpen()Tests if the ByteChannel is open.private static jnr.posix.LibCintread(ByteBuffer dst) Reads data from the native unix file descriptor.intwrite(ByteBuffer src) Writes data to the native unix file descriptor.
-
Field Details
-
libc
private final jnr.posix.LibC libc -
fd
private final int fd -
isOpen
private volatile boolean isOpen
-
-
Constructor Details
-
FileDescriptorByteChannel
Creates a new FileDescriptorByteChannel.- Parameters:
fd- The native unix fd to read/write.
-
-
Method Details
-
libc
-
read
Reads data from the native unix file descriptor.- Specified by:
readin interfaceReadableByteChannel- 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
Writes data to the native unix file descriptor.- Specified by:
writein interfaceWritableByteChannel- 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. -
close
Closes the Channel.This closes the underlying native file descriptor.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-