public class InputStreamHandler extends InputStream implements ContentHandler
ContentHandler used by ControllerDispatcher.
This handler receives chunks of data which are stored in an internal buffer. This buffer can be accessed via
the familiar InputStream interface. Note that the methods of this implementation might block if either
the internal buffer is full, or if no content is currently readable.
For stability reasons all blocking methods timeout after a given interval of time leading the handle to be in an error state. Therefore all incoming data will be discarded and all read requests will fail as some data might have already been lost anyway.
| Constructor and Description |
|---|
InputStreamHandler()
Creates a new handler with default settings for buffer size and timeouts.
|
InputStreamHandler(int bufferDepth,
int readTimeout,
int writeTimeout,
TimeUnit unit)
Creates a new handler with the given buffer size and timeouts.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
void |
cleanup()
Invoked once the request is completely handled or the underlying channel was closed.
|
void |
close() |
void |
handle(ByteBuf content,
boolean last)
Handles the given chunk of data.
|
boolean |
isFailed()
Determines if this stream is in an ERROR state or not.
|
void |
mark(int readlimit) |
boolean |
markSupported() |
int |
read() |
int |
read(byte[] b,
int off,
int len) |
void |
reset() |
long |
skip(long n) |
readpublic InputStreamHandler()
public InputStreamHandler(int bufferDepth,
int readTimeout,
int writeTimeout,
TimeUnit unit)
bufferDepth - controls how many chunks are kept in memory before the next call to
handle(io.netty.buffer.ByteBuf, boolean) blocks until some data is read from the
buffer. Although the number of chunks does not provide an exact measure of the buffer size,
it should provide a raw estimate as incoming chunks will be between 1024 and 8192 bytes in
size.readTimeout - contains maximal amount of time a reading thread is blocked, waiting for new data,
before the operation is cancelled by a timeoutwriteTimeout - contains maximal amount of time a writing thread is blocked, waiting for buffer space,
before the operation is cancelled by a timeoutunit - specifies the time unit used by readTimeout and writeTimeoutpublic void handle(ByteBuf content, boolean last) throws IOException
ContentHandlerhandle in interface ContentHandlercontent - the data sent by the client. The buffer might be of size 0 but not null.last - a flag signalling if this will be the last chunk of dataIOException - if case of an error (e.g. response already sent...)public void cleanup()
throws IOException
ContentHandlerCan be used to release all internal buffers.
cleanup in interface ContentHandlerIOException - in case of an internal errorpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOExceptionpublic int read()
throws IOException
read in class InputStreamIOExceptionpublic int read(byte[] b,
int off,
int len)
throws IOException
read in class InputStreamIOExceptionpublic long skip(long n)
throws IOException
skip in class InputStreamIOExceptionpublic int available()
throws IOException
available in class InputStreamIOExceptionpublic void mark(int readlimit)
mark in class InputStreampublic void reset()
throws IOException
reset in class InputStreamIOExceptionpublic boolean markSupported()
markSupported in class InputStreampublic boolean isFailed()
Copyright © 2018. All rights reserved.