Package 

Class MultiReadOnlySeekableByteChannel

    • Method Summary

      Modifier and Type Method Description
      static SeekableByteChannel forSeekableByteChannels(Array<SeekableByteChannel> channels) Concatenates the given channels.
      void close() Closes an open channel.
      boolean isOpen() Returns true if this channel is open.
      long position() Returns this channel's position.
      synchronized SeekableByteChannel position(long newPosition) Sets the channel's position to {@code newPosition}.
      synchronized SeekableByteChannel position(long channelNumber, long relativeOffset) set the position based on the given channel number and relative offset
      synchronized int read(ByteBuffer dst) Reads bytes from this channel into the given buffer.
      long size() Returns the size of the data source underlying this channel in bytes.
      SeekableByteChannel truncate(long size)
      int write(ByteBuffer src)
      • Methods inherited from class org.readium.r2.shared.util.zip.jvm.SeekableByteChannel

        position, read, truncate, write
      • Methods inherited from class java.io.Closeable

        close
      • Methods inherited from class java.lang.Object

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

      • MultiReadOnlySeekableByteChannel

        MultiReadOnlySeekableByteChannel(List<SeekableByteChannel> channels)
        Concatenates the given channels.
        Parameters:
        channels - the channels to concatenate
    • Method Detail

      • close

         void close()

        Closes an open channel. If the channel is already closed then this methodhas no effect. If there is a problem with closing the channel then themethod throws an IOException and the exception contains reasons for thefailure.

        If an attempt is made to perform an operation on a closed channel then a ClosedChannelException will be thrown on that attempt.

        If multiple threads attempt to simultaneously close a channel, then onlyone thread will run the closure code, and others will be blocked untilthe first returns.

      • isOpen

         boolean isOpen()

        Returns true if this channel is open.

      • position

         long position()

        Returns this channel's position.

        This method violates the contract of position as it will not throw any exceptionwhen invoked on a closed channel. Instead it will return the position the channel had when close has beencalled.

      • position

         synchronized SeekableByteChannel position(long newPosition)

        Sets the channel's position to {@code newPosition}.

        The argument is the number of bytes counted from the start of the data source. The positioncannot be set to a value that is negative. The new position can be set beyond the currentsize. If set beyond the current size, attempts to read will return end-of-file. Writeoperations will succeed but they will fill the bytes between the current end of the datasourceand the new position with the required number of (unspecified) byte values.

      • position

         synchronized SeekableByteChannel position(long channelNumber, long relativeOffset)

        set the position based on the given channel number and relative offset

        Parameters:
        channelNumber - the channel number
        relativeOffset - the relative offset in the corresponding channel
      • read

         synchronized int read(ByteBuffer dst)

        Reads bytes from this channel into the given buffer.

        If the channels position is beyond the current end of the underlying data source thenend-of-file (-1) is returned.

        The bytes are read starting at the channel's current position, and after some number ofbytes are read (up to the remaining number of bytes in thebuffer) the channel's position is increased by the number of bytes actually read. The byteswill be read into the buffer starting at the buffer's current position. The buffer's limit is not changed.

        The call may block if other threads are also attempting to read from the same channel.

      • size

         long size()

        Returns the size of the data source underlying this channel in bytes.