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) |
read
public 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
ContentHandler
handle
in interface ContentHandler
content
- 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
ContentHandler
Can be used to release all internal buffers.
cleanup
in interface ContentHandler
IOException
- in case of an internal errorpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
IOException
public long skip(long n) throws IOException
skip
in class InputStream
IOException
public int available() throws IOException
available
in class InputStream
IOException
public void mark(int readlimit)
mark
in class InputStream
public void reset() throws IOException
reset
in class InputStream
IOException
public boolean markSupported()
markSupported
in class InputStream
public boolean isFailed()
Copyright © 2018. All rights reserved.