ByteArrayDataSink


@UnstableApi
public final class ByteArrayDataSink implements DataSink


A DataSink for writing to a byte array.

Summary

Public constructors

Public methods

void

Closes the sink.

@Nullable byte[]

Returns the data written to the sink since the last call to open, or null if open has never been called.

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

ByteArrayDataSink

public ByteArrayDataSink()

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.

getData

public @Nullable byte[] getData()

Returns the data written to the sink since the last call to open, or null if open has never been called.

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.