Beispiel #1
0
  public void save() {
    boolean isNoticed = false;
    if (!notice.isVisible()) {
      isNoticed = true;
      notice.setVisible(true);
      notice.setText("Saving...");
    }
    if (getOptions() != null) {
      DB database = null;
      try {
        database = factory.open(this.leveldbStore.getSelectedFile(), getOptions());
        DBIterator iterator = database.iterator();
        HashSet<byte[]> keys = new HashSet<>();

        for (iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {
          keys.add(iterator.peekNext().getKey());
        }
        iterator.close();

        for (byte[] key : keys) {
          database.delete(key);
        }

        for (int i = 0; i < dataList.getModel().getSize(); ++i) {
          DBItem item = dataList.getModel().getElementAt(i);
          database.put(item.key, item.value);
        }
      } catch (Exception e) {
        JOptionPane.showMessageDialog(pane, "Unable to open database:\n" + e);
        e.printStackTrace();
      } finally {
        if (database != null) {
          try {
            database.close();
          } catch (IOException e) {
            JOptionPane.showMessageDialog(pane, "Unable to close database:\n" + e);
            e.printStackTrace();
          }
        }
        saveButton.setEnabled(false);
      }
    }
    if (isNoticed) {
      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      notice.setVisible(false);
      notice.setText("");
    }
  }
Beispiel #2
0
  public void openDatabase(File select) {
    if (getOptions() != null) {
      DB database = null;
      try {
        database = factory.open(select, getOptions());
        DBIterator iterator = database.iterator();

        ArrayList<DBItem> data = new ArrayList<>();

        String reg = findField.getText().trim();

        for (iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {
          if (reg.isEmpty()
              || new BigInteger(iterator.peekNext().getKey()).toString(16).contains(reg)
              || LevelDBViewer.toHexString(iterator.peekNext().getKey()).contains(reg)
              || new BigInteger(iterator.peekNext().getValue()).toString(16).contains(reg)
              || LevelDBViewer.toHexString(iterator.peekNext().getValue()).contains(reg)
              || new String(iterator.peekNext().getKey()).contains(reg)
              || new String(iterator.peekNext().getValue()).contains(reg)) {
            data.add(new DBItem(iterator.peekNext().getKey(), iterator.peekNext().getValue()));
          }
        }

        iterator.close();

        dialog.getRootPane().setDefaultButton(putButton);

        dataList.getSelectionModel().clearSelection();
        dataList.setListData(data.toArray(new DBItem[data.size()]));

        putButton.setEnabled(true);
        key.setEnabled(true);
        value.setEnabled(true);
        findField.setEnabled(true);
        deleteButton.setEnabled(true);
        putType.setEnabled(true);
        signedBox.setEnabled(true);
        // saveButton.setEnabled(true);

        hexValue.setText("");
        stringValue.setText("");
        hexKey.setText("");
        stringKey.setText("");

        lengthLabel.setText("");
        keyLength.setText("");
        valueLength.setText("");
      } catch (Exception e) {
        JOptionPane.showMessageDialog(pane, "Unable to open database:\n" + e);
        e.printStackTrace();
      } finally {
        if (database != null) {
          try {
            database.close();
          } catch (IOException e) {
            JOptionPane.showMessageDialog(pane, "Unable to close database:\n" + e);
            e.printStackTrace();
          }
        }
      }
    }
  }