List of usage examples for com.google.gwt.corp.localstorage LocalStorage length
public static int length() 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 . c o 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 w w w . j av a2 s .c om*/ // 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"); } }