public abstract class IntEncoder extends Object
OutputStream. Extending classes need to override
encode(int)to encode the value using their encoding algorithm. The default implementation of
close()closes the set
For convenience, each encoder implements
easy access to the matching decoder.
NOTE: some implementations may buffer the encoded values in memory
IntEncoderFilter implementations) and encoding will happen
only upon calling
close(). Therefore it is important to always call
close() on the encoder at hand.
NOTE: encoders are usually not thread safe, unless specifically documented otherwise by an implementation.
|Constructor and Description|
Default constructor, provided here for robustness: if in the future a constructor with parameters will be added, this might break custom implementations of this class which call this implicit constructor.
|Modifier and Type||Method and Description|
Instructs the encoder to finish the encoding process.
Encodes an integer to the output stream given in
Reinitializes the encoder with the give
protected OutputStream out
public void close() throws IOException
reInit. An implementation may do here additional cleanup required to complete the encoding, such as flushing internal buffers, etc.
encodeshould be made before first calling
NOTE: overriding classes should make sure they either call
super.close() or close the output stream themselves.
public abstract void encode(int value) throws IOException
public abstract IntDecoder createMatchingDecoder()
IntDecoderwhich matches this encoder. Every encoder must return an
nullis not a valid value. If an encoder is just a filter, it should at least return its wrapped encoder's matching decoder.
NOTE: this method should create a new instance of the matching decoder and leave the instance sharing to the caller. Returning the same instance over and over is risky because encoders and decoders are not thread safe.
public void reInit(OutputStream out)
OutputStream. For re-usability it can be changed without the need to reconstruct a new object.
NOTE: after calling
close(), one must call
this method even if the output stream itself hasn't changed. An example
case is that the output stream wraps a byte, and the output stream itself
is reset, but its instance hasn't changed. Some implementations of
IntEncoder may write some metadata about themselves to the output
stream, and therefore it is imperative that one calls this method before
encoding any data.