Module jtrim.query

Class FileChannelOpener

java.lang.Object
org.jtrim2.concurrent.query.io.FileChannelOpener
All Implemented Interfaces:
ChannelOpener<FileChannel>

public final class FileChannelOpener extends Object implements ChannelOpener<FileChannel>
Defines a 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.

Thread safety

As required by the ChannelOpener, this class is safe to be accessed by multiple threads concurrently.

Synchronization transparency

Methods of this class are not synchronization transparent.
See Also:
  • Constructor Details

    • FileChannelOpener

      public FileChannelOpener(Path fileToOpen)
      Creates a FileChannelOpener which will open the specified file when requested.
      Parameters:
      fileToOpen - the file to open when requested. This argument cannot be null
      Throws:
      NullPointerException - thrown if the specified path is null
  • Method Details

    • openChanel

      public FileChannel openChanel() throws IOException
      Opens a new channel to the source defined by this 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.

      Specified by:
      openChanel in interface ChannelOpener<FileChannel>
      Returns:
      new channel to the source defined by this ChannelOpener instance. The returned instance must be closed in order to prevent resource leakage. This method never returns null.
      Throws:
      IOException - thrown if the channel could not be opened for some reasons