Serializer
public interface Serializer<T extends Object>
PreferencesFileSerializer |
Proto based serializer for Preferences. |
The serializer determines the on-disk format and API for accessing it.
The type T MUST be immutable. Mutable types will result in broken DataStore functionality.
TODO(b/151635324): consider changing InputStream to File.
Summary
Public methods |
|
|---|---|
abstract @NonNull T |
Value to return if there is no data on disk. |
abstract @NonNull T |
readFrom(@NonNull InputStream input)Unmarshal object from stream. |
abstract void |
writeTo(@NonNull T t, @NonNull OutputStream output)Marshal object to a stream. |
Public methods
getDefaultValue
abstract @NonNull T getDefaultValue()
Value to return if there is no data on disk.
readFrom
abstract @NonNull T readFrom(@NonNull InputStream input)
Unmarshal object from stream.
| Parameters | |
|---|---|
@NonNull InputStream input |
the InputStream with the data to deserialize |
| Throws | |
|---|---|
androidx.datastore.core.CorruptionException |
if the data from |
writeTo
abstract void writeTo(@NonNull T t, @NonNull OutputStream output)
Marshal object to a stream. Closing the provided OutputStream is a no-op.
| Parameters | |
|---|---|
@NonNull T t |
the data to write to output |
@NonNull OutputStream output |
the OutputStream to serialize data to |