Binary Mode Output |
Active Web |
BinaryMode is a feature new in Active Web, it allows developers to generate binary output from a script page instead of encoded characters.
In non binary mode (the default) all output is buffered by Active Web. Once the page has completed execution all the headers specified in the response object are added to the Http response generated by Active Web; the output from the executing script then written to the requesting client.
When the response is switched into binary mode using the setBinaryMode() function all of the headers and content type specified in the response object are used in the HTTP response sent to the client browser. Any changes to the response object following a call to setBinaryMode will have no effect on the response sent to the client. The response object will still update in the executing script.
For this reason, as an example should you wish to spool a PDF document from a data file then the script must set the contentType of the response prior to calling the setBinaryMode() function. Failure to do so would result in the PDF document being written to the client browser but with a content type of text/html (the default for an XSP page) and not application/pdf.
Once you switch your script is in binary mode you write data in the same way as you always did using the write() or writeln() functions. The only difference being that certain Script objects behave in different ways when they are passed to the functions. The script objects behaving differently are the File, BinaryFile objects.
If an object of these types is passed to the write() or writeln() functions then the bytes contained within the File (binary or otherwise) and the large object are written to the output of the page.
If you instantiate your own Java object in script page then these too can be written in binary mode. To do this your Java object needs to implement an Active Web Java interface com.northgateis.xa.ByteOutputInterface; the interface is supplied in the concerto.jar file found in the WEB-INF/lib directory of the concerto.war web application archive distribution.
public interface ByteOutputInterface {
public InputStream getByteStream() throws IOException;
public long byteLength();
}
Click here to see an example of outputting a PDF document from a script page.
Topic ID: 150036