Class HttpInput.Content

java.lang.Object
org.eclipse.jetty.server.HttpInput.Content
All Implemented Interfaces:
Callback, Invocable
Direct Known Subclasses:
HttpInput.SpecialContent, HttpInput.WrappingContent
Enclosing class:
HttpInput

public static class HttpInput.Content extends Object implements Callback
A content represents the production of a HttpChannel returned by HttpChannel.produceContent(). There are two fundamental types of content: special and non-special. Non-special content always wraps a byte buffer that can be consumed and must be recycled once it is empty, either via Callback.succeeded() or Callback.failed(Throwable). Special content indicates a special event, like EOF or an error and never wraps a byte buffer. Calling Callback.succeeded() or Callback.failed(Throwable) on those have no effect.
  • Field Details

  • Constructor Details

  • Method Details

    • getByteBuffer

      public ByteBuffer getByteBuffer()
      Get the wrapped byte buffer. Throws IllegalStateException if the content is special.
      Returns:
      the wrapped byte buffer.
    • getInvocationType

      public Invocable.InvocationType getInvocationType()
      Specified by:
      getInvocationType in interface Invocable
      Returns:
      The InvocationType of this object
    • get

      public int get(byte[] buffer, int offset, int length)
      Read the wrapped byte buffer. Throws IllegalStateException if the content is special.
      Parameters:
      buffer - The array into which bytes are to be written.
      offset - The offset within the array of the first byte to be written.
      length - The maximum number of bytes to be written to the given array.
      Returns:
      The amount of bytes read from the buffer.
    • skip

      public int skip(int length)
      Skip some bytes from the buffer. Has no effect on a special content.
      Parameters:
      length - How many bytes to skip.
      Returns:
      How many bytes were skipped.
    • hasContent

      public boolean hasContent()
      Check if there is at least one byte left in the buffer. Always false on a special content.
      Returns:
      true if there is at least one byte left in the buffer.
    • remaining

      public int remaining()
      Get the number of bytes remaining in the buffer. Always 0 on a special content.
      Returns:
      the number of bytes remaining in the buffer.
    • isEmpty

      public boolean isEmpty()
      Check if the buffer is empty. Always true on a special content.
      Returns:
      true if there is 0 byte left in the buffer.
    • isSpecial

      public boolean isSpecial()
      Check if the content is special. A content is deemed special if it does not hold bytes but rather conveys a special event, like when EOF has been reached or an error has occurred.
      Returns:
      true if the content is special, false otherwise.
    • isEof

      public boolean isEof()
      Check if EOF was reached. Both special and non-special content can have this flag set to true but in the case of non-special content, this can be interpreted as a hint as it is always going to be followed by another content that is both special and EOF.
      Returns:
      true if EOF was reached, false otherwise.
    • getError

      public Throwable getError()
      Get the reported error. Only special contents can have an error.
      Returns:
      the error or null if there is none.
    • toString

      public String toString()
      Overrides:
      toString in class Object