/** * {@inheritDoc} * * @see org.modeshape.graph.property.ValueTypeSystem.Factory#length(java.lang.Object) */ @Override public long length( Object value ) { Binary binary = this.valueFactory.create(value); return binary != null ? binary.getSize() : 0; } };
/** * {@inheritDoc} */ @Override public boolean equals( Object obj ) { if (obj == this) return true; if (obj instanceof Binary) { Binary that = (Binary)obj; if (this.getSize() != that.getSize()) return false; return ValueComparators.BINARY_COMPARATOR.compare(this, that) == 0; } return false; }
/** * {@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()) + ")"; }
/** * {@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(); } }