org.priha.core.binary
Class MemoryBinarySource

java.lang.Object
  extended by org.priha.core.binary.MemoryBinarySource
All Implemented Interfaces:
BinarySource

public class MemoryBinarySource
extends java.lang.Object
implements BinarySource

A BinarySource which stores the binary in the memory in a byte array.

Obviously, this source is limited by the size of the heap.


Constructor Summary
MemoryBinarySource(byte[] v)
          Creates a MemoryBinarySource by using the given byte array.
MemoryBinarySource(java.io.InputStream in)
          Creates a new MemoryBinarySource by slurping the contents into a binary array.
 
Method Summary
 MemoryBinarySource clone()
          Duplicates the BinarySource object.
 long getLength()
          Return the length of the object represented by this BinarySource.
 java.io.InputStream getStream()
          Returns the contents of the BinarySource as an InputStream.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryBinarySource

public MemoryBinarySource(java.io.InputStream in)
                   throws java.io.IOException
Creates a new MemoryBinarySource by slurping the contents into a binary array.

Parameters:
in - The InputStream to read. If null, creates an empty MemoryBinarySource.
Throws:
java.io.IOException - If reading of the stream failed and the memory could not be initialized.s

MemoryBinarySource

public MemoryBinarySource(byte[] v)
Creates a MemoryBinarySource by using the given byte array.

Parameters:
v - The byte array to use.
Method Detail

getLength

public long getLength()
Return the length of the object represented by this BinarySource.

Specified by:
getLength in interface BinarySource
Returns:
The length of the object.

getStream

public java.io.InputStream getStream()
Returns the contents of the BinarySource as an InputStream. Note that this must always return a valid stream pointing at the beginning of the binary object.

Specified by:
getStream in interface BinarySource
Returns:
An InputStream representing the binary item.

clone

public MemoryBinarySource clone()
Duplicates the BinarySource object.

Specified by:
clone in interface BinarySource
Overrides:
clone in class java.lang.Object
Returns:
A new BinarySource which represents the same object.