ModeShape Distribution 3.2.0.Final

org.modeshape.jcr.value.binary
Class AbstractBinary

java.lang.Object
  extended by org.modeshape.jcr.value.binary.AbstractBinary
All Implemented Interfaces:
Serializable, Comparable<BinaryValue>, Binary, BinaryValue
Direct Known Subclasses:
EmptyBinaryValue, ExternalBinaryValue, InMemoryBinaryValue, StoredBinaryValue

@Immutable
public abstract class AbstractBinary
extends Object
implements BinaryValue

An abstract implementation of BinaryValue that provides some common capabilities for other implementations.

See Also:
Serialized Form

Field Summary
protected static byte[] EMPTY_CONTENT
           
 
Constructor Summary
protected AbstractBinary(BinaryKey key)
           
 
Method Summary
 int compareTo(BinaryValue o)
           
 void dispose()
           
 boolean equals(Object obj)
           
 byte[] getHash()
          Get the SHA-1 hash of the contents.
 String getHexHash()
          Get the hexadecimal form of the SHA-1 hash of the contents.
 BinaryKey getKey()
          Get the key for the binary value.
 String getReadableSize()
           
 int hashCode()
           
static BinaryKey keyFor(byte[] sha1)
           
 int read(byte[] b, long position)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.modeshape.jcr.value.BinaryValue
getSize
 
Methods inherited from interface org.modeshape.jcr.api.Binary
getMimeType, getMimeType
 
Methods inherited from interface javax.jcr.Binary
getStream
 

Field Detail

EMPTY_CONTENT

protected static final byte[] EMPTY_CONTENT
Constructor Detail

AbstractBinary

protected AbstractBinary(BinaryKey key)
Method Detail

keyFor

public static BinaryKey keyFor(byte[] sha1)

read

public int read(byte[] b,
                long position)
         throws IOException,
                RepositoryException
Specified by:
read in interface Binary
Throws:
IOException
RepositoryException

getKey

public BinaryKey getKey()
Description copied from interface: BinaryValue
Get the key for the binary value.

Specified by:
getKey in interface BinaryValue
Returns:
the key; never null

getHash

public byte[] getHash()
Description copied from interface: Binary
Get the SHA-1 hash of the contents. This hash can be used to determine whether two Binary instances contain the same content.

Repeatedly calling this method should generally be efficient, as it most implementations will compute the hash only once.

Returns:
the hash of the contents as a byte array, or an empty array if the hash could not be computed.
See Also:
MessageDigest.digest(byte[]), MessageDigest.getInstance(String), Binary.getHexHash()

getHexHash

public String getHexHash()
Description copied from interface: Binary
Get the hexadecimal form of the SHA-1 hash of the contents. This hash can be used to determine whether two Binary instances contain the same content.

Repeatedly calling this method should generally be efficient, as it most implementations will compute the hash only once.

Returns:
the hexadecimal form of the Binary.getHash(), or a null string if the hash could not be computed or is not known
See Also:
MessageDigest.digest(byte[]), MessageDigest.getInstance(String), Binary.getHash()

dispose

public void dispose()
Specified by:
dispose in interface Binary

compareTo

public int compareTo(BinaryValue o)
Specified by:
compareTo in interface Comparable<BinaryValue>

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

getReadableSize

public String getReadableSize()

ModeShape Distribution 3.2.0.Final

Copyright © 2008-2013 JBoss, a division of Red Hat. All Rights Reserved.