public interface ByteSink
Sink for writing bytes (and other data types). This is an interface that can be implemented by any class that can accept data and write it to some kind of channel, regardless of how the data is actually written. It allows for writing a block of heterogeneous data in a single "transaction", meaning that either the complete block of data is written, or none of it is written.
If data is written outside of an explicit transaction, each put operation is considered as an individual implicit transaction. If the put operation fails, no data will have been written, if it succeeds, all data will have been written.
Please note that there is no absolute guarantee about all data being written: Even if a put operation has been successful, the data might not be written completely due to circumstances outside the control of the byte sink. Please refer to the documentation of the individual-byte sink implementation in order to find out which guarantees it makes to ensure atomic write. In general, an implementation should make its best effort to ensure the atomicity of write operations.
This interface can be used in a similar way as a ByteBuffer
, however,
it is more flexible, because it does not have to be backed by a single
object.
In general, objects implementing this interface should be considered not thread-safe and if multiple threads access them, the access must be synchronized.
Modifier and Type | Interface and Description |
---|---|
static interface |
ByteSink.AtomicPutOperation<T>
Interface for use with the
atomicPut(AtomicPutOperation)
method. |
Modifier and Type | Method and Description |
---|---|
<T> T |
atomicPut(ByteSink.AtomicPutOperation<? extends T> atomicPutOperation)
Starts an atomic put operation.
|
ByteSink |
putByte(byte b)
Writes a single byte to this byte sink.
|
ByteSink |
putByteArray(byte[] source)
Writes a complete array of bytes to this byte sink.
|
ByteSink |
putByteArray(byte[] source,
int offset,
int length)
Writes a slice of an array of bytes to this byte sink.
|
ByteSink |
putDouble(double value)
Writes a single double value to this byte sink.
|
ByteSink |
putDoubleArray(double[] source)
Writes a complete array of double values to this byte sink.
|
ByteSink |
putDoubleArray(double[] source,
int offset,
int length)
Writes a slice of an array of double values to this byte sink.
|
ByteSink |
putFloat(float value)
Writes a single float value to this byte sink.
|
ByteSink |
putFloatArray(float[] source)
Writes a complete array of float values to this byte sink.
|
ByteSink |
putFloatArray(float[] source,
int offset,
int length)
Writes a slice of an array of float values to this byte sink.
|
ByteSink |
putInt(int value)
Writes a single int value to this byte sink.
|
ByteSink |
putIntArray(int[] source)
Writes a complete array of int values to this byte sink.
|
ByteSink |
putIntArray(int[] source,
int offset,
int length)
Writes a slice of an array of int values to this byte sink.
|
ByteSink |
putLong(long value)
Writes a single long value to this byte sink.
|
ByteSink |
putLongArray(long[] source)
Writes a complete array of long values to this byte sink.
|
ByteSink |
putLongArray(long[] source,
int offset,
int length)
Writes a slice of an array of long values to this byte sink.
|
ByteSink |
putShort(short value)
Writes a single short value to this byte sink.
|
ByteSink |
putShortArray(short[] source)
Writes a complete array of short values to this byte sink.
|
ByteSink |
putShortArray(short[] source,
int offset,
int length)
Writes a slice of an array of short values to this byte sink.
|
<T> T atomicPut(ByteSink.AtomicPutOperation<? extends T> atomicPutOperation)
ByteSink.AtomicPutOperation.put()
method of atomicPutOperation
throws an exception) all data
written within the transaction is discarded. This method will throw any
exception thrown by ByteSink.AtomicPutOperation.put()
. Atomic put
operations may be nested (see ByteSink.AtomicPutOperation.put()
for
details). Despite its name, this method should not be considered to be
thread-safe.T
- type of the return value of the atomic operation.atomicPutOperation
- put operation that shall be performed atomically.ByteSink.AtomicPutOperation.put()
.ByteSink putByte(byte b)
b
- byte to be written.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.ByteSink putByteArray(byte[] source)
source
- array of bytes that should be completely written to this byte
sink.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.ByteSink putByteArray(byte[] source, int offset, int length)
source
- array of bytes that should be partially written to this byte
sink.offset
- offset into source
. Data will be read from the
array starting at this index.length
- number of bytes to be written.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.IndexOutOfBoundsException
- if offset + length
is greater than
src.length
. No data is written to this byte
sink.ByteSink putDouble(double value)
value
- value to be written.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.ByteSink putDoubleArray(double[] source)
source
- array of double values that should be completely written to
this byte sink.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.ByteSink putDoubleArray(double[] source, int offset, int length)
source
- array of double values that should be partially written to
this byte sink.offset
- offset into source
. Data will be read from the
array starting at this index.length
- number of values to be written.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.IndexOutOfBoundsException
- if offset + length
is greater than
src.length
. No data is written to this byte
sink.ByteSink putFloat(float value)
value
- value to be written.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.ByteSink putFloatArray(float[] source)
source
- array of float values that should be completely written to
this byte sink.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.ByteSink putFloatArray(float[] source, int offset, int length)
source
- array of float values that should be partially written to this
byte sink.offset
- offset into source
. Data will be read from the
array starting at this index.length
- number of values to be written.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.IndexOutOfBoundsException
- if offset + length
is greater than
src.length
. No data is written to this byte
sink.ByteSink putInt(int value)
value
- value to be written.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.ByteSink putIntArray(int[] source)
source
- array of int values that should be completely written to this
byte sink.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.ByteSink putIntArray(int[] source, int offset, int length)
source
- array of int values that should be partially written to this
byte sink.offset
- offset into source
. Data will be read from the
array starting at this index.length
- number of values to be written.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.IndexOutOfBoundsException
- if offset + length
is greater than
src.length
. No data is written to this byte
sink.ByteSink putShort(short value)
value
- value to be written.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.ByteSink putShortArray(short[] source)
source
- array of short values that should be completely written to
this byte sink.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.ByteSink putShortArray(short[] source, int offset, int length)
source
- array of short values that should be partially written to this
byte sink.offset
- offset into source
. Data will be read from the
array starting at this index.length
- number of values to be written.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.IndexOutOfBoundsException
- if offset + length
is greater than
src.length
. No data is written to this byte
sink.ByteSink putLong(long value)
value
- value to be written.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.ByteSink putLongArray(long[] source)
source
- array of long values that should be completely written to this
byte sink.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.ByteSink putLongArray(long[] source, int offset, int length)
source
- array of long values that should be partially written to this
byte sink.offset
- offset into source
. Data will be read from the
array starting at this index.length
- number of values to be written.BufferOverflowException
- if there is not enough remaining space in the byte sink. No
data is written to this byte sink.IllegalArgumentException
- if trying to write more than Integer.MAX_VALUE
bytes
within a single transaction. No data is written to this byte
sink.IndexOutOfBoundsException
- if offset + length
is greater than
src.length
. No data is written to this byte
sink.Copyright © 2014–2016 aquenos GmbH. All rights reserved.