Exemplo n.º 1
0
  public static String serializeObjectToHexString(Serializable serializable) {
    String result = null;
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try {
      ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
      objectOutputStream.writeObject(serializable);

      result = com.google.bitcoin.core.Utils.bytesToHexString(byteArrayOutputStream.toByteArray());
      byteArrayOutputStream.close();
      objectOutputStream.close();

    } catch (IOException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
    return result;
  }
Exemplo n.º 2
0
  public static Object deserializeHexStringToObject(String serializedHexString) {
    Object result = null;
    try {
      ByteArrayInputStream byteInputStream =
          new ByteArrayInputStream(
              com.google.bitcoin.core.Utils.parseAsHexOrBase58(serializedHexString));

      try (ObjectInputStream objectInputStream = new ObjectInputStream(byteInputStream)) {
        result = objectInputStream.readObject();
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } finally {
        byteInputStream.close();
      }

    } catch (IOException i) {
      i.printStackTrace();
    }
    return result;
  }