org.jboss.dna.graph.property.basic
Class InMemoryBinary

java.lang.Object
  extended by org.jboss.dna.graph.property.basic.AbstractBinary
      extended by org.jboss.dna.graph.property.basic.InMemoryBinary
All Implemented Interfaces:
Serializable, Comparable<Binary>, Binary

@Immutable
public class InMemoryBinary
extends AbstractBinary

An implementation of Binary that keeps the binary data in-memory.

See Also:
Serialized Form

Constructor Summary
InMemoryBinary(byte[] bytes)
           
 
Method Summary
 void acquire()
          Acquire any resources for this data.
 byte[] getBytes()
          Get the contents of this data as a byte array.
 byte[] getHash()
          Get the SHA-1 hash of the contents.
 long getSize()
          Get the length of this binary data.
 InputStream getStream()
          Get the contents of this data as a stream.
 int hashCode()
          
 void release()
          Release any acquired resources.
 
Methods inherited from class org.jboss.dna.graph.property.basic.AbstractBinary
compareTo, equals, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InMemoryBinary

public InMemoryBinary(byte[] bytes)
Method Detail

hashCode

public int hashCode()

Overrides:
hashCode in class Object
See Also:
Object.hashCode()

getSize

public long getSize()
Get the length of this binary data.

Returns:
the number of bytes in this binary data
See Also:
Binary.acquire()

getHash

public byte[] getHash()
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:
Binary.getHash()

getBytes

public byte[] getBytes()
Get the contents of this data as a byte array.

Returns:
the data as an array
See Also:
Binary.acquire()

getStream

public InputStream getStream()
Get the contents of this data as a stream.

Returns:
the stream to this data's contents
See Also:
Binary.acquire()

acquire

public void acquire()
Acquire any resources for this data. This method must be called before any other method on this object.

See Also:
Binary.release()

release

public void release()
Release any acquired resources. This method must be called after a client is finished with this value.

See Also:
Binary.acquire()


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