FailOnCloseDataSink


@UnstableApi
public final class FailOnCloseDataSink implements 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

public final class FailOnCloseDataSink.Factory implements DataSink.Factory

Factory to create a FailOnCloseDataSink.

Public constructors

FailOnCloseDataSink(Cache cache, AtomicBoolean failOnClose)

Creates an instance.

Public methods

void

Closes the sink.

void
open(DataSpec dataSpec)

Opens the sink to consume the specified data.

void
write(byte[] buffer, int offset, int length)

Consumes the provided data.

Public constructors

FailOnCloseDataSink

public FailOnCloseDataSink(Cache cache, AtomicBoolean failOnClose)

Creates an instance.

Parameters
Cache cache

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

AtomicBoolean failOnClose

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 methods

close

public void close()

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

public void open(DataSpec dataSpec)

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

public void write(byte[] buffer, int offset, int length)

Consumes the provided data.

Parameters
byte[] buffer

The buffer from which data should be consumed.

int offset

The offset of the data to consume in buffer.

int length

The length of the data to consume, in bytes.

Throws
java.io.IOException

If an error occurs writing to the sink.