public class SelectableFileChannelFactory extends Object
SelectableChannel from InputStream or OutputStream.
This hides the hack that works around the fact that FileChannel is not a SelectableChannel.
JDK didn't make FileChannel selectable because it's not selectable on Windows.
But on POSIX, select API does support arbitrary file descriptors, including pipes and regular files.
Methods on this class takes various JDK objects that own FileDescriptor and
creates a SocketChannel object that points to the same file descriptor, as a hack.
Note that since it is not a real socket, various socket specific operations on SocketChannel
will fail, most notably Object.toString()
| Constructor and Description |
|---|
SelectableFileChannelFactory() |
| Modifier and Type | Method and Description |
|---|---|
SocketChannel |
create(FileDescriptor fd)
Create channel using the specified file descriptor.
|
SocketChannel |
create(FileInputStream in) |
SocketChannel |
create(FileOutputStream out) |
SocketChannel |
create(InputStream in) |
SocketChannel |
create(OutputStream out) |
protected FileInputStream |
unwrap(InputStream i) |
protected FileOutputStream |
unwrap(OutputStream i) |
@CheckForNull protected FileInputStream unwrap(InputStream i)
@CheckForNull protected FileOutputStream unwrap(OutputStream i)
@CheckForNull public SocketChannel create(InputStream in) throws IOException
IOException@CheckForNull public SocketChannel create(OutputStream out) throws IOException
IOException@CheckForNull public SocketChannel create(FileInputStream in) throws IOException
IOException@CheckForNull public SocketChannel create(FileOutputStream out) throws IOException
IOException@CheckForNull public SocketChannel create(FileDescriptor fd)
fd - File Descriptornull if the platform does not support it (e.g. Windows) OR the socket channel cannot be created.
In the latter case the error message will be printed to LOGGER then.Copyright © 2004–2022. All rights reserved.