public interface RevisionDataOutput
extends java.io.DataOutput
| Modifier and Type | Interface and Description |
|---|---|
static interface |
RevisionDataOutput.ElementSerializer<T>
Defines a Function signature that can serialize an element to a RevisionDataOutput.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
COMPACT_INT_MAX
Maximum value that can be encoded using writeCompactInt().
|
static int |
COMPACT_INT_MIN
Minimum value that can be encoded using writeCompactInt().
|
static long |
COMPACT_LONG_MAX
Maximum value that can be encoded using writeCompactLong().
|
static long |
COMPACT_LONG_MIN
Minimum value that can be encoded using writeCompactLong().
|
static int |
UUID_BYTES
The number of bytes required to encode a UUID.
|
| Modifier and Type | Method and Description |
|---|---|
java.io.OutputStream |
getBaseStream()
Gets a pointer to the OutputStream that this RevisionDataOutput writes to.
|
<T> int |
getCollectionLength(java.util.Collection<T> collection,
java.util.function.ToIntFunction<T> elementLengthProvider)
Calculates the number of bytes required to serialize a Collection.
|
int |
getCollectionLength(int elementCount,
int elementLength)
Calculates the number of bytes required to serialize a Collection or array.
|
<T> int |
getCollectionLength(T[] array,
java.util.function.ToIntFunction<T> elementLengthProvider)
Calculates the number of bytes required to serialize an array.
|
int |
getCompactIntLength(int value)
Calculates the length, in bytes, of the given Integer as serialized by using writeCompactInt().
|
int |
getCompactLongLength(long value)
Calculates the length, in bytes, of the given Long as serialized by using writeCompactLong().
|
int |
getMapLength(int elementCount,
int keyLength,
int valueLength)
Calculates the number of bytes required to serialize a Map.
|
<K,V> int |
getMapLength(java.util.Map<K,V> map,
java.util.function.ToIntFunction<K> keyLengthProvider,
java.util.function.ToIntFunction<V> valueLengthProvider)
Calculates the number of bytes required to serialize a Map.
|
int |
getUTFLength(java.lang.String s)
Calculates the length, in bytes, of the given String as serialized by using writeUTF().
|
void |
length(int length)
If requiresExplicitLength() == true, this method will write 4 bytes at the current position representing the expected
serialization length (via the argument).
|
boolean |
requiresExplicitLength()
Gets a value indicating whether this instance of a RevisionDataOutput requires length() to be called prior to writing
anything to it.
|
default void |
writeArray(byte[] array)
Serializes the given byte array.
|
void |
writeArray(byte[] array,
int offset,
int length)
Serializes the given byte array.
|
default void |
writeArray(ByteArraySegment segment)
Serializes the given byte array segment.
|
<T> void |
writeArray(T[] array,
RevisionDataOutput.ElementSerializer<T> elementSerializer)
Serializes the given array using the given ElementSerializer.
|
<T> void |
writeCollection(java.util.Collection<T> collection,
RevisionDataOutput.ElementSerializer<T> elementSerializer)
Serializes the given Collection using the given ElementSerializer.
|
void |
writeCompactInt(int value)
Encodes the given Integer into a compact serialization of 1, 2, 3 or 4 bytes.
|
void |
writeCompactLong(long value)
Encodes the given Long into a compact serialization of 1, 2, 4 or 8 bytes.
|
<K,V> void |
writeMap(java.util.Map<K,V> map,
RevisionDataOutput.ElementSerializer<K> keySerializer,
RevisionDataOutput.ElementSerializer<V> valueSerializer)
Serializes the given Map using the given ElementSerializers (one for Key and one for Value).
|
void |
writeUUID(java.util.UUID uuid)
Serializes the given UUID as two consecutive Long values.
|
static final long COMPACT_LONG_MAX
static final long COMPACT_LONG_MIN
static final int COMPACT_INT_MAX
static final int COMPACT_INT_MIN
static final int UUID_BYTES
boolean requiresExplicitLength()
void length(int length)
throws java.io.IOException
length - The length to declare.java.io.IOException - If an IO Exception occurred.java.io.OutputStream getBaseStream()
int getUTFLength(java.lang.String s)
s - The string to measure.int getCompactLongLength(long value)
value - The value to measure.java.lang.IllegalArgumentException - If value is negative or greater than 2^62-1.void writeCompactLong(long value)
throws java.io.IOException
This value must be read using RevisionDataInput.readCompactLong(). It cannot be read using DataInput.readLong().
value - The value to serialize.java.io.IOException - If an IO Exception occurred.java.lang.IllegalArgumentException - If value is negative or greater than 2^62-1.int getCompactIntLength(int value)
value - The value to measure.java.lang.IllegalArgumentException - If value is negative or greater than 2^30-1.void writeCompactInt(int value)
throws java.io.IOException
This value must be read using RevisionDataInput.readCompactInt(). It cannot be read using DataInput.readInt().
value - The value to serialize.java.io.IOException - If an IO Exception occurred.java.lang.IllegalArgumentException - If value is negative or greater than 2^60-1.void writeUUID(java.util.UUID uuid)
throws java.io.IOException
This value must be read using RevisionDataInput.readUUID().
uuid - The UUID to serialize.java.io.IOException - If an IO Exception occurred.int getCollectionLength(int elementCount,
int elementLength)
elementCount - The size of the collection.elementLength - The size (in bytes) of each element's serialization.<T> int getCollectionLength(java.util.Collection<T> collection,
java.util.function.ToIntFunction<T> elementLengthProvider)
T - Type of the Collection's Elements.collection - The Collection to measure.elementLengthProvider - A Function that, given an Element of type T, will return its serialization length.<T> int getCollectionLength(T[] array,
java.util.function.ToIntFunction<T> elementLengthProvider)
T - Type of the Array's Elementsarray - The array to measure.elementLengthProvider - A Function that, given an Element of type T, will return its serialization length.<T> void writeCollection(java.util.Collection<T> collection,
RevisionDataOutput.ElementSerializer<T> elementSerializer)
throws java.io.IOException
T - Type of the elements in the Collection.collection - The Collection to serialize. Can be null (in which case an Empty Collection will be deserialized
by RevisionDataInput.readCollection()).elementSerializer - A Function that serializes a single element of the collection to a RevisionDataOutput.java.io.IOException - If an IO Exception occurred.<T> void writeArray(T[] array,
RevisionDataOutput.ElementSerializer<T> elementSerializer)
throws java.io.IOException
T - Type of the elements in the array.array - The array to serialize. Can be null (in which case an Empty array will be deserialized
by RevisionDataInput.readArray()).elementSerializer - A Function that serializes a single element of the array to a RevisionDataOutput.java.io.IOException - If an IO Exception occurred.default void writeArray(byte[] array)
throws java.io.IOException
array - The array to serialize. Can be null (in which case an Empty array will be deserialized
by RevisionDataInput.readArray()).java.io.IOException - If an IO Exception occurred.default void writeArray(ByteArraySegment segment) throws java.io.IOException
segment - The byte array segment to serialize. Can be null (in which case an Empty array will be deserialized
by RevisionDataInput.readArray()).java.io.IOException - If an IO Exception occurred.void writeArray(byte[] array,
int offset,
int length)
throws java.io.IOException
array - The array to serialize. Can be null (in which case an Empty array will be deserialized
by RevisionDataInput.readArray()).offset - The offset within the array to begin serializing at. This is ignored if array == null.length - The number of elements to serialize. This is ignored if array == null.java.io.IOException - If an IO Exception occurred.int getMapLength(int elementCount,
int keyLength,
int valueLength)
elementCount - The size of the Map.keyLength - The size (in bytes) of each key's serialization.valueLength - The size (in bytes) of each value's serialization.<K,V> int getMapLength(java.util.Map<K,V> map,
java.util.function.ToIntFunction<K> keyLengthProvider,
java.util.function.ToIntFunction<V> valueLengthProvider)
K - Type of the Map's Keys.V - Type of the Map's Values.map - The Map to measure.keyLengthProvider - A Function that, given a Key of type K, will return its serialization length.valueLengthProvider - A Function that, given a Value of type V, will return its serialization length.<K,V> void writeMap(java.util.Map<K,V> map,
RevisionDataOutput.ElementSerializer<K> keySerializer,
RevisionDataOutput.ElementSerializer<V> valueSerializer)
throws java.io.IOException
K - Type of the Map's Keys.V - Type of the Map's Values.map - The Map to serialize. Can be null (in which case an Empty Map will be deserialized
by RevisionDataInput.readMap()).keySerializer - A Function that serializes a single Key of the Map to a RevisionDataOutput.valueSerializer - A Function that serializes a single Value of the Map to a RevisionDataOutput.java.io.IOException - If an IO Exception occurred.