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 TypeMethodDescriptionvoidclose()Closes theChannel.booleanisOpen()Tests if the ByteChannel is open.intread(ByteBuffer dst) Reads data from the native unix file descriptor.intwrite(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:
readin interfaceReadableByteChannel- Parameters:
dst- The destinationByteBufferto 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 sourceByteBufferto 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-