Interface DataSerializer<T>
- Type Parameters:
T- type of serialized data
- All Known Implementing Classes:
DataSerializer.NullableDataSerializer,DataSerializer.OptionalDataSerializer
public interface DataSerializer<T>
Serializer of arbitary data.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classData serializer for nullable types.static final classData serializer foroptionaltypes. -
Method Summary
Modifier and TypeMethodDescriptiondefault TfromByteArray(byte @NotNull [] byteArray) Reads the object from the given byte-array.default TfromByteArrayUnchecked(byte @NotNull [] byteArray) Reads the object from the given byte-array.default @NotNull DataSerializer<@Nullable T>nullable()Crates a data serializer based on this one which allows null values.default @NotNull DataSerializer<@NotNull Optional<T>>optional()Crates a data serializer based on this one which allowsoptionalvalues.read(@NotNull DataInputStream input) Reads the object from the given input stream.default TreadUnchecked(@NotNull DataInputStream input) Reads the object from the given input stream.default byte @NotNull []toByteArray(T object) Converts the given object into a byte-array.default byte @NotNull []toByteArray(T object, @org.jetbrains.annotations.Range(from=1L, to=2147483647L) int expectedSize) Converts the given object into a byte-array.default byte @NotNull []toByteArrayUnchecked(T object) Converts the given object into a byte-array.default byte @NotNull []toByteArrayUnchecked(T object, @org.jetbrains.annotations.Range(from=1L, to=2147483647L) int expectedSize) Converts the given object into a byte-array.voidwrite(@NotNull DataOutputStream output, T object) Writes the object into the given output stream.default voidwriteUnchecked(@NotNull DataOutputStream output, T object) Writes the object into the given output stream.
-
Method Details
-
write
Writes the object into the given output stream.- Parameters:
output- output in which the output should be writtenobject- object to be written into the output stream- Throws:
IOException- if an error happens while writing
-
writeUnchecked
Writes the object into the given output stream.- Parameters:
output- output in which the output should be writtenobject- object to be written into the output stream- Implementation note
- delegates to
write(DataOutputStream, Object) - Implementation specification
- should not be overridden
-
read
Reads the object from the given input stream.- Parameters:
input- input from which the object should be read- Returns:
- read object
- Throws:
IOException- if an error happens while reading
-
readUnchecked
Reads the object from the given input stream.- Parameters:
input- input from which the object should be read- Returns:
- read object
- Implementation note
- delegates to
read(DataInputStream) - Implementation specification
- should not be overridden
-
fromByteArray
Reads the object from the given byte-array.- Parameters:
byteArray- byte-array from which the object should be read- Returns:
- read object
- Throws:
IOException- if an error happens while reading- See Also:
- Implementation note
- default implementation simply creates a new
ByteArrayInputStreamwrapped inDataInputStreamand passes it toread(DataInputStream)
-
fromByteArrayUnchecked
Reads the object from the given byte-array.- Parameters:
byteArray- byte-array from which the object should be read- Returns:
- read object
- See Also:
- Implementation note
- default implementation simply creates a new
ByteArrayInputStreamwrapped inDataInputStreamand passes it toread(DataInputStream), delegates tofromByteArray(byte[]) - Implementation specification
- should not be overridden
-
toByteArray
default byte @NotNull [] toByteArray(T object, @org.jetbrains.annotations.Range(from=1L, to=2147483647L) int expectedSize) throws IOException Converts the given object into a byte-array.- Parameters:
object- object to be converted into a byte-arrayexpectedSize- expected size of the created byte-array- Returns:
- byte-array representation of the object
- Throws:
IOException- if an error happens while writing- See Also:
- API note
expectedSizeis not required to actually be exact, it is just used for possible optimizations- Implementation note
- default implementation simply creates a new
ByteArrayOutputStreamwrapped inDataOutputStreamand passes it towrite(DataOutputStream, Object)
-
toByteArray
Converts the given object into a byte-array.- Parameters:
object- object to be converted into a byte-array- Returns:
- byte-array representation of the object
- Throws:
IOException- if an error happens while writing- See Also:
- API note
- alternative implementations may simply call to
toByteArray(Object, int)with specific size - Implementation note
- default implementation simply creates a new
ByteArrayOutputStreamwrapped inDataOutputStreamand passes it towrite(DataOutputStream, Object)
-
toByteArrayUnchecked
default byte @NotNull [] toByteArrayUnchecked(T object, @org.jetbrains.annotations.Range(from=1L, to=2147483647L) int expectedSize) Converts the given object into a byte-array.- Parameters:
object- object to be converted into a byte-arrayexpectedSize- expected size of the created byte-array- Returns:
- byte-array representation of the object
- See Also:
- API note
expectedSizeis not required to actually be exact, it is just used for possible optimizations- Implementation note
- default implementation simply creates a new
ByteArrayOutputStreamwrapped inDataOutputStreamand passes it towrite(DataOutputStream, Object), delegates totoByteArray(Object, int) - Implementation specification
- should not be overridden
-
toByteArrayUnchecked
Converts the given object into a byte-array.- Parameters:
object- object to be converted into a byte-array- Returns:
- byte-array representation of the object
- See Also:
- API note
- alternative implementations may simply call to
toByteArray(Object, int)with specific size - Implementation note
- default implementation simply creates a new
ByteArrayOutputStreamwrapped inDataOutputStreamand passes it towrite(DataOutputStream, Object), delegates totoByteArray(Object) - Implementation specification
- should not be overridden
-
nullable
Crates a data serializer based on this one which allows null values.- Returns:
- null-friendly equivalent of this data serializer
- See Also:
-
optional
Crates a data serializer based on this one which allowsoptionalvalues.- Returns:
Optional-friendly equivalent of this data serializer- See Also:
-