ByteStream

sealed class ByteStream

Represents an abstract read-only stream of bytes

Inheritors

Types

Link copied to clipboard
abstract class Buffer : ByteStream

Variant of a ByteStream with payload represented as an in-memory byte buffer.

Link copied to clipboard
abstract class ChannelStream : ByteStream

Variant of a ByteStream with a streaming payload read from an SdkByteReadChannel

Link copied to clipboard
object Companion
Link copied to clipboard
abstract class SourceStream : ByteStream

Variant of a ByteStream with a streaming payload read from an SdkSource

Properties

Link copied to clipboard
open val contentLength: Long? = null

The content length if known

Link copied to clipboard
open val isOneShot: Boolean = true

Flag indicating if the body can only be consumed once. If false the underlying stream must be capable of being replayed.

Inherited functions

Link copied to clipboard
suspend fun ByteStream.appendToOutputStream(outputStream: OutputStream): Long

Writes this stream to the given OutputStream. This method does not flush or close the given OutputStream.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Consume the ByteStream and pull the entire contents into memory as a ByteArray. Only do this if you are sure the contents fit in-memory as this will read the entire contents of a streaming variant.

Link copied to clipboard
fun ByteStream.toFlow(bufferSize: Long = 8192): Flow<ByteArray>

Return a Flow that consumes the underlying ByteStream when collected.

Link copied to clipboard

Create a blocking InputStream that reads from the underlying ByteStream.

Link copied to clipboard
suspend fun ByteStream.writeToFile(file: File): Long

Write the contents of this ByteStream to file and close it

suspend fun ByteStream.writeToFile(path: Path): Long

Write the contents of this ByteStream to file at the given path

Link copied to clipboard
suspend fun ByteStream.writeToOutputStream(outputStream: OutputStream): Long

Writes this stream to the given OutputStream, then closes it.