Ejemplo n.º 1
0
 public void save(File file) throws Exception {
   int idx = 0;
   int size = pCaches.size();
   if (size == 0) {
     return;
   }
   synchronized (pCaches) {
     StringBuilder sbr = new StringBuilder();
     WalletSeed seed = new WalletSeed(LSystem.getAppPassword());
     for (int i = 0; i < size; i++) {
       WalletItem item = (WalletItem) pCaches.getEntry(i).getValue();
       if (!item.isOnline()) {
         RPAddress address = new RPAddress(item.getPublicKey(), item.getPrivateKey());
         sbr.append(item.getDate());
         sbr.append(',');
         sbr.append(address.getPublic());
         sbr.append(',');
         sbr.append(address.getPrivate());
         sbr.append(',');
         sbr.append(item.getAmount());
         sbr.append(',');
         sbr.append(item.getStatus());
         idx++;
         if (idx < size) {
           sbr.append(LSystem.LS);
         }
       }
     }
     seed.save(file, sbr.toString());
   }
 }
Ejemplo n.º 2
0
 public String load(File file) throws Exception {
   synchronized (pCaches) {
     WalletSeed seed = new WalletSeed(LSystem.getAppPassword());
     String text = seed.load(file);
     StringTokenizer tokenizer = new StringTokenizer(text, LSystem.LS);
     String result = null;
     BigDecimal count = new BigDecimal("0");
     for (; tokenizer.hasMoreElements(); ) {
       result = tokenizer.nextToken();
       if (result != null && result.length() > 0) {
         String[] split = result.split(",");
         if (split.length > 4) {
           String date = split[0];
           String pubKey = split[1];
           String priKey = split[2];
           String amount = split[3];
           String status = split[4];
           RPAddress address = new RPAddress(pubKey, priKey);
           pubKey = new String(address.getPublic());
           priKey = new String(address.getPrivate());
           String key = pubKey.concat(priKey);
           if (!pCaches.containsKey(key)) {
             WalletItem walletItem = new WalletItem(date, priKey, amount, status);
             if (MathUtils.isNan(amount)) {
               count = count.add(new BigDecimal(amount));
             }
             pCaches.put(key, walletItem);
           }
         }
       }
       int res = count.intValue();
       if (res > 0) {
         amounts = String.valueOf(res);
       }
     }
     return text;
   }
 }