Pipe

class Pipe(maxBufferSize: Long)

A source and a sink that are attached. The sink's output is the source's input. Typically each is accessed by its own thread: a producer thread writes data to the sink and a consumer thread reads data from the source.

This class uses a buffer to decouple source and sink. This buffer has a user-specified maximum size. When a producer thread outruns its consumer the buffer fills up and eventually writes to the sink will block until the consumer has caught up. Symmetrically, if a consumer outruns its producer reads block until there is data to be read. Limits on the amount of time spent waiting for the other party can be configured with timeouts on the source and the sink.

When the sink is closed, source reads will continue to complete normally until the buffer has been exhausted. At that point reads will return -1, indicating the end of the stream. But if the source is closed first, writes to the sink will immediately fail with an IOException.

A pipe may be canceled to immediately fail writes to the sink and reads from the source.

Constructors

Pipe
Link copied to clipboard
fun Pipe(maxBufferSize: Long)

Functions

cancel
Link copied to clipboard
fun cancel()
Fail any in-flight and future operations.
equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
fold
Link copied to clipboard
fun fold(sink: Sink)
Writes any buffered contents of this pipe to sink, then replace this pipe's source with sink.
hashCode
Link copied to clipboard
open fun hashCode(): Int
toString
Link copied to clipboard
open fun toString(): String

Properties

sink
Link copied to clipboard
val sink: Sink
source
Link copied to clipboard
val source: Source