com.google.gwt.storage.client.Storage Java Examples

The following examples show how to use com.google.gwt.storage.client.Storage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsKeyValueStorage.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
public JsKeyValueStorage(String prefix, Storage storage) {
    this.storage = storage;
    this.prefix = prefix;

    try {
        String index = storage.getItem("kv_" + prefix + "_index");
        if (index != null) {
            byte[] data = fromBase64(index);
            DataInput dataInput = new DataInput(data, 0, data.length);
            int count = dataInput.readInt();
            for (int i = 0; i < count; i++) {
                items.add(dataInput.readLong());
            }
        }
    } catch (Exception e) {
        Log.e(TAG, e);
    }
}
 
Example #2
Source File: JsListStorage.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
public JsListStorage(String prefix, Storage storage) {
    this.storage = storage;
    this.prefix = prefix;

    String indexData = storage.getItem("list_" + prefix + "_index");
    if (indexData != null) {
        try {
            byte[] data = fromBase64(indexData);
            DataInput dataInput = new DataInput(data, 0, data.length);
            int count = dataInput.readInt();
            for (int i = 0; i < count; i++) {
                long id = dataInput.readLong();
                long order = dataInput.readLong();
                index.add(new Index(id, order));
            }
        } catch (Exception e) {
            Log.e(TAG, e);
        }
    }

    updateIndex();
}
 
Example #3
Source File: CirSim.java    From circuitjs1 with GNU General Public License v2.0 5 votes vote down vote up
boolean getOptionFromStorage(String key, boolean val) {
    Storage stor = Storage.getLocalStorageIfSupported();
    if (stor == null)
        return val;
    String s = stor.getItem(key);
    if (s == null)
        return val;
    return s == "true";
}
 
Example #4
Source File: CirSim.java    From circuitjs1 with GNU General Public License v2.0 5 votes vote down vote up
void saveShortcuts() {
    Storage stor = Storage.getLocalStorageIfSupported();
    if (stor == null)
        return;
    String str = "1";
    int i;
    // format: version;code1=ClassName;code2=ClassName;etc
    for (i = 0; i != shortcuts.length; i++) {
        String sh = shortcuts[i];
        if (sh == null)
    		continue;
        str += ";" + i + "=" + sh;
    }
    stor.setItem("shortcuts", str);
}
 
Example #5
Source File: Index.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
Index(final String prefix, final BeanFactory beanFactory) {
    this.prefix = prefix;
    this.beanFactory = beanFactory;
    this.localStorage = Storage.getLocalStorageIfSupported();
    this.idCounter = 0;

    load();
    Storage.addStorageEventHandler(this);
}
 
Example #6
Source File: LocalStoragePropertyProvider.java    From mapper with Apache License 2.0 5 votes vote down vote up
@Override
public String get(String key) {
  Storage storage = Storage.getLocalStorageIfSupported();
  if (storage != null) {
    return storage.getItem(myPrefix + "." + key);
  }
  return null;
}
 
Example #7
Source File: CirSim.java    From circuitjs1 with GNU General Public License v2.0 5 votes vote down vote up
void writeRecoveryToStorage() {
console("write recovery");
   	Storage stor = Storage.getLocalStorageIfSupported();
   	if (stor == null)
   		return;
   	String s = dumpCircuit();
   	stor.setItem("circuitRecovery", s);
   }
 
Example #8
Source File: AuthImpl.java    From requestor with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the correct {@link TokenStore} implementation to use based on browser support for localStorage.
 */
// TODO(jasonhall): This will not result in CookieStoreImpl being compiled out
// for browsers that support localStorage, and vice versa? If not, this should
// be a deferred binding rule.
private static TokenStoreImpl getTokenStore() {
    return Storage.isLocalStorageSupported() ? new TokenStoreImpl() : new CookieStoreImpl();
}
 
Example #9
Source File: DisplayDensityStorage.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
public static void apply(DisplayDensity density) {
    if (Storage.isLocalStorageSupported()) {
        storage.setItem(STORAGE_ID, density.getCssName());
        Window.Location.reload();
    } else {
        GWT.log("localStorage API is not supported by your browser.");
    }
}
 
Example #10
Source File: DisplayDensityStorage.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
public static DisplayDensity get() {
    if (Storage.isLocalStorageSupported()) {
        Storage storage = Storage.getLocalStorageIfSupported();
        return DisplayDensity.fromStyleName(storage.getItem(STORAGE_ID));
    } else {
        return DisplayDensity.DEFAULT;
    }
}
 
Example #11
Source File: IdentityUtils.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
public static String getUniqueId() {
    Storage storage = Storage.getLocalStorageIfSupported();
    String id = storage.getItem("tech_unique_id");
    if (id != null) {
        return id;
    }
    Random rnd = new Random();
    id = "";
    for (int i = 0; i < 128; i++) {
        id += ((char) ('a' + rnd.nextInt('z' - 'a')));
    }
    storage.setItem("tech_unique_id", id);
    return id;
}
 
Example #12
Source File: BootstrapServerStore.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public BootstrapServerStore() {
    factory = GWT.create(BeanFactory.class);
    storage = Storage.getLocalStorageIfSupported();
}
 
Example #13
Source File: JsPreferencesStorage.java    From actor-platform with GNU Affero General Public License v3.0 4 votes vote down vote up
public JsPreferencesStorage(Storage storage) {
    this.storage = storage;
}
 
Example #14
Source File: CirSim.java    From circuitjs1 with GNU General Public License v2.0 4 votes vote down vote up
void readRecovery() {
Storage stor = Storage.getLocalStorageIfSupported();
if (stor == null)
	return;
recovery = stor.getItem("circuitRecovery");
   }
 
Example #15
Source File: CirSim.java    From circuitjs1 with GNU General Public License v2.0 4 votes vote down vote up
void readClipboardFromStorage() {
	Storage stor = Storage.getLocalStorageIfSupported();
	if (stor == null)
		return;
	clipboard = stor.getItem("circuitClipboard");
}
 
Example #16
Source File: CirSim.java    From circuitjs1 with GNU General Public License v2.0 4 votes vote down vote up
void writeClipboardToStorage() {
	Storage stor = Storage.getLocalStorageIfSupported();
	if (stor == null)
		return;
	stor.setItem("circuitClipboard", clipboard);
}
 
Example #17
Source File: CirSim.java    From circuitjs1 with GNU General Public License v2.0 4 votes vote down vote up
void setOptionInStorage(String key, boolean val) {
    Storage stor = Storage.getLocalStorageIfSupported();
    if (stor == null)
        return;
    stor.setItem(key,  val ? "true" : "false");
}