java.lang.Object
java.util.prefs.Preferences
java.util.prefs.AbstractPreferences
is.codion.common.model.preferences.FilePreferences
A file-based preferences implementation without length restrictions.
Supports hierarchical preferences through nested JSON structure.
Clearing the preferences instance and flushing deletes the underlying file.
Note that, unlike the AbstractPreferences contract, PreferenceChangeListeners
are not notified of put(String, String) calls.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PropertyValue<String> Provides a way to override the default (OS dependent) directory used to store the user preferences file.static final PropertyValue<Boolean> Specifies whether JSON preference files are pretty-printed, causes significant size increase.Fields inherited from class java.util.prefs.AbstractPreferences
lock, newNodeFields inherited from class java.util.prefs.Preferences
MAX_KEY_LENGTH, MAX_NAME_LENGTH, MAX_VALUE_LENGTH -
Method Summary
Modifier and TypeMethodDescriptionvoidCopies the backing file to a sibling with the given suffix appended to the filename.protected String[]protected AbstractPreferencesstatic PreferencesfilePreferences(String filename) voidflush()Saves the changes made since the last flush or sync, once for the whole tree, re-applied on top of the file if it has been modified externally in the meantime, assync()does.protected voidflushSpi()protected String[]keysSpi()voidprotected voidprotected voidprotected voidvoidsync()Reloads the file if it has been modified externally since it was last read or written, re-applying the changes made since the last flush or sync on top of it, and saves those changes, once for the whole tree.protected voidsyncSpi()Methods inherited from class java.util.prefs.AbstractPreferences
absolutePath, addNodeChangeListener, addPreferenceChangeListener, cachedChildren, childrenNames, clear, exportNode, exportSubtree, get, getBoolean, getByteArray, getChild, getDouble, getFloat, getInt, getLong, isRemoved, isUserNode, keys, name, node, nodeExists, parent, putBoolean, putByteArray, putDouble, putFloat, putInt, putLong, remove, removeNode, removeNodeChangeListener, removePreferenceChangeListener, toStringMethods inherited from class java.util.prefs.Preferences
importPreferences, systemNodeForPackage, systemRoot, userNodeForPackage, userRoot
-
Field Details
-
PREFERENCES_LOCATION
Provides a way to override the default (OS dependent) directory used to store the user preferences file.Note that changing this value after a file based preferences instance has been created has no effect on subsequent instances.
- Value type: String
- Default value: null
- See Also:
-
PRETTY_PRINT
Specifies whether JSON preference files are pretty-printed, causes significant size increase.Note that this value is captured when a file based preferences instance is created; changing it afterwards has no effect on that instance.
- Value type: Boolean
- Default value: false
-
-
Method Details
-
put
- Overrides:
putin classAbstractPreferences
-
filePreferences
- Parameters:
filename- the preferences filename- Returns:
- a file based Preferences instance based on the given filename
-
backup
Copies the backing file to a sibling with the given suffix appended to the filename. Does nothing in case of an in-memory instance or if the backing file does not exist.- Parameters:
suffix- the backup filename suffix
-
putSpi
- Specified by:
putSpiin classAbstractPreferences
-
getSpi
- Specified by:
getSpiin classAbstractPreferences
-
removeSpi
- Specified by:
removeSpiin classAbstractPreferences
-
keysSpi
- Specified by:
keysSpiin classAbstractPreferences- Throws:
BackingStoreException
-
flush
Saves the changes made since the last flush or sync, once for the whole tree, re-applied on top of the file if it has been modified externally in the meantime, assync()does. Leaves the file untouched when there are no changes to save.AbstractPreferences.flush()would callflushSpi()on this node and on each cached descendant, saving the file once per node.- Overrides:
flushin classAbstractPreferences- Throws:
BackingStoreException- in case of an I/O error
-
sync
Reloads the file if it has been modified externally since it was last read or written, re-applying the changes made since the last flush or sync on top of it, and saves those changes, once for the whole tree.AbstractPreferences.sync()would callsyncSpi()on this node and on each cached descendant.- Overrides:
syncin classAbstractPreferences- Throws:
BackingStoreException- in case of an I/O errorIllegalStateException- in case this node has been removed
-
flushSpi
- Specified by:
flushSpiin classAbstractPreferences- Throws:
BackingStoreException
-
syncSpi
- Specified by:
syncSpiin classAbstractPreferences- Throws:
BackingStoreException
-
childrenNamesSpi
- Specified by:
childrenNamesSpiin classAbstractPreferences
-
childSpi
- Specified by:
childSpiin classAbstractPreferences
-
removeNodeSpi
protected void removeNodeSpi()- Specified by:
removeNodeSpiin classAbstractPreferences
-