Class ChannelProxy

All Implemented Interfaces:
AutoCloseable, SharedCloseable

public final class ChannelProxy extends SharedCloseableImpl
A proxy of a FileChannel that: - implements reference counting - exports only thread safe FileChannel operations - wraps IO exceptions into runtime exceptions Tested by RandomAccessReaderTest.
  • Constructor Details

    • ChannelProxy

      public ChannelProxy(String path)
    • ChannelProxy

      public ChannelProxy(File file)
    • ChannelProxy

      public ChannelProxy(File file, FileChannel channel)
    • ChannelProxy

      public ChannelProxy(ChannelProxy copy)
  • Method Details

    • openChannel

      public static FileChannel openChannel(File file)
    • newChannel

      public final ChannelProxy newChannel()
      sharedCopy() can not be used if thread will be interruped, as the backing channel will be closed.
      Returns:
      a new channel instance
    • sharedCopy

      public ChannelProxy sharedCopy()
      Returns:
      a new instance of the object representing the same state and backed by the same underlying resources. Coordinates with the original (and other instances) when the underlying resource should be closed. Throws an exception if the shared resource has already been closed.
    • filePath

      public String filePath()
    • file

      public File file()
    • read

      public int read(ByteBuffer buffer, long position)
    • transferTo

      public long transferTo(long position, long count, WritableByteChannel target)
    • map

      public MappedByteBuffer map(FileChannel.MapMode mode, long position, long size)
    • size

      public long size()
    • getFileDescriptor

      public int getFileDescriptor()
    • toString

      public String toString()
      Overrides:
      toString in class Object