public final class FileChannelOpener extends Object implements ChannelOpener<FileChannel>
ChannelOpener which opens a specific file. The file is
always opened for reading only. The file must exists when requested to be
opened otherwise FileChannelOpener will fail to open the file.
ChannelOpener, this class is safe to be accessed
by multiple threads concurrently.
AsyncChannelLink| Constructor and Description |
|---|
FileChannelOpener(Path fileToOpen)
Creates a
FileChannelOpener which will open the specified file
when requested. |
| Modifier and Type | Method and Description |
|---|---|
FileChannel |
openChanel()
Opens a new channel to the source defined by this
ChannelOpener instance. |
public FileChannelOpener(Path fileToOpen)
FileChannelOpener which will open the specified file
when requested.fileToOpen - the file to open when requested. This argument cannot
be nullNullPointerException - thrown if the specified path is nullpublic FileChannel openChanel() throws IOException
ChannelOpener instance. This method opens a new channel each
time called an these opened channels must be
closed separately.
Implementation note: The file channel will be opened for reading
only. That is, with the StandardOpenOption.READ.
openChanel in interface ChannelOpener<FileChannel>ChannelOpener instance. The returned instance must be
closed in order to prevent resource leakage.
This method never returns null.IOException - thrown if the channel could not be opened for some
reasons