Class ChunkedBodyOutputStream

java.lang.Object
java.io.OutputStream
org.glassfish.jersey.jdk.connector.internal.BodyOutputStream
org.glassfish.jersey.jdk.connector.internal.ChunkedBodyOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

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

    • EMPTY_BUFFER

      private static final ByteBuffer EMPTY_BUFFER
    • chunkSize

      private final int chunkSize
    • encodedFullChunkSize

      private final int encodedFullChunkSize
    • dataBuffer

      private final ByteBuffer dataBuffer
    • initialBlockingLatch

      private final CountDownLatch initialBlockingLatch
    • downstreamFilter

      private volatile Filter<ByteBuffer,?,?,?> downstreamFilter
    • writeListener

      private volatile WriteListener writeListener
    • closeListener

      private volatile ChunkedBodyOutputStream.Listener closeListener
    • mode

      private volatile ChunkedBodyOutputStream.Mode mode
    • ready

      private volatile boolean ready
    • callListener

      private volatile boolean callListener
    • closed

      private volatile boolean closed
  • Constructor Details

    • ChunkedBodyOutputStream

      ChunkedBodyOutputStream(int chunkSize)
  • Method Details

    • 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 IOException
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • flush

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

      public void write(int b) throws IOException
      Specified by:
      write in class OutputStream
      Throws:
      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(ByteBuffer byteBuffer) throws IOException
      Throws:
      IOException
    • open

      void open(Filter<ByteBuffer,?,?,?> downstreamFilter)
    • doInitialBlocking

      protected void doInitialBlocking() throws IOException
      Throws:
      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 ByteBuffer encodeToHttp(ByteBuffer byteBuffer)
      Transform raw application data into HTTP body.
      Parameters:
      byteBuffer - application data.
      Returns:
      http body part.
    • close

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