/** * Flushes the preferences (system and user). * * @throws BackingStoreException if failed */ public void flush() throws BackingStoreException { if (!systemOnly) { getUserPrefs().flush(); } getSystemPrefs().flush(); }
/** * Syncs the preferences (system and user). * * @throws BackingStoreException if failed */ public void sync() throws BackingStoreException { if (!systemOnly) { getUserPrefs().sync(); } getSystemPrefs().sync(); }
/** * Sets the value for a key.<br> * If the value is the same as in systemspace, the user value is removed. * Null-values also perform a remove. * * @param key the preferences key * @param val the value */ public void setString(String key, String val) { if (!systemOnly) { if (val == null || Objects.equals(val, getSystemPrefs().get(key, null))) { getUserPrefs().remove(key); } else { getUserPrefs().put(key, val); } } else { if (val == null) { getSystemPrefs().remove(key); } else { getSystemPrefs().put(key, val); } } }
/** * Gets a bytearray from the preferences. * * @param key the preferences key * @return the byte array or null if no such value */ public byte[] getByteArray(String key) { byte[] val = null; if (!systemOnly) { val = getUserPrefs().getByteArray(key, null); } if (val == null) { val = getSystemPrefs().getByteArray(key, null); } return val; }
/** * Gets the value for a key. * Userspace overwrites systemspace. * * @param key the preferences key * @return the value string or null if no such value */ public String getString(String key) { String val = null; if (!systemOnly) { val = getUserPrefs().get(key, null); } if (val == null) { val = getSystemPrefs().get(key, null); } return val; }
/** * Sets a bytearray.<br> * If the value is the same as in systemspace, the user value is removed. * Null-values also perform a remove. * * @param key the preferences key * @param val the values */ public void setByteArray(String key, byte[] val) { if (!systemOnly) { if (val == null || areByteArraysEqual(val, getSystemPrefs().getByteArray(key, null))) { getUserPrefs().remove(key); } else { getUserPrefs().putByteArray(key, val); } } else { if (val == null) { getSystemPrefs().remove(key); } else { getSystemPrefs().putByteArray(key, val); } } }