encodeBufferedAsync

@JvmStatic
inline suspend fun ByteArray.encodeBufferedAsync(encoder: Encoder<*>, throwOnOverflow: Boolean, noinline action: suspend (buf: CharArray, offset: Int, len: Int) -> Unit): Long(source)

Encode a ByteArray using a buffer of maximum size DEFAULT_BUFFER_SIZE.

The encoding operation will allocate a single buffer, streaming encoded characters to it and flushing to action when needed. If the pre-calculated size returned by EncoderDecoder.Config.encodeOutMaxSize is less than or equal to the DEFAULT_BUFFER_SIZE, then a buffer of that size will be allocated and action is only invoked once (single-shot encoding). In the event that EncoderDecoder.Config.encodeOutMaxSize throws its EncodingSizeException (i.e. encoding would exceed Int.MAX_VALUE) while throwOnOverflow is false, or its return value is greater than DEFAULT_BUFFER_SIZE, then this function will always stream encode to a buffer while flushing to action until the encoding operation has completed.

NOTE: Documented exceptions thrown by this function do not include those for which action may throw.

NOTE: The Encoder implementation must be compatible with version 2.6.0+ APIs and define a EncoderDecoder.Config.maxEncodeEmit. If the value is -1 (i.e. it has not updated to the new API yet), then this function will fail with an EncodingException. All implementations provided by this library have been updated to meet the API requirement; only EncoderDecoder implementations external to this library that have not updated yet may fail when using them with encodeBuffered and encodeBufferedAsync APIs.

Return

The number of encoded characters.

Parameters

encoder

The Encoder to use.

throwOnOverflow

If true and EncoderDecoder.Config.encodeOutMaxSize throws an EncodingSizeException, it will be re-thrown. If false, the exception is ignored and stream encoding to the buffer will continue.

action

The suspend function to flush the buffer to; a destination to "write" encoded data to whereby len is the number of characters within buf, starting at index offset, to "write".

See also

Throws

CancellationException

If the encoder is configured to reject something, such as UTF-8 byte to text transformations rejecting invalid byte sequences.

If EncoderDecoder.Config.encodeOutMaxSize threw its exception (i.e. output would exceed Int.MAX_VALUE) and throwOnOverflow is true.


@JvmStatic
inline suspend fun ByteArray.encodeBufferedAsync(encoder: Encoder<*>, throwOnOverflow: Boolean, offset: Int, len: Int, noinline action: suspend (buf: CharArray, offset: Int, len: Int) -> Unit): Long(source)

Encode len number of bytes from the array, starting at index offset, using a buffer of maximum size DEFAULT_BUFFER_SIZE.

The encoding operation will allocate a single buffer, streaming encoded characters to it and flushing to action when needed. If the pre-calculated size returned by EncoderDecoder.Config.encodeOutMaxSize is less than or equal to the DEFAULT_BUFFER_SIZE, then a buffer of that size will be allocated and action is only invoked once (single-shot encoding). In the event that EncoderDecoder.Config.encodeOutMaxSize throws its EncodingSizeException (i.e. encoding would exceed Int.MAX_VALUE) while throwOnOverflow is false, or its return value is greater than DEFAULT_BUFFER_SIZE, then this function will always stream encode to a buffer while flushing to action until the encoding operation has completed.

NOTE: Documented exceptions thrown by this function do not include those for which action may throw.

NOTE: The Encoder implementation must be compatible with version 2.6.0+ APIs and define a EncoderDecoder.Config.maxEncodeEmit. If the value is -1 (i.e. it has not updated to the new API yet), then this function will fail with an EncodingException. All implementations provided by this library have been updated to meet the API requirement; only EncoderDecoder implementations external to this library that have not updated yet may fail when using them with encodeBuffered and encodeBufferedAsync APIs.

Return

The number of encoded characters.

Parameters

encoder

The Encoder to use.

throwOnOverflow

If true and EncoderDecoder.Config.encodeOutMaxSize throws an EncodingSizeException, it will be re-thrown. If false, the exception is ignored and stream encoding to the buffer will continue.

offset

The index in the array to start at.

len

The number of bytes, starting at index offset.

action

The suspend function to flush the buffer to; a destination to "write" encoded data to whereby len is the number of characters within buf, starting at index offset, to "write".

See also

Throws

CancellationException

If the encoder is configured to reject something, such as UTF-8 byte to text transformations rejecting invalid byte sequences.

If EncoderDecoder.Config.encodeOutMaxSize threw its exception (i.e. output would exceed Int.MAX_VALUE) and throwOnOverflow is true.

IndexOutOfBoundsException

If offset or len are inappropriate.


@JvmStatic
suspend fun ByteArray.encodeBufferedAsync(encoder: Encoder<*>, throwOnOverflow: Boolean, maxBufSize: Int, action: suspend (buf: CharArray, offset: Int, len: Int) -> Unit): Long(source)

Encode a ByteArray using a buffer of maximum size maxBufSize.

The encoding operation will allocate a single buffer, streaming encoded characters to it and flushing to action when needed. If the pre-calculated size returned by EncoderDecoder.Config.encodeOutMaxSize is less than or equal to the maxBufSize, then a buffer of that size will be allocated and action is only invoked once (single-shot encoding). In the event that EncoderDecoder.Config.encodeOutMaxSize throws its EncodingSizeException (i.e. encoding would exceed Int.MAX_VALUE) while throwOnOverflow is false, or its return value is greater than maxBufSize, then this function will always stream encode to a buffer while flushing to action until the encoding operation has completed.

NOTE: Documented exceptions thrown by this function do not include those for which action may throw.

NOTE: The Encoder implementation must be compatible with version 2.6.0+ APIs and define a EncoderDecoder.Config.maxEncodeEmit. If the value is -1 (i.e. it has not updated to the new API yet), then this function will fail with an EncodingException. All implementations provided by this library have been updated to meet the API requirement; only EncoderDecoder implementations external to this library that have not updated yet may fail when using them with encodeBuffered and encodeBufferedAsync APIs.

Return

The number of encoded characters.

Parameters

encoder

The Encoder to use.

throwOnOverflow

If true and EncoderDecoder.Config.encodeOutMaxSize throws an EncodingSizeException, it will be re-thrown. If false, the exception is ignored and stream encoding to the buffer will continue.

maxBufSize

The maximum size buffer this function will allocate. Must be greater than EncoderDecoder.Config.maxEncodeEmitWithLineBreak.

action

The suspend function to flush the buffer to; a destination to "write" encoded data to whereby len is the number of characters within buf, starting at index offset, to "write".

See also

Throws

CancellationException

If the encoder is configured to reject something, such as UTF-8 byte to text transformations rejecting invalid byte sequences.

If EncoderDecoder.Config.encodeOutMaxSize threw its exception (i.e. output would exceed Int.MAX_VALUE) and throwOnOverflow is true.

IllegalArgumentException

@JvmStatic
suspend fun ByteArray.encodeBufferedAsync(encoder: Encoder<*>, throwOnOverflow: Boolean, offset: Int, len: Int, maxBufSize: Int, action: suspend (buf: CharArray, offset: Int, len: Int) -> Unit): Long(source)

Encode len number of bytes from the array, starting at index offset, using a buffer of maximum size maxBufSize.

The encoding operation will allocate a single buffer, streaming encoded characters to it and flushing to action when needed. If the pre-calculated size returned by EncoderDecoder.Config.encodeOutMaxSize is less than or equal to the maxBufSize, then a buffer of that size will be allocated and action is only invoked once (single-shot encoding). In the event that EncoderDecoder.Config.encodeOutMaxSize throws its EncodingSizeException (i.e. encoding would exceed Int.MAX_VALUE) while throwOnOverflow is false, or its return value is greater than maxBufSize, then this function will always stream encode to a buffer while flushing to action until the encoding operation has completed.

NOTE: Documented exceptions thrown by this function do not include those for which action may throw.

NOTE: The Encoder implementation must be compatible with version 2.6.0+ APIs and define a EncoderDecoder.Config.maxEncodeEmit. If the value is -1 (i.e. it has not updated to the new API yet), then this function will fail with an EncodingException. All implementations provided by this library have been updated to meet the API requirement; only EncoderDecoder implementations external to this library that have not updated yet may fail when using them with encodeBuffered and encodeBufferedAsync APIs.

Return

The number of encoded characters.

Parameters

encoder

The Encoder to use.

throwOnOverflow

If true and EncoderDecoder.Config.encodeOutMaxSize throws an EncodingSizeException, it will be re-thrown. If false, the exception is ignored and stream encoding to the buffer will continue.

offset

The index in the array to start at.

len

The number of bytes, starting at index offset.

maxBufSize

The maximum size buffer this function will allocate. Must be greater than EncoderDecoder.Config.maxEncodeEmitWithLineBreak.

action

The suspend function to flush the buffer to; a destination to "write" encoded data to whereby len is the number of characters within buf, starting at index offset, to "write".

See also

Throws

CancellationException

If the encoder is configured to reject something, such as UTF-8 byte to text transformations rejecting invalid byte sequences.

If EncoderDecoder.Config.encodeOutMaxSize threw its exception (i.e. output would exceed Int.MAX_VALUE) and throwOnOverflow is true.

IllegalArgumentException
IndexOutOfBoundsException

If offset or len are inappropriate.


@JvmStatic
suspend fun ByteArray.encodeBufferedAsync(encoder: Encoder<*>, throwOnOverflow: Boolean, buf: CharArray, action: suspend (buf: CharArray, offset: Int, len: Int) -> Unit): Long(source)

Encode a ByteArray using the provided pre-allocated, reusable, buf array.

The encoding operation will stream encoded characters to the provided buf, flushing to action when needed. If the pre-calculated size returned by EncoderDecoder.Config.encodeOutMaxSize is less than or equal to the buf size, then action is only invoked once (single-shot encoding). In the event that EncoderDecoder.Config.encodeOutMaxSize throws its EncodingSizeException (i.e. encoding would exceed Int.MAX_VALUE) while throwOnOverflow is false, or its return value is greater than buf size, then this function will always stream encode to a buffer while flushing to action until the encoding operation has completed.

NOTE: Documented exceptions thrown by this function do not include those for which action may throw.

NOTE: If EncoderDecoder.Config.backFillBuffers is true, provided buf array will be back-filled with null character \u0000 upon encoding completion.

NOTE: The Encoder implementation must be compatible with version 2.6.0+ APIs and define a EncoderDecoder.Config.maxEncodeEmit. If the value is -1 (i.e. it has not updated to the new API yet), then this function will fail with an EncodingException. All implementations provided by this library have been updated to meet the API requirement; only EncoderDecoder implementations external to this library that have not updated yet may fail when using them with encodeBuffered and encodeBufferedAsync APIs.

Return

The number of encoded characters.

Parameters

encoder

The Encoder to use.

throwOnOverflow

If true and EncoderDecoder.Config.encodeOutMaxSize throws an EncodingSizeException, it will be re-thrown. If false, the exception is ignored and stream encoding to the buffer will continue.

buf

The pre-allocated array to use as the buffer. Its size must be greater than EncoderDecoder.Config.maxEncodeEmitWithLineBreak.

action

The suspend function to flush the buffer to; a destination to "write" encoded data to whereby len is the number of characters within buf, starting at index offset, to "write".

See also

Throws

CancellationException

If the encoder is configured to reject something, such as UTF-8 byte to text transformations rejecting invalid byte sequences.

If EncoderDecoder.Config.encodeOutMaxSize threw its exception (i.e. output would exceed Int.MAX_VALUE) and throwOnOverflow is true.

IllegalArgumentException

If buf size is less than or equal to EncoderDecoder.Config.maxEncodeEmitWithLineBreak.


@JvmStatic
suspend fun ByteArray.encodeBufferedAsync(encoder: Encoder<*>, throwOnOverflow: Boolean, offset: Int, len: Int, buf: CharArray, action: suspend (buf: CharArray, offset: Int, len: Int) -> Unit): Long(source)

Encode len number of bytes from the array, starting at index offset, using the provided pre-allocated, reusable, buf array.

The encoding operation will stream encoded characters to the provided buf, flushing to action when needed. If the pre-calculated size returned by EncoderDecoder.Config.encodeOutMaxSize is less than or equal to the buf size, then action is only invoked once (single-shot encoding). In the event that EncoderDecoder.Config.encodeOutMaxSize throws its EncodingSizeException (i.e. encoding would exceed Int.MAX_VALUE) while throwOnOverflow is false, or its return value is greater than buf size, then this function will always stream encode to a buffer while flushing to action until the encoding operation has completed.

NOTE: Documented exceptions thrown by this function do not include those for which action may throw.

NOTE: If EncoderDecoder.Config.backFillBuffers is true, provided buf array will be back-filled with null character \u0000 upon encoding completion.

NOTE: The Encoder implementation must be compatible with version 2.6.0+ APIs and define a EncoderDecoder.Config.maxEncodeEmit. If the value is -1 (i.e. it has not updated to the new API yet), then this function will fail with an EncodingException. All implementations provided by this library have been updated to meet the API requirement; only EncoderDecoder implementations external to this library that have not updated yet may fail when using them with encodeBuffered and encodeBufferedAsync APIs.

Return

The number of encoded characters.

Parameters

encoder

The Encoder to use.

throwOnOverflow

If true and EncoderDecoder.Config.encodeOutMaxSize throws an EncodingSizeException, it will be re-thrown. If false, the exception is ignored and stream encoding to the buffer will continue.

offset

The index in the array to start at.

len

The number of bytes, starting at index offset.

buf

The pre-allocated array to use as the buffer. Its size must be greater than EncoderDecoder.Config.maxEncodeEmitWithLineBreak.

action

The suspend function to flush the buffer to; a destination to "write" encoded data to whereby len is the number of characters within buf, starting at index offset, to "write".

See also

Throws

CancellationException

If the encoder is configured to reject something, such as UTF-8 byte to text transformations rejecting invalid byte sequences.

If EncoderDecoder.Config.encodeOutMaxSize threw its exception (i.e. output would exceed Int.MAX_VALUE) and throwOnOverflow is true.

IllegalArgumentException

If buf size is less than or equal to EncoderDecoder.Config.maxEncodeEmitWithLineBreak.

IndexOutOfBoundsException

If offset or len are inappropriate.