title: Passing an InputStream via subreportExpression in JasperReports
body: <p>I have a problem with a JasperReports's report because I'm using a Spring-boot framework. Instead of the absolute path in a subreport expression tag, I need to pass a InputStream. </p>
  
  <p>Hence, I add a parameter with this InputStream:</p>
  
  <pre><code>Map&lt;String, Object&gt; parameters = new HashedMap();
  parameters.put("STREAM_SUBREPORT",classLoader.getResource(subreport_filename).openStream());
  </code></pre>
  
  <p>and in the jrxml a have the following subreport definition</p>
  
  <pre><code>&lt;subreportParameter name="ItemDataSource"&gt;
      &lt;subreportParameterExpression&gt;&lt;![CDATA[$P{ItemDataSource}]]&gt;&lt;/subreportParameterExpression&gt;
  &lt;/subreportParameter&gt;
  &lt;dataSourceExpression&gt;&lt;![CDATA[$P{ItemDataSource}]]&gt;&lt;/dataSourceExpression&gt;
  &lt;subreportExpression&gt;&lt;![CDATA[$P{STREAM_SUBREPORT}]]&gt;&lt;/subreportExpression&gt;
  </code></pre>
  
  <p>My Java Code is:</p>
  
  <pre><code>JasperDesign jd = null;
  try {
      jd = JRXmlLoader.load(classLoader.getResource(REPORT_PATH).openStream());
  
  } catch (IOException e) {
     ...
  }
  JasperReport report = JasperCompileManager.compileReport(jd);
  JasperPrint print = JasperFillManager.fillReport(report, parameters, ds);
  </code></pre>
  
  <p>The definition of the subreport that I try to pass is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  --&gt;
  &lt;!-- 2017-04-02T23:37:54 --&gt;
  &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="submissions_subreport_summary" pageWidth="595" pageHeight="842" whenNoDataType="BlankPage" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="408f425e-96dc-41a9-991e-2208c3c8a120"&gt;
      &lt;property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/&gt;
      &lt;property name="com.jaspersoft.studio.data.sql.tables" value=""/&gt;
      &lt;property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w1" value="233"/&gt;
      &lt;property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w2" value="756"/&gt;
      &lt;parameter name="ItemDataSourceSummary" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/&gt;
      &lt;field name="title" class="java.lang.String"/&gt;
      &lt;field name="details" class="java.lang.String"/&gt;
      &lt;title&gt;
          &lt;band height="15"&gt;
              &lt;property name="com.jaspersoft.studio.unit.height" value="pixel"/&gt;
              &lt;staticText&gt;
                  &lt;reportElement x="2" y="0" width="123" height="12" uuid="782e96a2-5db0-458a-9078-63d470b2e155"&gt;
                      &lt;property name="com.jaspersoft.studio.unit.height" value="pixel"/&gt;
                      &lt;property name="com.jaspersoft.studio.unit.width" value="pixel"/&gt;
                  &lt;/reportElement&gt;
                  &lt;box&gt;
                      &lt;bottomPen lineWidth="1.0"/&gt;
                  &lt;/box&gt;
                  &lt;textElement&gt;
                      &lt;font isBold="true"/&gt;
                  &lt;/textElement&gt;
                  &lt;text&gt;&lt;![CDATA[Subreport Caption]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
          &lt;/band&gt;
      &lt;/title&gt;
      &lt;detail&gt;
          &lt;band height="35"&gt;
              &lt;property name="com.jaspersoft.studio.unit.height" value="pixel"/&gt;
              &lt;textField&gt;
                  &lt;reportElement x="0" y="0" width="280" height="30" uuid="6f92584d-1738-4d79-b169-2f544152341b"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{title}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement x="280" y="0" width="270" height="30" uuid="579b2443-f865-4422-888d-d995ffdfbdc5"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{details}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/band&gt;
      &lt;/detail&gt;
  &lt;/jasperReport&gt;
  </code></pre>
  
  <p>But, I got the exception by the JasperFillManager method,</p>
  
  <pre><code>net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: $P{STREAM_SUBREPORT}
  </code></pre>
  
  <p>I try with the follow cast in the jrxml </p>
  
  <pre><code>&lt;subreportExpression&gt;&lt;![CDATA[(java.io.InputStream($P{DIR_SUBREPORT_SUBMISSION}))]]&gt;&lt;/subreportExpression&gt;
  </code></pre>
  
  <p>but also got an exception</p>
  
  <pre><code>net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
  1. java.io cannot be resolved to a type
                  value = (java.io.InputStream(((java.lang.String)parameter_STREAM_SUBREPORT.getValue()))); //$JR_EXPR_ID=11$
  </code></pre>
  
  <p>Any suggestions would be welcome!</p>