Example usage for com.google.gwt.corp.localstorage LocalStorage length

List of usage examples for com.google.gwt.corp.localstorage LocalStorage length

Introduction

In this page you can find the example usage for com.google.gwt.corp.localstorage LocalStorage length.

Prototype

public static int length() throws IOException 

Source Link

Usage

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");
    }
}