FailOnCloseDataSink


@UnstableApi
class FailOnCloseDataSink : DataSink


A DataSink that can simulate caching the bytes being written to it, and then failing to persist them when close is called.

Summary

Nested types

Factory to create a FailOnCloseDataSink.

Public constructors

FailOnCloseDataSink(cache: Cache!, failOnClose: AtomicBoolean!)

Creates an instance.

Public functions

Unit

Closes the sink.

Unit
open(dataSpec: DataSpec!)

Opens the sink to consume the specified data.

Unit
write(buffer: ByteArray!, offset: Int, length: Int)

Consumes the provided data.

Public constructors

FailOnCloseDataSink

FailOnCloseDataSink(cache: Cache!, failOnClose: AtomicBoolean!)

Creates an instance.

Parameters
cache: Cache!

The cache to write to when not in fail-on-close mode.

failOnClose: AtomicBoolean!

An AtomicBoolean whose value is read in each call to open to determine whether to enable fail-on-close for the read that's being started.

Public functions

close

fun close(): Unit

Closes the sink.

Note: This method must be called even if the corresponding call to open threw an IOException. See open for more details.

Throws
java.io.IOException

If an error occurs closing the sink.

open

fun open(dataSpec: DataSpec!): Unit

Opens the sink to consume the specified data.

Note: If an IOException is thrown, callers must still call close to ensure that any partial effects of the invocation are cleaned up.

Parameters
dataSpec: DataSpec!

Defines the data to be consumed.

Throws
java.io.IOException

If an error occurs opening the sink.

write

fun write(buffer: ByteArray!, offset: Int, length: Int): Unit

Consumes the provided data.

Parameters
buffer: ByteArray!

The buffer from which data should be consumed.

offset: Int

The offset of the data to consume in buffer.

length: Int

The length of the data to consume, in bytes.

Throws
java.io.IOException

If an error occurs writing to the sink.