Module 

Class FixedLengthStreamSourceChannel

    • Constructor Detail

      • FixedLengthStreamSourceChannel

        public FixedLengthStreamSourceChannel​(StreamSourceChannel delegate,
                                              long contentLength,
                                              ChannelListener<? super FixedLengthStreamSourceChannel> finishListener,
                                              java.lang.Object guard)
        Construct a new instance. The given listener is called once all the bytes are read from the stream or the stream is closed. This listener should cause the remaining data to be drained from the underlying stream via the #drain() method if the underlying stream is to be reused.

        Calling this constructor will replace the read listener of the underlying channel. The listener should be restored from the finishListener object. The underlying stream should not be closed while this wrapper stream is active.

        Parameters:
        delegate - the stream source channel to read from
        contentLength - the amount of content to read
        finishListener - the listener to call once the stream is exhausted or closed
        guard - the guard object to use
      • FixedLengthStreamSourceChannel

        public FixedLengthStreamSourceChannel​(StreamSourceChannel delegate,
                                              long contentLength,
                                              boolean configurable,
                                              ChannelListener<? super FixedLengthStreamSourceChannel> finishListener,
                                              java.lang.Object guard)
        Construct a new instance. The given listener is called once all the bytes are read from the stream or the stream is closed. This listener should cause the remaining data to be drained from the underlying stream via the #drain() method if the underlying stream is to be reused.

        Calling this constructor will replace the read listener of the underlying channel. The listener should be restored from the finishListener object. The underlying stream should not be closed while this wrapper stream is active.

        Parameters:
        delegate - the stream source channel to read from
        contentLength - the amount of content to read
        configurable - true to allow options to pass through to the delegate, false otherwise
        finishListener - the listener to call once the stream is exhausted or closed
        guard - the guard object to use
      • FixedLengthStreamSourceChannel

        public FixedLengthStreamSourceChannel​(StreamSourceChannel delegate,
                                              long contentLength,
                                              boolean configurable,
                                              boolean propagateClose,
                                              ChannelListener<? super FixedLengthStreamSourceChannel> finishListener,
                                              java.lang.Object guard)
        Construct a new instance. The given listener is called once all the bytes are read from the stream or the stream is closed. This listener should cause the remaining data to be drained from the underlying stream via the #drain() method if the underlying stream is to be reused.

        Calling this constructor will replace the read listener of the underlying channel. The listener should be restored from the finishListener object. The underlying stream should not be closed while this wrapper stream is active.

        Parameters:
        delegate - the stream source channel to read from
        contentLength - the amount of content to read
        configurable - true to allow options to pass through to the delegate, false otherwise
        propagateClose - true to propagate close/shutdown to the delegate, false otherwise
        finishListener - the listener to call once the stream is exhausted or closed
        guard - the guard object to use
    • Method Detail

      • transferTo

        public long transferTo​(long position,
                               long count,
                               java.nio.channels.FileChannel target)
                        throws java.io.IOException
        Description copied from interface: StreamSourceChannel
        Transfers bytes into the given file from this channel. Using this method in preference to FileChannel.transferFrom(ReadableByteChannel, long, long) may provide a performance advantage on some platforms.

        If the current thread is interrupted when this method is called, it may throw a InterruptedIOException; however, if this exception is thrown, the InterruptedIOException.bytesTransferred field is guaranteed to be 0.

        Specified by:
        transferTo in interface StreamSourceChannel
        Parameters:
        position - the position within the file from which the transfer is to begin
        count - the number of bytes to be transferred
        target - the file to write to
        Returns:
        the number of bytes (possibly 0) that were actually transferred
        Throws:
        java.io.IOException - if an I/O error occurs
      • transferTo

        public long transferTo​(long count,
                               java.nio.ByteBuffer throughBuffer,
                               StreamSinkChannel target)
                        throws java.io.IOException
        Description copied from interface: StreamSourceChannel
        Transfers bytes into the given channel target. On some platforms, this may avoid copying bytes between user and kernel space. On other platforms, bytes are passed through the throughBuffer parameter's buffer space. On entry, throughBuffer will be cleared. On exit, the buffer will be flipped for emptying, and may possibly be empty or may contain data. If this method returns a value less than count, then the remaining data in throughBuffer may contain data read from this channel which must be written to target to complete the operation. Note that using a direct buffer may provide an intermediate performance gain on platforms without zero-copy facilities.

        If the current thread is interrupted when this method is called, it may throw a InterruptedIOException; however, if this exception is thrown, the InterruptedIOException.bytesTransferred field is guaranteed to be 0. Note that the return value is the amount of data that was actually transferred to the StreamSinkChannel. The actual amount of data read could be larger than this, and can be calculated by adding the return value and the amount of data left in throughBuffer.

        Specified by:
        transferTo in interface StreamSourceChannel
        Parameters:
        count - the number of bytes to be transferred
        throughBuffer - the buffer to copy through.
        target - the destination to write to
        Returns:
        the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached
        Throws:
        java.io.IOException - if an I/O error occurs
      • read

        public long read​(java.nio.ByteBuffer[] dsts,
                         int offset,
                         int length)
                  throws java.io.IOException
        Specified by:
        read in interface java.nio.channels.ScatteringByteChannel
        Throws:
        java.io.IOException
      • read

        public long read​(java.nio.ByteBuffer[] dsts)
                  throws java.io.IOException
        Specified by:
        read in interface java.nio.channels.ScatteringByteChannel
        Throws:
        java.io.IOException
      • read

        public int read​(java.nio.ByteBuffer dst)
                 throws java.io.IOException
        Specified by:
        read in interface java.nio.channels.ReadableByteChannel
        Throws:
        java.io.IOException
      • shutdownReads

        public void shutdownReads()
                           throws java.io.IOException
        Description copied from interface: SuspendableReadChannel
        Places this readable channel at "end of stream". Further reads will result in EOF. Shutting down all directions of a channel will cause CloseableChannel.close() to be called automatically.
        Specified by:
        shutdownReads in interface SuspendableReadChannel
        Throws:
        java.io.IOException - if an I/O error occurs
      • awaitReadable

        public void awaitReadable()
                           throws java.io.IOException
        Description copied from interface: SuspendableReadChannel
        Block until this channel becomes readable again. This method may return spuriously before the channel becomes readable.
        Specified by:
        awaitReadable in interface SuspendableReadChannel
        Throws:
        java.io.InterruptedIOException - if the operation is interrupted; the thread's interrupt flag will be set as well
        java.io.IOException - if an I/O error occurs
      • awaitReadable

        public void awaitReadable​(long time,
                                  java.util.concurrent.TimeUnit timeUnit)
                           throws java.io.IOException
        Description copied from interface: SuspendableReadChannel
        Block until this channel becomes readable again, or until the timeout expires. This method may return spuriously before the channel becomes readable or the timeout expires.
        Specified by:
        awaitReadable in interface SuspendableReadChannel
        Parameters:
        time - the time to wait
        timeUnit - the time unit
        Throws:
        java.io.InterruptedIOException - if the operation is interrupted; the thread's interrupt flag will be set as well
        java.io.IOException - if an I/O error occurs
      • isOpen

        public boolean isOpen()
        Specified by:
        isOpen in interface java.nio.channels.Channel
      • close

        public void close()
                   throws java.io.IOException
        Description copied from interface: CloseableChannel
        Close this channel. When a channel is closed, its close listener is invoked. Invoking this method more than once has no additional effect.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface CloseableChannel
        Specified by:
        close in interface java.nio.channels.InterruptibleChannel
        Throws:
        java.io.IOException - if the close failed
      • supportsOption

        public boolean supportsOption​(Option<?> option)
        Description copied from interface: Configurable
        Determine whether an option is supported on this channel.
        Specified by:
        supportsOption in interface Configurable
        Parameters:
        option - the option
        Returns:
        true if it is supported
      • getOption

        public <T> T getOption​(Option<T> option)
                        throws java.io.IOException
        Description copied from interface: Configurable
        Get the value of a channel option.
        Specified by:
        getOption in interface Configurable
        Type Parameters:
        T - the type of the option value
        Parameters:
        option - the option to get
        Returns:
        the value of the option, or null if it is not set
        Throws:
        java.io.IOException - if an I/O error occurred when reading the option
      • setOption

        public <T> T setOption​(Option<T> option,
                               T value)
                        throws java.lang.IllegalArgumentException,
                               java.io.IOException
        Description copied from interface: Configurable
        Set an option for this channel. Unsupported options are ignored.
        Specified by:
        setOption in interface Configurable
        Type Parameters:
        T - the type of the option value
        Parameters:
        option - the option to set
        value - the value of the option to set
        Returns:
        the previous option value, if any
        Throws:
        java.lang.IllegalArgumentException - if the value is not acceptable for this option
        java.io.IOException - if an I/O error occurred when modifying the option
      • getRemaining

        public long getRemaining()
        Get the number of remaining bytes.
        Returns:
        the number of remaining bytes