AbstractBlob implements Blob { public static boolean equal(Blob a, Blob b) { long al = a.length(); long bl = b.length(); if (al != -1 && bl != -1 && al != bl) { return false; } String ai = a.getContentIdentity(); String bi = b.getContentIdentity(); if (ai != null && bi != null && ai.equals(bi)){ return true; } try { return supplier(a).contentEquals(supplier(b)); } catch (IOException e) { throw new IllegalStateException("Blob equality check failed", e); } } protected  AbstractBlob(HashCode hashCode); protected  AbstractBlob(); static boolean equal(Blob a, Blob b); static HashCode calculateSha256(final Blob blob); @Override @Nullable String getReference(); @Override String getContentIdentity(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString();  }
@Test public void blobComparisonBasedOnContentIdentity() throws Exception { byte[] data = bytes(100); Blob a = new TestBlob(data, "id1", false); Blob b = new TestBlob(data, "id1", false); assertTrue(AbstractBlob.equal(a, b)); Blob a2 = new TestBlob(data, "id1", true); Blob b2 = new TestBlob(data, "id2", true); assertTrue("Blobs with different id but same content should match", AbstractBlob.equal(a2, b2)); assertFalse(a2.isInlined()); assertFalse(b2.isInlined()); }
@Test public void blobComparisonBasedOnLength() throws Exception { Blob a = new TestBlob(bytes(100), null, false); Blob b = new TestBlob(bytes(50), null, false); assertFalse("Blob comparison should not fallback on content if lengths not same", AbstractBlob.equal(a, b)); }