List of usage examples for com.google.gwt.corp.localstorage LocalStorage key
public static String key(int index) throws IOException
From source file:com.badlogic.gdx.backends.gwt.GwtPreferences.java
License:Apache License
GwtPreferences(String prefix) {
this.prefix = prefix + ":";
int prefixLength = this.prefix.length();
try {// w w w . j a v a 2s. co m
for (int i = 0; i < LocalStorage.length(); i++) {
String key = LocalStorage.key(i);
if (key.startsWith(prefix)) {
String value = LocalStorage.getItem(key);
values.put(key.substring(prefixLength, key.length() - 1), toObject(key, value));
}
}
} catch (Exception e) {
values.clear();
}
}
From source file:com.badlogic.gdx.backends.gwt.GwtPreferences.java
License:Apache License
@Override public void flush() { try {/*from ww w .j a v a 2 s . c o m*/ // remove all old values for (int i = 0; i < LocalStorage.length(); i++) { String key = LocalStorage.key(i); if (key.startsWith(prefix)) LocalStorage.removeItem(key); } // push new values to LocalStorage for (String key : values.keys()) { String storageKey = toStorageKey(key, values.get(key)); String storageValue = "" + values.get(key).toString(); LocalStorage.setItem(storageKey, storageValue); } } catch (Exception e) { throw new GdxRuntimeException("Couldn't flush preferences"); } }