freemarker.template
Class BinaryData

java.lang.Object
  extended by freemarker.template.BinaryData
All Implemented Interfaces:
Cacheable, Compileable, java.io.Serializable, java.lang.Cloneable

public class BinaryData
extends java.lang.Object
implements Cacheable, java.lang.Cloneable, Compileable, java.io.Serializable

An application or servlet can instantiate a BinaryData to retrieve a binary file.

You can pass the filename of the binary file to a BinaryDataFactory object, in which case it is read in immediately.

To retrieve the binary data, call the process(java.io.OutputStream) method.

To facilitate multithreading, BinaryData objects are immutable; if you need to reload a binary file, you must make a new BinaryData object. In most cases, it will be sufficient to let a Cache do this for you.

Version:
$Id: BinaryData.java 1166 2013-04-21 08:21:15Z run2000 $
See Also:
FileTemplateCache, BinaryDataFactory, Serialized Form

Field Summary
protected  Cache cache
          The cache to which this binary data object belongs (if any).
protected  byte[] dataArray
          The binary data held by this object.
 
Constructor Summary
BinaryData(java.io.InputStream stream)
          Clones an existing BinaryData instance.
BinaryData(java.io.InputStream stream, Cache cache)
          Clones an existing BinaryData instance.
 
Method Summary
 java.lang.Object clone()
          Clones the current BinaryData object.
 void compile(java.io.InputStream stream)
          Compiles the template from an InputStream.
 Cache getCache()
          Retrieve the Cache that this object is stored in.
 int getContentLength()
          Returns the length of the binary data, in bytes.
 void process(java.io.OutputStream out)
          Processes the binary data file, and output the resulting binary data to an OutputStream.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

dataArray

protected byte[] dataArray
The binary data held by this object.


cache

protected transient Cache cache
The cache to which this binary data object belongs (if any).

Constructor Detail

BinaryData

public BinaryData(java.io.InputStream stream)
           throws java.io.IOException
Clones an existing BinaryData instance.

Parameters:
stream - an InputStream from which the template can be read.
Throws:
java.io.IOException

BinaryData

public BinaryData(java.io.InputStream stream,
                  Cache cache)
           throws java.io.IOException
Clones an existing BinaryData instance.

Parameters:
stream - an InputStream from which the template can be read.
Throws:
java.io.IOException
Method Detail

compile

public void compile(java.io.InputStream stream)
             throws java.io.IOException,
                    java.lang.IllegalArgumentException
Compiles the template from an InputStream. If the template has already been compiled, this method does nothing.

Parameters:
stream - an InputStream from which the template can be read.
Throws:
java.io.IOException
java.lang.IllegalArgumentException

process

public void process(java.io.OutputStream out)
Processes the binary data file, and output the resulting binary data to an OutputStream.

Parameters:
out - an OutputStream to output the binary data to.

getContentLength

public int getContentLength()
Returns the length of the binary data, in bytes. This is convenient for Servlets that want to return this information to the caller.

Returns:
the content length of the binary data, in bytes

getCache

public Cache getCache()
Retrieve the Cache that this object is stored in.

Specified by:
getCache in interface Cacheable
Returns:
the Cache that this template belongs to.

clone

public java.lang.Object clone()
Clones the current BinaryData object.

Overrides:
clone in class java.lang.Object
Returns:
a cloned instance of the current BinaryData object

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object.