Class HttpInput

java.lang.Object
java.io.InputStream
javax.servlet.ServletInputStream
org.eclipse.jetty.server.HttpInput
All Implemented Interfaces:
Closeable, AutoCloseable, Runnable
Direct Known Subclasses:
HttpInputOverHTTP

public class HttpInput extends javax.servlet.ServletInputStream implements Runnable
HttpInput provides an implementation of ServletInputStream for HttpChannel.

Content may arrive in patterns such as [content(), content(), messageComplete()] so that this class maintains two states: the content state that tells whether there is content to consume and the EOF state that tells whether an EOF has arrived. Only once the content has been consumed the content state is moved to the EOF state.

  • Field Details

  • Constructor Details

  • Method Details

    • getHttpChannelState

      protected HttpChannelState getHttpChannelState()
    • recycle

      public void recycle()
    • fail

      private Throwable fail(HttpInput.Content content, Throwable failure)
    • getInterceptor

      public HttpInput.Interceptor getInterceptor()
      Returns:
      The current Interceptor, or null if none set
    • setInterceptor

      public void setInterceptor(HttpInput.Interceptor interceptor)
      Set the interceptor.
      Parameters:
      interceptor - The interceptor to use.
    • addInterceptor

      public void addInterceptor(HttpInput.Interceptor interceptor)
      Parameters:
      interceptor - the next HttpInput.Interceptor in a chain
    • available

      public int available()
      Overrides:
      available in class InputStream
    • wake

      protected void wake()
    • getBlockingTimeout

      private long getBlockingTimeout()
    • read

      public int read() throws IOException
      Specified by:
      read in class InputStream
      Throws:
      IOException
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • produceContent

      protected void produceContent() throws IOException
      Called when derived implementations should attempt to produce more Content and add it via addContent(Content). For protocols that are constantly producing (eg HTTP2) this can be left as a noop;
      Throws:
      IOException - if unable to produce content
    • asyncReadProduce

      public void asyncReadProduce() throws IOException
      Called by channel when asynchronous IO needs to produce more content
      Throws:
      IOException - if unable to produce content
    • nextContent

      protected HttpInput.Content nextContent() throws IOException
      Get the next content from the inputQ, calling produceContent() if need be. EOF is processed and state changed.
      Returns:
      the content or null if none available.
      Throws:
      IOException - if retrieving the content fails
    • nextNonSentinelContent

      protected HttpInput.Content nextNonSentinelContent() throws IOException
      Poll the inputQ for Content. Consumed buffers and HttpInput.SentinelContents are removed and EOF state updated if need be.
      Returns:
      Content or null
      Throws:
      IOException
    • produceNextContent

      protected HttpInput.Content produceNextContent() throws IOException
      Get the next readable from the inputQ, calling produceContent() if need be. EOF is NOT processed and state is not changed.
      Returns:
      the content or EOF or null if none available.
      Throws:
      IOException - if retrieving the content fails
    • nextInterceptedContent

      protected HttpInput.Content nextInterceptedContent() throws IOException
      Poll the inputQ for Content or EOF. Consumed buffers and non EOF HttpInput.SentinelContents are removed. EOF state is not updated. Interception is done within this method.
      Returns:
      Content with remaining, a HttpInput.SentinelContent, or null
      Throws:
      IOException
    • intercept

      private HttpInput.Content intercept(HttpInput.Content content) throws IOException
      Throws:
      IOException
    • consume

      private void consume(HttpInput.Content content)
    • get

      protected int get(HttpInput.Content content, byte[] buffer, int offset, int length)
      Copies the given content into the given byte buffer.
      Parameters:
      content - the content to copy from
      buffer - the buffer to copy into
      offset - the buffer offset to start copying from
      length - the space available in the buffer
      Returns:
      the number of bytes actually copied
    • blockForContent

      protected void blockForContent() throws IOException
      Blocks until some content or some end-of-file event arrives.
      Throws:
      IOException - if the wait is interrupted
    • addContent

      public boolean addContent(HttpInput.Content content)
      Adds some content to this input stream.
      Parameters:
      content - the content to add
      Returns:
      true if content channel woken for read
    • hasContent

      public boolean hasContent()
    • unblock

      public void unblock()
    • getContentConsumed

      public long getContentConsumed()
    • getContentReceived

      public long getContentReceived()
    • earlyEOF

      public boolean earlyEOF()
      This method should be called to signal that an EOF has been detected before all the expected content arrived.

      Typically this will result in an EOFException being thrown from a subsequent read rather than a -1 return.

      Returns:
      true if content channel woken for read
    • eof

      public boolean eof()
      This method should be called to signal that all the expected content arrived.
      Returns:
      true if content channel woken for read
    • consumeAll

      public boolean consumeAll()
      Consume all available content without blocking. Raw content is counted in the getContentReceived() statistics, but is not intercepted nor counted in the getContentConsumed() statistics
      Returns:
      True if EOF was reached, false otherwise.
    • isError

      public boolean isError()
    • isAsync

      public boolean isAsync()
    • isFinished

      public boolean isFinished()
      Specified by:
      isFinished in class javax.servlet.ServletInputStream
    • isReady

      public boolean isReady()
      Specified by:
      isReady in class javax.servlet.ServletInputStream
    • setReadListener

      public void setReadListener(javax.servlet.ReadListener readListener)
      Specified by:
      setReadListener in class javax.servlet.ServletInputStream
    • onIdleTimeout

      public boolean onIdleTimeout(Throwable x)
    • failed

      public boolean failed(Throwable x)
    • wakeup

      private boolean wakeup()
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • toString

      public String toString()
      Overrides:
      toString in class Object