IN
- The type of Buffer
being read from.OUT
- The type of Buffer
being written to.T
- The concrete type that is extending this class.
Used to provide automatic covariant return types for
config(ICoder)
, clone()
, and reset()
.public abstract class BaseCoder<IN extends Buffer,OUT extends Buffer,T extends BaseCoder<IN,OUT,T>> extends Object implements ICoder<IN,OUT>
Modifier and Type | Field and Description |
---|---|
protected float |
averageOutPerIn |
protected float |
maxOutPerIn |
protected float |
minInPerOut |
protected CodingStates |
state |
Modifier | Constructor and Description |
---|---|
protected |
BaseCoder(float minInPerOut,
float averageOutPerIn,
float maxOutPerIn) |
Modifier and Type | Method and Description |
---|---|
protected abstract OUT |
allocate(int capacity) |
protected void |
checkConfigAllowed() |
protected <TA> TA |
checkNullArgument(TA o) |
T |
clone()
Another means for obtaining a configured instance copy from another.
|
OUT |
code(IN in)
|
CoderResult |
code(IN in,
OUT out,
boolean endOfInput)
Encodes as many units as possible from the given input buffer,
writing the results to the given output buffer.
|
protected abstract CoderResult |
codingLoop(IN in,
OUT out,
boolean endOfInput) |
T |
config(ICoder<IN,OUT> base)
Configures this instances based upon another.
|
protected void |
configImpl(T base)
Hook for implementations to configure themselves from another instance.
|
CoderResult |
flush(OUT out)
Writes any final output after the entire input has been processed.
|
float |
getAverageOutPerIn()
Heuristic value of the average number of output units generated per input unit.
|
float |
getMaxOutPerIn()
Heuristic value of the maximum number of output units generated per input unit.
|
float |
getMinInPerOut()
Heuristic value of the minimum number of input units required to produce
one or more output units.
|
protected CoderResult |
implFlush(OUT out) |
protected void |
init()
Hook called once after the first coding operation is started.
|
protected abstract OUT |
put(OUT base,
OUT put) |
T |
reset()
Resets the coder, allowing it to be reused against new input and output,
while keeping the same configuration.
|
protected void |
resetImpl()
Hook called from
reset() . |
protected void |
throwIllegalStateException(CodingStates from,
CodingStates to) |
protected float minInPerOut
protected float averageOutPerIn
protected float maxOutPerIn
protected transient CodingStates state
protected BaseCoder(float minInPerOut, float averageOutPerIn, float maxOutPerIn)
public T config(ICoder<IN,OUT> base)
ICoder
Configures this instances based upon another.
The passed-in parameter must be an instance of the current implementation,
or an IllegalArgumentException
will be thrown.
protected void configImpl(T base)
Hook for implementations to configure themselves from another instance. The base implementation does nothing.
base
- The instance to copy the configuration from.public T clone() throws CloneNotSupportedException
ICoder
Another means for obtaining a configured instance copy from another.
Typically utilizes ICoder.config(ICoder)
.
protected void init()
Hook called once after the first coding operation is started. The base implementation does nothing.
protected <TA> TA checkNullArgument(TA o)
public float getMinInPerOut()
ICoder
Heuristic value of the minimum number of input units required to produce one or more output units.
Similar to ICoder.getAverageOutPerIn()
and ICoder.getMaxOutPerIn()
.
public float getAverageOutPerIn()
ICoder
Heuristic value of the average number of output units generated per input unit.
Similar to CharsetEncoder.averageBytesPerChar()
and CharsetDecoder.averageCharsPerByte()
.
public float getMaxOutPerIn()
ICoder
Heuristic value of the maximum number of output units generated per input unit.
Similar to CharsetEncoder.maxBytesPerChar()
and CharsetDecoder.maxCharsPerByte()
.
public T reset()
ICoder
Resets the coder, allowing it to be reused against new input and output, while keeping the same configuration.
protected void resetImpl()
Hook called from reset()
.
The base implementation does nothing.
public OUT code(IN in) throws CharacterCodingException
ICoder
Convenience method that encodes the passed-in input Buffer
to a
returned output Buffer
.
Functions similar to
CharsetEncoder.encode(java.nio.CharBuffer)
and
CharsetDecoder.decode(java.nio.ByteBuffer)
.
protected abstract OUT allocate(int capacity)
public CoderResult code(IN in, OUT out, boolean endOfInput)
ICoder
Encodes as many units as possible from the given input buffer, writing the results to the given output buffer.
Functions similar to
CharsetEncoder.encode(java.nio.CharBuffer, java.nio.ByteBuffer, boolean)
and
CharsetDecoder.decode(java.nio.ByteBuffer, java.nio.CharBuffer, boolean)
.
protected abstract CoderResult codingLoop(IN in, OUT out, boolean endOfInput)
public CoderResult flush(OUT out)
ICoder
Writes any final output after the entire input has been processed.
Should be called after ICoder.code(Buffer, Buffer, boolean)
is
called for the final time.
Functions similar to
CharsetEncoder.flush(java.nio.ByteBuffer)
and
CharsetDecoder.flush(java.nio.CharBuffer)
.
protected CoderResult implFlush(OUT out)
protected void checkConfigAllowed()
protected void throwIllegalStateException(CodingStates from, CodingStates to)
Copyright © 2009–2017 Mark A. Ziesemer. All rights reserved.