public class KeyValueEncryptedFileStore extends java.lang.Object implements KeyValueStore
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
KEY_SUFFIX |
static java.lang.String |
KEY_VALUE_STORES |
static int |
KV_VERSION |
static int |
MAX_STORE_NAME_LENGTH |
static java.lang.String |
VALUE_SUFFIX |
static java.lang.String |
VERSION_FILE_NAME |
Constructor and Description |
---|
KeyValueEncryptedFileStore(Context ctx,
java.lang.String storeName,
java.lang.String encryptionKey)
Constructor
|
Modifier and Type | Method and Description |
---|---|
boolean |
changeEncryptionKey(java.lang.String newEncryptionKey)
Change encryption key
All files are read/decrypted with old key and encrypted/written back with new key
|
static java.io.File |
computeParentDir(Context ctx)
Return parent directory for all key stores
|
boolean |
contains(java.lang.String key)
Return true if store contains a file for the given key
|
int |
count() |
boolean |
deleteAll()
Deletes all stored values.
|
boolean |
deleteValue(java.lang.String key)
Deletes stored value for given key.
|
java.io.File |
getStoreDir() |
java.lang.String |
getStoreName() |
int |
getStoreVersion() |
java.io.InputStream |
getStream(java.lang.String key)
Returns stream for value of given key.
|
java.lang.String |
getValue(java.lang.String key)
Returns value stored for given key.
|
static boolean |
hasKeyValueStore(Context ctx,
java.lang.String storeName)
Return boolean indicating if a key value store with the given (full) name already exists
|
boolean |
isEmpty() |
static boolean |
isValidStoreName(java.lang.String storeName)
Store name can only contain letters, digits and _ and cannot exceed 96 characters
|
java.util.Set<java.lang.String> |
keySet()
Get all keys.
|
static void |
removeKeyValueStore(Context ctx,
java.lang.String storeName)
Remove key value store with given (full) name
|
boolean |
saveStream(java.lang.String key,
java.io.InputStream stream)
Save value given as an input stream for the given key.
|
boolean |
saveValue(java.lang.String key,
java.lang.String value)
Save value for the given key.
|
public static final int KV_VERSION
public static final int MAX_STORE_NAME_LENGTH
public static final java.lang.String KEY_SUFFIX
public static final java.lang.String VALUE_SUFFIX
public static final java.lang.String VERSION_FILE_NAME
public static final java.lang.String KEY_VALUE_STORES
public KeyValueEncryptedFileStore(Context ctx, java.lang.String storeName, java.lang.String encryptionKey)
storeName
- name for key value storeencryptionKey
- encryption key for key value storepublic static boolean hasKeyValueStore(Context ctx, java.lang.String storeName)
ctx
- storeName
- full store namepublic static void removeKeyValueStore(Context ctx, java.lang.String storeName)
ctx
- storeName
- full store namepublic static java.io.File computeParentDir(Context ctx)
ctx
- public static boolean isValidStoreName(java.lang.String storeName)
storeName
- public boolean contains(java.lang.String key)
contains
in interface KeyValueStore
key
- public boolean saveValue(java.lang.String key, java.lang.String value)
saveValue
in interface KeyValueStore
key
- Unique identifier.value
- Value to be persisted.public boolean saveStream(java.lang.String key, java.io.InputStream stream)
saveStream
in interface KeyValueStore
key
- Unique identifier.stream
- Stream to be persisted.public java.lang.String getValue(java.lang.String key)
getValue
in interface KeyValueStore
key
- Unique identifier.public java.io.InputStream getStream(java.lang.String key)
getStream
in interface KeyValueStore
key
- Unique identifier.public boolean deleteValue(java.lang.String key)
deleteValue
in interface KeyValueStore
key
- Unique identifier.public boolean deleteAll()
deleteAll
in interface KeyValueStore
public java.util.Set<java.lang.String> keySet()
keySet
in interface KeyValueStore
public int count()
count
in interface KeyValueStore
public boolean isEmpty()
isEmpty
in interface KeyValueStore
public java.io.File getStoreDir()
public java.lang.String getStoreName()
getStoreName
in interface KeyValueStore
public int getStoreVersion()
public boolean changeEncryptionKey(java.lang.String newEncryptionKey)
newEncryptionKey
-