public abstract class SimpleDecoder<I extends DecoderInputBuffer,O extends OutputBuffer,E extends Exception> extends Object implements Decoder<I,O,E>
Decoder
s that use their own decode thread.Modifier | Constructor and Description |
---|---|
protected |
SimpleDecoder(I[] inputBuffers,
O[] outputBuffers) |
Modifier and Type | Method and Description |
---|---|
protected abstract I |
createInputBuffer()
Creates a new input buffer.
|
protected abstract O |
createOutputBuffer()
Creates a new output buffer.
|
protected abstract E |
createUnexpectedDecodeException(Throwable error)
Creates an exception to propagate for an unexpected decode error.
|
protected abstract E |
decode(I inputBuffer,
O outputBuffer,
boolean reset)
Decodes the
inputBuffer and stores any decoded output in outputBuffer . |
I |
dequeueInputBuffer()
Dequeues the next input buffer to be filled and queued to the decoder.
|
O |
dequeueOutputBuffer()
Dequeues the next output buffer from the decoder.
|
void |
flush()
Flushes the decoder.
|
void |
queueInputBuffer(I inputBuffer)
Queues an input buffer to the decoder.
|
void |
release()
Releases the decoder.
|
protected void |
releaseOutputBuffer(O outputBuffer)
Releases an output buffer back to the decoder.
|
protected void |
setInitialInputBufferSize(int size)
Sets the initial size of each input buffer.
|
protected final void setInitialInputBufferSize(int size)
This method should only be called before the decoder is used (i.e. before the first call to
dequeueInputBuffer()
.
size
- The required input buffer size.public final I dequeueInputBuffer() throws E extends Exception
Decoder
dequeueInputBuffer
in interface Decoder<I extends DecoderInputBuffer,O extends OutputBuffer,E extends Exception>
E
- If a decoder error has occurred.E extends Exception
public final void queueInputBuffer(I inputBuffer) throws E extends Exception
Decoder
queueInputBuffer
in interface Decoder<I extends DecoderInputBuffer,O extends OutputBuffer,E extends Exception>
inputBuffer
- The input buffer.E
- If a decoder error has occurred.E extends Exception
public final O dequeueOutputBuffer() throws E extends Exception
Decoder
dequeueOutputBuffer
in interface Decoder<I extends DecoderInputBuffer,O extends OutputBuffer,E extends Exception>
E
- If a decoder error has occurred.E extends Exception
protected void releaseOutputBuffer(O outputBuffer)
outputBuffer
- The output buffer being released.public final void flush()
Decoder
flush
in interface Decoder<I extends DecoderInputBuffer,O extends OutputBuffer,E extends Exception>
public void release()
Decoder
release
in interface Decoder<I extends DecoderInputBuffer,O extends OutputBuffer,E extends Exception>
protected abstract I createInputBuffer()
protected abstract O createOutputBuffer()
protected abstract E createUnexpectedDecodeException(Throwable error)
error
- The unexpected decode error.@Nullable protected abstract E decode(I inputBuffer, O outputBuffer, boolean reset)
inputBuffer
and stores any decoded output in outputBuffer
.inputBuffer
- The buffer to decode.outputBuffer
- The output buffer to store decoded data. The flag C.BUFFER_FLAG_DECODE_ONLY
will be set if the same flag is set on inputBuffer
, but
may be set/unset as required. If the flag is set when the call returns then the output
buffer will not be made available to dequeue. The output buffer may not have been populated
in this case.reset
- Whether the decoder must be reset before decoding.