Class FileChannels


  • public final class FileChannels
    extends java.lang.Object
    Works with FileChannel.
    Since:
    2.15.0
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private FileChannels()
      Don't instantiate.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static boolean contentEquals​(java.nio.channels.FileChannel channel1, java.nio.channels.FileChannel channel2, int bufferCapacity)
      static boolean contentEquals​(java.nio.channels.ReadableByteChannel channel1, java.nio.channels.ReadableByteChannel channel2, int bufferCapacity)
      Tests if two readable byte channel contents are equal starting at their respective current positions.
      static boolean contentEquals​(java.nio.channels.SeekableByteChannel channel1, java.nio.channels.SeekableByteChannel channel2, int bufferCapacity)
      Tests if two seekable byte channel contents are equal starting at their respective current positions.
      private static int readToLimit​(java.nio.channels.ReadableByteChannel channel, java.nio.ByteBuffer dst)
      Reads a sequence of bytes from a channel into the given buffer until the buffer reaches its limit or the channel has reaches end-of-stream.
      private static long size​(java.nio.channels.SeekableByteChannel channel)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FileChannels

        private FileChannels()
        Don't instantiate.
    • Method Detail

      • contentEquals

        @Deprecated
        public static boolean contentEquals​(java.nio.channels.FileChannel channel1,
                                            java.nio.channels.FileChannel channel2,
                                            int bufferCapacity)
                                     throws java.io.IOException
        Tests if two file channel contents are equal starting at their respective current positions.
        Parameters:
        channel1 - A file channel.
        channel2 - Another file channel.
        bufferCapacity - The two internal buffer capacities, in bytes.
        Returns:
        true if the contents of both RandomAccessFiles are equal, false otherwise.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • contentEquals

        public static boolean contentEquals​(java.nio.channels.ReadableByteChannel channel1,
                                            java.nio.channels.ReadableByteChannel channel2,
                                            int bufferCapacity)
                                     throws java.io.IOException
        Tests if two readable byte channel contents are equal starting at their respective current positions.
        Parameters:
        channel1 - A readable byte channel.
        channel2 - Another readable byte channel.
        bufferCapacity - The two internal buffer capacities, in bytes.
        Returns:
        true if the contents of both RandomAccessFiles are equal, false otherwise.
        Throws:
        java.io.IOException - if an I/O error occurs or the timeout is met.
        Since:
        2.19.0
      • contentEquals

        public static boolean contentEquals​(java.nio.channels.SeekableByteChannel channel1,
                                            java.nio.channels.SeekableByteChannel channel2,
                                            int bufferCapacity)
                                     throws java.io.IOException
        Tests if two seekable byte channel contents are equal starting at their respective current positions.

        If the two channels have different sizes, no content comparison takes place, and this method returns false.

        Parameters:
        channel1 - A seekable byte channel.
        channel2 - Another seekable byte channel.
        bufferCapacity - The two internal buffer capacities, in bytes.
        Returns:
        true if the contents of both RandomAccessFiles are equal, false otherwise.
        Throws:
        java.io.IOException - if an I/O error occurs or the timeout is met.
        Since:
        2.19.0
      • readToLimit

        private static int readToLimit​(java.nio.channels.ReadableByteChannel channel,
                                       java.nio.ByteBuffer dst)
                                throws java.io.IOException
        Reads a sequence of bytes from a channel into the given buffer until the buffer reaches its limit or the channel has reaches end-of-stream.

        The buffer's limit is not changed.

        Parameters:
        channel - The source channel.
        dst - The buffer into which bytes are to be transferred.
        Returns:
        The number of bytes read, never zero, or -1 if the channel has reached end-of-stream
        Throws:
        java.io.IOException - If some other I/O error occurs.
        java.lang.IllegalArgumentException - If there is room in the given buffer.
      • size

        private static long size​(java.nio.channels.SeekableByteChannel channel)
                          throws java.io.IOException
        Throws:
        java.io.IOException