Class ChunkedBodyOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    class ChunkedBodyOutputStream
    extends BodyOutputStream
    Body stream that can operate either synchronously or asynchronously. See BodyOutputStream for details.
    • Field Detail

      • EMPTY_BUFFER

        private static final java.nio.ByteBuffer EMPTY_BUFFER
      • chunkSize

        private final int chunkSize
      • encodedFullChunkSize

        private final int encodedFullChunkSize
      • dataBuffer

        private final java.nio.ByteBuffer dataBuffer
      • initialBlockingLatch

        private final java.util.concurrent.CountDownLatch initialBlockingLatch
      • downstreamFilter

        private volatile Filter<java.nio.ByteBuffer,​?,​?,​?> downstreamFilter
      • ready

        private volatile boolean ready
      • callListener

        private volatile boolean callListener
      • closed

        private volatile boolean closed
    • Constructor Detail

      • ChunkedBodyOutputStream

        ChunkedBodyOutputStream​(int chunkSize)
    • Method Detail

      • setWriteListener

        public void setWriteListener​(WriteListener writeListener)
        Description copied from class: BodyOutputStream
        Instructs the stream to invoke the provided WriteListener when it is possible to write.

        If the stream is in UNDECIDED state, invoking this method will commit the stream to ASYNCHRONOUS mode.

        Specified by:
        setWriteListener in class BodyOutputStream
        Parameters:
        writeListener - the WriteListener that should be notified when it's possible to write.
      • write

        public void write​(byte[] b,
                          int off,
                          int len)
                   throws java.io.IOException
        Overrides:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(int b)
                   throws java.io.IOException
        Specified by:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • isReady

        public boolean isReady()
        Description copied from class: BodyOutputStream
        Returns true if data can be written without blocking else returns false.

        If the stream is in ASYNCHRONOUS mode and the user attempts to write to it even though this method returns false, an IllegalStateException is thrown.

        Specified by:
        isReady in class BodyOutputStream
        Returns:
        true if data can be obtained without blocking, otherwise returns false.
      • assertValidState

        private void assertValidState()
      • write

        protected void write​(java.nio.ByteBuffer byteBuffer)
                      throws java.io.IOException
        Throws:
        java.io.IOException
      • open

        void open​(Filter<java.nio.ByteBuffer,​?,​?,​?> downstreamFilter)
      • doInitialBlocking

        protected void doInitialBlocking()
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • commitToMode

        protected void commitToMode()
      • assertAsynchronousOperation

        private void assertAsynchronousOperation()
      • callOnWritePossible

        private void callOnWritePossible()
      • setCloseListener

        void setCloseListener​(ChunkedBodyOutputStream.Listener closeListener)
        Set a close listener which will be called when the user closes the stream.

        This is used to indicate that the body has been completely written.

        Parameters:
        closeListener - close listener.
      • encodeToHttp

        protected java.nio.ByteBuffer encodeToHttp​(java.nio.ByteBuffer byteBuffer)
        Transform raw application data into HTTP body.
        Parameters:
        byteBuffer - application data.
        Returns:
        http body part.
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream
        Throws:
        java.io.IOException