Feed

sealed class Feed<C : EncoderDecoder.Config>(val config: C)(source)

The base abstraction for Decoder.Feed and Encoder.Feed.

Feeds are meant to be single use disposables for the given encoding/decoding operation.

TLDR; Feeds only care about Bytes and Chars, not the medium for which they come from or are going to. Use the use extension function.

Their primary use case is for breaking the process of encoding and decoding into their individual parts. This allows for input and output type transformations to occur at the call site, instead of within the encoding/decoding process.

After a Feed consumes all the data you have for it via Decoder.Feed.consume/Encoder.Feed.consume, call doFinal to complete the encoding/decoding operation.

Alternatively, utilize the use extension function (highly recommended) which will call doFinal (or close if there was an error with the operation) for you.

If encoding/decoding multiple chunks of data (e.g. encoding 2 ByteArrays and concatenating them with a separator character), you can call flush between chunks to perform final operations on that chunk without closing the Feed.

See also

Inheritors

Constructors

Link copied to clipboard
protected constructor(config: C)

Properties

Link copied to clipboard
val config: C

Functions

Link copied to clipboard
abstract fun close()

Closes the feed rendering it useless.

Link copied to clipboard
fun doFinal()

closes the Decoder.Feed/Encoder.Feed and finalizes the encoding/decoding, such as applying padding (encoding), or processing remaining data in its buffer before dumping them to Decoder.OutFeed/Encoder.OutFeed.

Link copied to clipboard
protected abstract fun doFinalProtected()

Implementations should perform final operations on their buffered input, AND reset any stateful variables they may have. This is called by both flush and doFinal.

Link copied to clipboard
abstract fun flush()

Flushes any buffered input of the Feed without closing it, performing final encoding/decoding operations for that chunk of data.

Link copied to clipboard
abstract fun isClosed(): Boolean