##### Feeding input/output stream to JReport Engine

By feeding input/output stream instead of files to JReport Engine, you can control the input/output stream via the stream API directly.

The stream API consists of two types of function APIs:

- Input stream API for feeding data via InputStream to JReport Engine.
- Output stream API for retrieving exported report via OutputStream from JReport Engine.

###### Input stream API

Input stream API provides a programmable way to specify data for JReport products besides the URI.

For supporting input stream API, the following requirements should be met:

- Relational XML data source or hierarchical XML data source.
- XML format data input stream from which JReport Engine fetches data.

An interface Jet.datasource.InputStreamFactory is provided in the Engine Bean for you to implement so that JReport Engine can create your customized InputStream instance from your InputStreamFactory implementation. The following is the method in the interface:

- createInputStream()
  Creates a new input stream.

Except for implementing the InputStreamFactory interface, you need also call either of the two methods in order to use input stream:

- setXmlStreamFactory (java.lang.String datasourceName, InputStreamFactory streamFactory)
  Sets customer class which implements InputStreamFactory for Relational XML Data Source.

  Parameters:

  - datasourceName - Indicates data source name.
  - streamFactory - User implemented InputStreamFactory.
- setHDSStreamFactory (java.lang.String datasourceName, java.lang.String HDSName, InputStreamFactory streamFactory)
  Sets customer class which implements InputStreamFactory for Hierarchical XML Data Source.

  Parameters:

  - datasourceName - Indicates data source name.
  - HDSName - Indicates Hierarchical XML Data Source name, also as the folder name following the path Data_Source_Name\Hierarchical.
  - streamFactory - User implemented HDS InputStreamFactory.

Reference: See the demo XmlStreamSample.java for input stream API usage in `<install_root>\help\designer\samples`.

###### Output stream API

Output stream API enables exporting current report and specified result file as output stream in common file formats, such as PDF, RTF, Excel, Text, and PostScript.

You can use output stream API as follows:

    ... ... JREngine bean = new JREngine();
    bean.setReportHome(ReportHome);
    ... ...//initialize bean
    OutputStream output=new FileOutputStream("filename");
    ... ...//initialize outputstream
    bean.exportToPdf(output); ... ...