/** * {@inheritDoc} * * @see org.modeshape.graph.property.ValueFactory#create(org.modeshape.graph.property.Binary) */ public String create( Binary value ) throws ValueFormatException, IoException { if (value == null) return null; try { value.acquire(); InputStream stream = value.getStream(); try { return create(stream, value.getSize()); } finally { try { stream.close(); } catch (IOException e) { Logger.getLogger(getClass()).debug(e, "Error closing the stream while converting from Binary to String"); } } } finally { value.release(); } }
@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(); }
try { stream = binary.getStream(); StreamSequencerContext streamSequencerContext = createStreamSequencerContext(input, sequencedProperty,