PreferencesFileSerializer


public static class PreferencesFileSerializer implements Serializer


Proto based serializer for Preferences. Can be used to manually create DataStore using the DataStoreFactory#create function.

Summary

Public methods

@NonNull Preferences

Value to return if there is no data on disk.

@NonNull Preferences

Unmarshal object from stream.

void

Marshal object to a stream.

Public fields

INSTANCE

Added in 1.2.0-alpha01
public static @NonNull PreferencesFileSerializer INSTANCE

Public methods

getDefaultValue

Added in 1.2.0-alpha01
public @NonNull Preferences getDefaultValue()

Value to return if there is no data on disk.

readFrom

public @NonNull Preferences 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 input is corrupted and/or unparseable, e.g. InvalidProtocolBufferException when the type T is a protobuf message and it is corrupted. Other unrecoverable IOException from the file system should not be thrown as CorruptionException.

writeTo

Added in 1.2.0-alpha01
public void writeTo(@NonNull Preferences t, @NonNull OutputStream output)

Marshal object to a stream. Closing the provided OutputStream is a no-op.

Parameters
@NonNull Preferences t

the data to write to output

@NonNull OutputStream output

the OutputStream to serialize data to