freemarker.template
Class BinaryData

java.lang.Object
  |
  +--freemarker.template.BinaryData

public class BinaryData
extends java.lang.Object

An application or servlet can instantiate a subclass of 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() 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 BinaryCache do this for you.

See Also:
BinaryCache

Constructor Summary
BinaryData()
          Constructs an empty template.
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
 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.
static java.lang.String formatErrorMessage(java.lang.String errorMessage)
          Used by FreeMarker classes to format an error message as an HTML comment.
 BinaryCache getBinaryCache()
          Gets the BinaryCache that this binary data file belongs to.
static java.lang.String getStackTrace(java.lang.Exception e)
          Used by FreeMarker classes to format a stack trace as a string.
 void process(java.io.OutputStream out)
          Processes the binary data file, and output the resulting binary data to an OutputStream.
 void setBinaryCache(BinaryCache cache)
          Sets the BinaryCache that this file belongs to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinaryData

public BinaryData()
Constructs an empty template.

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.
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.
Parameters:
stream - an InputStream from which the template can be read.

setBinaryCache

public void setBinaryCache(BinaryCache cache)
Sets the BinaryCache that this file belongs to. IncludeInstruction objects will be able to request this BinaryCache at run-time.
Parameters:
cache - the BinaryCache that this binary data file belongs to.

getBinaryCache

public BinaryCache getBinaryCache()
Gets the BinaryCache that this binary data file belongs to.
Returns:
the BinaryCache that this binary data file belongs to.

process

public void process(java.io.OutputStream out)
Processes the binary data file, and output the resulting binary data to an OutputStream.
Parameters:
modelRoot - the root node of the data model. If null, an empty data model is used.
out - an OutputStream to output the HTML to.

formatErrorMessage

public static java.lang.String formatErrorMessage(java.lang.String errorMessage)
Used by FreeMarker classes to format an error message as an HTML comment.

getStackTrace

public static java.lang.String getStackTrace(java.lang.Exception e)
Used by FreeMarker classes to format a stack trace as a string.