Package org.eclipse.jetty.server
Class HttpInput
- java.lang.Object
-
- java.io.InputStream
-
- javax.servlet.ServletInputStream
-
- org.eclipse.jetty.server.HttpInput
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Runnable
- Direct Known Subclasses:
HttpInputOverHTTP
public class HttpInput extends ServletInputStream implements java.lang.Runnable
HttpInput
provides an implementation ofServletInputStream
forHttpChannel
.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HttpInput.ChainedInterceptor
AnHttpInput.Interceptor
that chains two otherHttpInput.Interceptor
s together.static class
HttpInput.Content
static class
HttpInput.EofContent
static interface
HttpInput.Interceptor
An interceptor for HTTP Request input.static class
HttpInput.SentinelContent
A Sentinel Content, which has zero length content but indicates some other event in the input stream (eg EOF)
-
Constructor Summary
Constructors Constructor Description HttpInput(HttpChannelState state)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addContent(HttpInput.Content content)
Adds some content to this input stream.void
addInterceptor(HttpInput.Interceptor interceptor)
Set theHttpInput.Interceptor
, using aHttpInput.ChainedInterceptor
if anHttpInput.Interceptor
is already set.void
asyncReadProduce()
Called by channel when asynchronous IO needs to produce more contentint
available()
boolean
consumeAll()
boolean
earlyEOF()
This method should be called to signal that an EOF has been detected before all the expected content arrived.boolean
eof()
This method should be called to signal that all the expected content arrived.boolean
failed(java.lang.Throwable x)
long
getContentConsumed()
HttpInput.Interceptor
getInterceptor()
boolean
hasContent()
boolean
isAsync()
boolean
isError()
boolean
isFinished()
boolean
isReady()
boolean
onIdleTimeout(java.lang.Throwable x)
int
read()
int
read(byte[] b, int off, int len)
void
recycle()
void
run()
void
setInterceptor(HttpInput.Interceptor interceptor)
Set the interceptor.void
setReadListener(ReadListener readListener)
java.lang.String
toString()
void
unblock()
-
Methods inherited from class javax.servlet.ServletInputStream
readLine
-
-
-
-
Constructor Detail
-
HttpInput
public HttpInput(HttpChannelState state)
-
-
Method Detail
-
recycle
public void recycle()
-
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)
Set theHttpInput.Interceptor
, using aHttpInput.ChainedInterceptor
if anHttpInput.Interceptor
is already set.- Parameters:
interceptor
- the nextHttpInput.Interceptor
in a chain
-
available
public int available()
- Overrides:
available
in classjava.io.InputStream
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
asyncReadProduce
public void asyncReadProduce() throws java.io.IOException
Called by channel when asynchronous IO needs to produce more content- Throws:
java.io.IOException
- if unable to produce content
-
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()
-
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()
-
isError
public boolean isError()
-
isAsync
public boolean isAsync()
-
isFinished
public boolean isFinished()
- Specified by:
isFinished
in classServletInputStream
-
isReady
public boolean isReady()
- Specified by:
isReady
in classServletInputStream
-
setReadListener
public void setReadListener(ReadListener readListener)
- Specified by:
setReadListener
in classServletInputStream
-
onIdleTimeout
public boolean onIdleTimeout(java.lang.Throwable x)
-
failed
public boolean failed(java.lang.Throwable x)
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-