public class Storage
extends java.lang.Object
Constructor and Description |
---|
Storage(@NotNull java.lang.String defaultPath,
@Nullable java.io.File file)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
@NotNull java.lang.String[] |
childrenNames(@NotNull java.lang.String path)
Returns the names of the children of a node.
|
@NotNull java.lang.String[] |
getKeys(@NotNull java.lang.String path)
Returns all of the keys that have an associated value in a node.
|
@Nullable java.lang.String |
getValue(@NotNull java.lang.String path,
@NotNull java.lang.String key)
Returns the value associated with the specified key at a node, or
null if there is no association for this key. |
void |
newNode(@NotNull java.lang.String path)
Makes sure a node exists.
|
void |
putValue(@NotNull java.lang.String path,
@NotNull java.lang.String key,
@NotNull java.lang.String value)
Puts the given key-value association into a node.
|
void |
removeNode(@NotNull java.lang.String path)
Removes a preference node including all preferences that it contains.
|
void |
removeValue(@NotNull java.lang.String path,
@NotNull java.lang.String key)
Removes the association (if any) for the specified key at a node.
|
void |
sync(boolean sync)
Saves changes to the underlying file.
|
public Storage(@NotNull @NotNull java.lang.String defaultPath, @Nullable @Nullable java.io.File file)
defaultPath
- the default key name for loading/saving valuesfile
- the file for loading/saving values or null
to not use
a backing filepublic void newNode(@NotNull @NotNull java.lang.String path)
path
- the node path name@NotNull public @NotNull java.lang.String[] childrenNames(@NotNull @NotNull java.lang.String path)
path
- the node path name@Nullable public @Nullable java.lang.String getValue(@NotNull @NotNull java.lang.String path, @NotNull @NotNull java.lang.String key)
null
if there is no association for this key.path
- the node path namekey
- the key to get value for@NotNull public @NotNull java.lang.String[] getKeys(@NotNull @NotNull java.lang.String path)
path
- the node path namepublic void putValue(@NotNull @NotNull java.lang.String path, @NotNull @NotNull java.lang.String key, @NotNull @NotNull java.lang.String value)
path
- the node path namekey
- the key to storevalue
- the value to storepublic void removeNode(@NotNull @NotNull java.lang.String path)
path
- the node path namepublic void removeValue(@NotNull @NotNull java.lang.String path, @NotNull @NotNull java.lang.String key)
path
- the node path name to remove fromkey
- the key to removepublic void sync(boolean sync) throws java.util.prefs.BackingStoreException
sync
- not currently usedjava.util.prefs.BackingStoreException
- in case sync was not possible, i.e. due to
I/O problems