/** * {@inheritDoc} * * @see org.modeshape.graph.property.ValueTypeSystem.Factory#asReadableString(java.lang.Object) */ @Override public String asReadableString( Object value ) { Binary binary = this.valueFactory.create(value); // Just print out the SHA-1 hash in Base64, plus length return "(Binary,length=" + binary.getSize() + ",SHA1=" + Base64.encodeBytes(binary.getHash()) + ")"; }
public LargeValue get( Binary obj ) { return get(obj.getHash()); }
@Test public void shouldCompareBinaryAndStringValues() { String strValue = "Jack and Jill went up the hill"; Binary binaryValue = factories.getBinaryFactory().create(strValue); Binary binarySpy = spy(binaryValue); // The values should compare to each other ... assertThat(ValueComparators.OBJECT_COMPARATOR.compare(strValue, binarySpy), is(0)); assertThat(ValueComparators.OBJECT_COMPARATOR.compare(binarySpy, strValue), is(0)); // Verify that the binary value was not obtained, but that we just used the hash verify(binarySpy, times(0)).getBytes(); verify(binarySpy, times(0)).getStream(); verify(binarySpy, atLeastOnce()).getHash(); }
public boolean isSkipped( Binary binary ) { String key = StringUtil.getHexString(binary.getHash()); return isSkipped(key); }
value2 = stringFactory.create(o2); hash2 = SecureHash.getHash(SecureHash.Algorithm.SHA_1, value2.getBytes()); hash1 = ((Binary)o1).getHash(); } else { assert type2 == PropertyType.BINARY; value1 = stringFactory.create(o1); hash1 = SecureHash.getHash(SecureHash.Algorithm.SHA_1, value1.getBytes()); hash2 = ((Binary)o2).getHash();
@FixFor( "MODE-966" ) @Test public void shouldStoreLargeBinaryValue() throws Exception { File file = new File("src/test/resources/testdata/test1.xmi"); assertThat(file.exists(), is(true)); BinaryFactory binaryFactory = context.getValueFactories().getBinaryFactory(); Binary binaryValue = binaryFactory.create(file); graph.batch() .create("/someFile.xmi") .with("jcr:primaryType", "nt:file") .and() .create("/someFile.xmi/jcr:content") .with("jcr:priamryType", "nt:resource") .and("jcr:data", binaryValue) .and() .execute(); // Now read the content back out ... Property data = graph.getProperty("jcr:data").on("/someFile.xmi/jcr:content"); Binary readValue = binaryFactory.create(data.getFirstValue()); // and verify the content matches ... assertThat(binaryValue.getHash(), is(readValue.getHash())); assertThat(binaryValue.getBytes(), is(readValue.getBytes())); }