private void updateIndex() {
    Collections.sort(index, comparator);
    DataOutput dataOutput = new DataOutput();
    dataOutput.writeInt(index.size());

    for (Index i : index) {
      dataOutput.writeLong(i.getId());
      dataOutput.writeLong(i.getSortKey());
    }

    storage.setItem("list_" + prefix + "_index", toBase64(dataOutput.toByteArray()));
  }
 @Override
 public void onResponseReceived(final Request request, @Nonnull final Response response) {
   if (response.getStatusCode() == 304 && Storage.isSessionStorageSupported()) {
     final Storage storage = Storage.getSessionStorageIfSupported();
     if (storage.getItem(cacheKey()) != null) {
       callback.onResponseReceived(request, getOldResponse(storage));
       return;
     }
   }
   if (response.getStatusCode() == 304 && Storage.isLocalStorageSupported()) {
     final Storage storage = Storage.getLocalStorageIfSupported();
     if (storage.getItem(cacheKey()) != null) {
       callback.onResponseReceived(request, getOldResponse(storage));
       return;
     }
   }
   if (response.getStatusCode() == 200
       && response.getHeader(DataStoreService.X_VORTEX_CACHE_SCOPE) != null
       && response
           .getHeader(DataStoreService.X_VORTEX_CACHE_SCOPE)
           .equals(CachingScope.USER.name())) {
     serializedResponse = response.getText();
     if (Storage.isLocalStorageSupported()) {
       final Storage storage = Storage.getLocalStorageIfSupported();
       storage.setItem(cacheKey(), serializedResponse);
     }
   } else if (response.getStatusCode() == 200
       && response.getHeader(DataStoreService.X_VORTEX_CACHE_SCOPE) != null
       && response
           .getHeader(DataStoreService.X_VORTEX_CACHE_SCOPE)
           .equals(CachingScope.SESSION.name())) {
     serializedResponse = response.getText();
     if (Storage.isSessionStorageSupported()) {
       final Storage storage = Storage.getSessionStorageIfSupported();
       storage.setItem(cacheKey(), serializedResponse);
     }
   }
   callback.onResponseReceived(request, response);
 }
  @Override
  public void updateOrAdd(ListEngineRecord record) {
    // Update Index
    for (Index i : index) {
      if (i.getId() == record.getKey()) {
        index.remove(i);
        break;
      }
    }
    index.add(new Index(record.getKey(), record.getOrder()));
    updateIndex();

    // Save record
    storage.setItem(getId(record.getKey()), toBase64(record.getData()));
  }
 public void save_licence(byte[] databytes, Options option) {
   /*        Preferences prefs = Preferences.userNodeForPackage(this.getClass());
           prefs.putByteArray("licence."+ option.getHostname(), databytes);
   */ Storage store = Storage.getLocalStorageIfSupported();
   if (store != null) store.setItem("licence." + option.getHostname(), new String(databytes));
 }
 public void setPersistantTabFlag(String flag) {
   stockStore = Storage.getLocalStorageIfSupported();
   if (stockStore != null) {
     stockStore.setItem("tabKey", flag);
   }
 }