Class ChannelProxy

  • All Implemented Interfaces:
    java.lang.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 Detail

      • ChannelProxy

        public ChannelProxy​(java.lang.String path)
      • ChannelProxy

        public ChannelProxy​(File file)
      • ChannelProxy

        public ChannelProxy​(File file,
                            java.nio.channels.FileChannel channel)
    • Method Detail

      • openChannel

        public static java.nio.channels.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 java.lang.String filePath()
      • file

        public File file()
      • read

        public int read​(java.nio.ByteBuffer buffer,
                        long position)
      • transferTo

        public long transferTo​(long position,
                               long count,
                               java.nio.channels.WritableByteChannel target)
      • map

        public java.nio.MappedByteBuffer map​(java.nio.channels.FileChannel.MapMode mode,
                                             long position,
                                             long size)
      • size

        public long size()
      • getFileDescriptor

        public int getFileDescriptor()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object