Search code examples
javablobinputstream

Can i compare the content of 2 different Blob Objects


I have 2 BLOB Objects and I want to compare the content within those BLOB objects??

How can i do this in JAVA.

Blob blob = new SerialBlob(cis.readAllBytes());
final Blob blob2 = test.reEncrypt(blob, "");

I want to compare the content in blob and blob2. My target is to check if the reEncryption gave me the same data or different.

Any leads would be really great. Thanks

  final InputStream cis = test.getEncryptingInputStream(is);
  final InputStream resStream = test
                .reEncrypt(cis, "");
  String encodeStr1 = Base64.getEncoder().encodeToString(cis.readAllBytes());
  String encodeStr2 = Base64.getEncoder().encodeToString(resStream.readAllBytes());

encodestr1 and encodestr2 is coming empty. Can you explain how can we compare the content of InputStream as well. Correct me If I am doing anything wrong here.


Solution

  • I would try something like

        String string1 = Base64.getEncoder().encodeToString(blob.getBytes(1, (int)blob.length()));
        String string2 = Base64.getEncoder().encodeToString(blob2.getBytes(1, (int)blob2.length()));
        System.out.println(string1.equals(string2));