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.FactoryFactory to create a |
Public constructors |
|---|
FailOnCloseDataSink(Cache cache, AtomicBoolean failOnClose)Creates an instance. |
Public methods |
|
|---|---|
void |
close()Closes the sink. |
void |
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 |
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 |
int length |
The length of the data to consume, in bytes. |
| Throws | |
|---|---|
java.io.IOException |
If an error occurs writing to the sink. |