freemarker.template
Class BinaryData

java.lang.Object
  |
  +--freemarker.template.BinaryData
All Implemented Interfaces:
Cacheable, java.lang.Cloneable, Compileable, java.io.Serializable

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 the constructor, in which case it is read in immediately.

To retrive 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,v 1.17 2003/11/24 05:49:49 run2000 Exp $
See Also:
FileTemplateCache, 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()
          Constructs an empty binary object.
BinaryData(BinaryData data)
          Clones an existing BinaryData instance.
BinaryData(java.io.File file)
          Constructs a BinaryData object by compiling it from a file.
BinaryData(java.io.InputStream stream)
          Constructs a template by compiling it from an InputStream.
BinaryData(java.lang.String filePath)
          Constructs a binary data object by compiling it from a file.
 
Method Summary
 java.lang.Object clone()
          Clones the current BinaryData object.
 void compileFromFile(java.io.File file)
          Reads and compiles a template from a file, by getting the file's FileInputStream and using it to call compileFromStream(), using the platform's default character encoding.
 void compileFromFile(java.lang.String filePath)
          Reads and compiles a template from a file, by getting the file's FileInputStream and using it to call compileFromStream(), using the platform's default character encoding.
 void compileFromStream(java.io.InputStream stream)
          Compiles the template from an InputStream, using the platform's default character encoding.
 void compileFromStream(java.io.InputStream stream, java.lang.String encoding)
          Compiles the template from an InputStream, using the specified character encoding.
 Cache getCache()
          Retrieve the Cache that this object is stored in.
 void process(java.io.OutputStream out)
          Processes the binary data file, and output the resulting binary data to an OutputStream.
 void setCache(Cache cache)
          Sets the Cache that this object is stored in.
 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()
Constructs an empty binary object.

BinaryData

public BinaryData(java.lang.String filePath)
           throws java.io.IOException
Constructs a binary data object by compiling it from a file. Calls compileFromFile().
Parameters:
filePath - the absolute path of the binary file to be compiled.

BinaryData

public BinaryData(java.io.File file)
           throws java.io.IOException
Constructs a BinaryData object by compiling it from a file. Calls compileFromFile().
Parameters:
file - a File representing the binary file to be compiled.

BinaryData

public BinaryData(java.io.InputStream stream)
           throws java.io.IOException
Constructs a template by compiling it from an InputStream. Calls compileFromStream().
Parameters:
stream - an InputStream from which the template can be read.

BinaryData

public BinaryData(BinaryData data)
Clones an existing BinaryData instance.
Parameters:
data - the BinaryData instance to be cloned
Method Detail

compileFromFile

public void compileFromFile(java.lang.String filePath)
                     throws java.io.IOException
Reads and compiles a template from a file, by getting the file's FileInputStream and using it to call compileFromStream(), using the platform's default character encoding.
Parameters:
filePath - the absolute path of the template file to be compiled.

compileFromFile

public void compileFromFile(java.io.File file)
                     throws java.io.IOException
Reads and compiles a template from a file, by getting the file's FileInputStream and using it to call compileFromStream(), using the platform's default character encoding.
Parameters:
file - a File representing the template file to be compiled.

compileFromStream

public void compileFromStream(java.io.InputStream stream)
                       throws java.io.IOException
Compiles the template from an InputStream, using the platform's default character encoding. If the template has already been compiled, this method does nothing.
Specified by:
compileFromStream in interface Compileable
Parameters:
stream - an InputStream from which the template can be read.

compileFromStream

public void compileFromStream(java.io.InputStream stream,
                              java.lang.String encoding)
                       throws java.io.IOException
Compiles the template from an InputStream, using the specified character encoding. If the template has already been compiled, this method does nothing.
Specified by:
compileFromStream in interface Compileable
Parameters:
stream - an InputStream from which the template can be read.
encoding - the character encoding to use. For binary data, this does nothing.

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 HTML to.

setCache

public void setCache(Cache cache)
Sets the Cache that this object is stored in. IncludeInstruction objects will be able to request this Cache at run-time.
Specified by:
setCache in interface Cacheable
Parameters:
cache - the Cache that this template belongs to.

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.
Specified by:
clone in interface Cacheable
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.