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 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 1145 2005-10-09 06:32:16Z run2000 $
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)
          Deprecated. Use the InputSource constructor instead
BinaryData(InputSource source)
          Clones an existing BinaryData instance.
BinaryData(java.io.InputStream stream)
          Deprecated. Use the InputSource constructor instead
BinaryData(java.lang.String filePath)
          Deprecated. Use the InputSource constructor instead
 
Method Summary
 java.lang.Object clone()
          Clones the current BinaryData object.
 void compile(InputSource source)
          Compiles the template from an InputSource.
 void compileFromFile(java.io.File file)
          Deprecated. Use the compile(freemarker.template.InputSource) method instead
 void compileFromFile(java.lang.String filePath)
          Deprecated. Use the compile(freemarker.template.InputSource) method instead
 void compileFromStream(java.io.InputStream stream)
          Deprecated. Use the compile(freemarker.template.InputSource) method instead
 void compileFromStream(java.io.InputStream stream, java.lang.String encoding)
          Deprecated. Use the compile(freemarker.template.InputSource) method instead
 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

@Deprecated
public BinaryData(java.lang.String filePath)
           throws java.io.IOException
Deprecated. Use the InputSource constructor instead

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.
Throws:
java.io.IOException

BinaryData

@Deprecated
public BinaryData(java.io.File file)
           throws java.io.IOException
Deprecated. Use the InputSource constructor instead

Constructs a BinaryData object by compiling it from a file. Calls compileFromFile().

Parameters:
file - a File representing the binary file to be compiled.
Throws:
java.io.IOException

BinaryData

@Deprecated
public BinaryData(java.io.InputStream stream)
           throws java.io.IOException
Deprecated. Use the InputSource constructor instead

Constructs a template by compiling it from an InputStream. Calls compileFromStream().

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

BinaryData

public BinaryData(InputSource source)
           throws java.io.IOException
Clones an existing BinaryData instance.

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

BinaryData

public BinaryData(BinaryData data)
Clones an existing BinaryData instance.

Parameters:
data - the BinaryData instance to be cloned
Method Detail

compileFromFile

@Deprecated
public void compileFromFile(java.lang.String filePath)
                     throws java.io.IOException
Deprecated. Use the compile(freemarker.template.InputSource) method instead

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.
Throws:
java.io.IOException

compileFromFile

@Deprecated
public void compileFromFile(java.io.File file)
                     throws java.io.IOException
Deprecated. Use the compile(freemarker.template.InputSource) method instead

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.
Throws:
java.io.IOException

compileFromStream

@Deprecated
public void compileFromStream(java.io.InputStream stream)
                       throws java.io.IOException
Deprecated. Use the compile(freemarker.template.InputSource) method instead

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.
Throws:
java.io.IOException

compileFromStream

@Deprecated
public void compileFromStream(java.io.InputStream stream,
                                         java.lang.String encoding)
                       throws java.io.IOException
Deprecated. Use the compile(freemarker.template.InputSource) method instead

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.
Throws:
java.io.IOException

compile

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

Specified by:
compile in interface Compileable
Parameters:
source - an InputSource 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 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.