Class FixedLengthStreamSourceConduit

  • All Implemented Interfaces:
    org.xnio.conduits.Conduit, org.xnio.conduits.SourceConduit, org.xnio.conduits.StreamSourceConduit

    public final class FixedLengthStreamSourceConduit
    extends org.xnio.conduits.AbstractStreamSourceConduit<org.xnio.conduits.StreamSourceConduit>
    A channel which reads data of a fixed length and calls a finish listener. When the finish listener is called, it should examine the result of getRemaining() to see if more bytes were pending when the channel was closed.
    Author:
    David M. Lloyd, Flavia Rainone
    • Field Summary

      • Fields inherited from class org.xnio.conduits.AbstractConduit

        next
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void awaitReadable()  
      void awaitReadable​(long time, java.util.concurrent.TimeUnit timeUnit)  
      long getRemaining()
      Get the number of remaining bytes.
      boolean isReadResumed()  
      int read​(java.nio.ByteBuffer dst)  
      long read​(java.nio.ByteBuffer[] dsts)  
      long read​(java.nio.ByteBuffer[] dsts, int offset, int length)  
      void resumeReads()  
      void terminateReads()  
      long transferTo​(long position, long count, java.nio.channels.FileChannel target)  
      long transferTo​(long count, java.nio.ByteBuffer throughBuffer, org.xnio.channels.StreamSinkChannel target)  
      void wakeupReads()  
      • Methods inherited from class org.xnio.conduits.AbstractSourceConduit

        getReadThread, isReadShutdown, setReadReadyHandler, suspendReads
      • Methods inherited from class org.xnio.conduits.AbstractConduit

        getWorker
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.xnio.conduits.Conduit

        getWorker
      • Methods inherited from interface org.xnio.conduits.SourceConduit

        getReadThread, isReadShutdown, setReadReadyHandler, suspendReads
    • Constructor Detail

      • FixedLengthStreamSourceConduit

        public FixedLengthStreamSourceConduit​(org.xnio.conduits.StreamSourceConduit next,
                                              long contentLength,
                                              ConduitListener<? super FixedLengthStreamSourceConduit> finishListener,
                                              HttpServerExchange exchange)
        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 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:
        next - 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
        exchange - The server exchange. This is used to determine the max size
      • FixedLengthStreamSourceConduit

        public FixedLengthStreamSourceConduit​(org.xnio.conduits.StreamSourceConduit next,
                                              long contentLength,
                                              ConduitListener<? super FixedLengthStreamSourceConduit> finishListener)
        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 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:
        next - 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
    • Method Detail

      • transferTo

        public long transferTo​(long position,
                               long count,
                               java.nio.channels.FileChannel target)
                        throws java.io.IOException
        Specified by:
        transferTo in interface org.xnio.conduits.StreamSourceConduit
        Overrides:
        transferTo in class org.xnio.conduits.AbstractStreamSourceConduit<org.xnio.conduits.StreamSourceConduit>
        Throws:
        java.io.IOException
      • transferTo

        public long transferTo​(long count,
                               java.nio.ByteBuffer throughBuffer,
                               org.xnio.channels.StreamSinkChannel target)
                        throws java.io.IOException
        Specified by:
        transferTo in interface org.xnio.conduits.StreamSourceConduit
        Overrides:
        transferTo in class org.xnio.conduits.AbstractStreamSourceConduit<org.xnio.conduits.StreamSourceConduit>
        Throws:
        java.io.IOException
      • read

        public long read​(java.nio.ByteBuffer[] dsts,
                         int offset,
                         int length)
                  throws java.io.IOException
        Specified by:
        read in interface org.xnio.conduits.StreamSourceConduit
        Overrides:
        read in class org.xnio.conduits.AbstractStreamSourceConduit<org.xnio.conduits.StreamSourceConduit>
        Throws:
        java.io.IOException
      • read

        public long read​(java.nio.ByteBuffer[] dsts)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        public int read​(java.nio.ByteBuffer dst)
                 throws java.io.IOException
        Specified by:
        read in interface org.xnio.conduits.StreamSourceConduit
        Overrides:
        read in class org.xnio.conduits.AbstractStreamSourceConduit<org.xnio.conduits.StreamSourceConduit>
        Throws:
        java.io.IOException
      • isReadResumed

        public boolean isReadResumed()
        Specified by:
        isReadResumed in interface org.xnio.conduits.SourceConduit
        Overrides:
        isReadResumed in class org.xnio.conduits.AbstractSourceConduit<org.xnio.conduits.StreamSourceConduit>
      • wakeupReads

        public void wakeupReads()
        Specified by:
        wakeupReads in interface org.xnio.conduits.SourceConduit
        Overrides:
        wakeupReads in class org.xnio.conduits.AbstractSourceConduit<org.xnio.conduits.StreamSourceConduit>
      • resumeReads

        public void resumeReads()
        Specified by:
        resumeReads in interface org.xnio.conduits.SourceConduit
        Overrides:
        resumeReads in class org.xnio.conduits.AbstractSourceConduit<org.xnio.conduits.StreamSourceConduit>
      • terminateReads

        public void terminateReads()
                            throws java.io.IOException
        Specified by:
        terminateReads in interface org.xnio.conduits.SourceConduit
        Overrides:
        terminateReads in class org.xnio.conduits.AbstractSourceConduit<org.xnio.conduits.StreamSourceConduit>
        Throws:
        java.io.IOException
      • awaitReadable

        public void awaitReadable()
                           throws java.io.IOException
        Specified by:
        awaitReadable in interface org.xnio.conduits.SourceConduit
        Overrides:
        awaitReadable in class org.xnio.conduits.AbstractSourceConduit<org.xnio.conduits.StreamSourceConduit>
        Throws:
        java.io.IOException
      • awaitReadable

        public void awaitReadable​(long time,
                                  java.util.concurrent.TimeUnit timeUnit)
                           throws java.io.IOException
        Specified by:
        awaitReadable in interface org.xnio.conduits.SourceConduit
        Overrides:
        awaitReadable in class org.xnio.conduits.AbstractSourceConduit<org.xnio.conduits.StreamSourceConduit>
        Throws:
        java.io.IOException
      • getRemaining

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