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

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

@Immutable
public class InMemoryBinary
extends Object
implements Binary

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

Author:
Randall Hauch
See Also:
Serialized Form

Constructor Summary
InMemoryBinary(byte[] bytes)
           
 
Method Summary
 void acquire()
          Acquire any resources for this data.
 int compareTo(Binary o)
          
 boolean equals(Object obj)
          
 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.
 void release()
          Release any acquired resources.
 String toString()
          
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InMemoryBinary

public InMemoryBinary(byte[] bytes)
Method Detail

getSize

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

Specified by:
getSize in interface Binary
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.

Specified by:
getHash in interface Binary
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.

Specified by:
getBytes in interface Binary
Returns:
the data as an array
See Also:
Binary.acquire()

getStream

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

Specified by:
getStream in interface Binary
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.

Specified by:
acquire in interface Binary
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.

Specified by:
release in interface Binary
See Also:
Binary.acquire()

compareTo

public int compareTo(Binary o)

Specified by:
compareTo in interface Comparable<Binary>

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

toString

public String toString()

Overrides:
toString in class Object


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