1

入力: 1. メンバ InputStream を持つクラス

public class Dateien {
...
   private InputStream payload = null;
...
   public InputStream getPayload() {
       return payload;
   }
   public void setPayload(InputStream payload) {
     this.payload = payload;
   }
}
  1. ペイロードには、画像付きのストリーム (jpg またはその他の形式) が含まれます
  2. テキスト フィールド (class=java.lang.String, expression=$F{file.payload}) を含む Jasper レポートでは、レポートに正しい文字列が表示されます

    java.io.ByteArrayInputStream@6aa27760
    
  3. しかし、レポートに画像フィールドを作成すると(class=java.io.InputStream, expression=$F{file.payload})

  4. 例外が発生します

     SEVERE: Servlet.service() for servlet [appServlet] in context with path [/abc] threw exception [Request processing failed; nested exception is
     net.sf.jasperreports.engine.JRException: Image read failed.] with root cause
     net.sf.jasperreports.engine.JRException: Image read failed.
     at net.sf.jasperreports.engine.util.JRJdk14ImageReader.readImage(JRJdk14ImageReader.java:73)
    

問題を解決するにはどうすればよいですか?

ところで、ブラウザで HTTP 経由で画像ストリームを取得しようとしましたが、適切にレンダリングされた画像が表示されます。したがって、ストリームは問題なく、破損していないことがわかります。

4

1 に答える 1

1

net.sf.jasperreports.engine.util.JRJdk14ImageReaderクラスの行番号 73 で例外が発生しました。

メソッドのソースコードJRJdk14ImageReader.readImage(byte[]):

public Image readImage(byte[] bytes) throws JRException
{
    InputStream bais = new ByteArrayInputStream(bytes);

    Image image = null;
    try
    {
        image = ImageIO.read(bais);
    }
    catch (Exception e)
    {
        throw new JRException(e);
    }
    finally
    {
        try
        {
            bais.close();
        }
        catch (IOException e)
        {
        }
    }

    if (image == null)
    {
        throw new JRException("Image read failed."); // the line #73
    }

    return image;
}

ご覧のとおり、画像がまだ null の場合に例外がスローされます。

実際にバイト配列 ( ) をペイロードフィールドbyte[]としてレポートに 渡していることを確認する必要があります。

于 2013-07-03T11:43:05.843 に答える