Class HttpInput.Content

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

public static class HttpInput.Content extends Object implements org.eclipse.jetty.util.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.
  • 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, org.eclipse.jetty.util.thread.Invocable.ReadyTask, org.eclipse.jetty.util.thread.Invocable.Task
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final ByteBuffer
     

    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
    int
    get(byte[] buffer, int offset, int length)
    Read the wrapped byte buffer.
    Get the wrapped byte buffer.
    Get the reported error.
    org.eclipse.jetty.util.thread.Invocable.InvocationType
     
    boolean
    Check if there is at least one byte left in the buffer.
    boolean
    Check if the buffer is empty.
    boolean
    Check if EOF was reached.
    boolean
    Check if the content is special.
    int
    Get the number of bytes remaining in the buffer.
    int
    skip(int length)
    Skip some bytes from the buffer.
     

    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.Callback

    completeWith, failed, succeeded
  • 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 org.eclipse.jetty.util.thread.Invocable.InvocationType getInvocationType()
      Specified by:
      getInvocationType in interface org.eclipse.jetty.util.thread.Invocable
    • 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