Class HttpContent

java.lang.Object
org.eclipse.jetty.client.HttpContent
All Implemented Interfaces:
Closeable, AutoCloseable, org.eclipse.jetty.util.Callback, org.eclipse.jetty.util.thread.Invocable

public class HttpContent extends Object implements org.eclipse.jetty.util.Callback, Closeable
HttpContent is a stateful, linear representation of the request content provided by a ContentProvider that can be traversed one-way to obtain content buffers to send to an HTTP server.

HttpContent offers the notion of a one-way cursor to traverse the content. The cursor starts in a virtual "before" position and can be advanced using advance() until it reaches a virtual "after" position where the content is fully consumed.

      +---+  +---+  +---+  +---+  +---+
      |   |  |   |  |   |  |   |  |   |
      +---+  +---+  +---+  +---+  +---+
   ^           ^                    ^    ^
   |           | --> advance()      |    |
   |           |                  last   |
   |           |                         |
 before        |                        after
               |
            current
 
At each valid (non-before and non-after) cursor position, HttpContent provides the following state:
  • the buffer containing the content to send, via getByteBuffer()
  • a copy of the content buffer that can be used for notifications, via getContent()
  • whether the buffer to write is the last one, via isLast()
HttpContent may not have content, if the related ContentProvider is null, and this is reflected by hasContent().

HttpContent may have deferred content, in which case advance() moves the cursor to a position that provides null buffer and content. When the deferred content is available, a further call to advance() will move the cursor to a position that provides non null buffer and content.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.Callback

    org.eclipse.jetty.util.Callback.Completable, org.eclipse.jetty.util.Callback.Completing, org.eclipse.jetty.util.Callback.Nested

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable

    org.eclipse.jetty.util.thread.Invocable.InvocationType
  • Field Summary

    Fields inherited from interface org.eclipse.jetty.util.Callback

    NOOP

    Fields inherited from interface org.eclipse.jetty.util.thread.Invocable

    __nonBlocking
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Advances the cursor to the next block of content.
    void
     
    void
     
     
     
    boolean
     
    boolean
     
    boolean
     
    void
     
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.eclipse.jetty.util.thread.Invocable

    getInvocationType
  • Constructor Details

  • Method Details

    • hasContent

      public boolean hasContent()
      Returns:
      whether there is any content at all
    • isLast

      public boolean isLast()
      Returns:
      whether the cursor points to the last content
    • getByteBuffer

      public ByteBuffer getByteBuffer()
      Returns:
      the ByteBuffer containing the content at the cursor's position
    • getContent

      public ByteBuffer getContent()
      Returns:
      a ByteBuffer.slice() of getByteBuffer() at the cursor's position
    • advance

      public boolean advance()
      Advances the cursor to the next block of content.

      The next block of content may be valid (which yields a non-null buffer returned by getByteBuffer()), but may also be deferred (which yields a null buffer returned by getByteBuffer()).

      If the block of content pointed by the new cursor position is valid, this method returns true.

      Returns:
      true if there is content at the new cursor's position, false otherwise.
    • isConsumed

      public boolean isConsumed()
      Returns:
      whether the cursor has been advanced past the last position.
    • succeeded

      public void succeeded()
      Specified by:
      succeeded in interface org.eclipse.jetty.util.Callback
    • failed

      public void failed(Throwable x)
      Specified by:
      failed in interface org.eclipse.jetty.util.Callback
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • toString

      public String toString()
      Overrides:
      toString in class Object