错误ZLIB输入流的意外结束

时间:2013-04-30 08:42:14

标签: java

InputStream转换为BufferedImage时,我收到以下错误

byte[] imgBytes = decoder.decode(encodedStr);

这一行正常运行并正确生成字节数组

InputStream in = new ByteArrayInputStream(imgBytes);
BufferedImage  bImageFromConvert = ImageIO.read(in);

由于无法正确阅读InputStream

,此行会出错
Below is the error
    javax.imageio.IIOException: Error reading PNG image data
      at com.sun.imageio.plugins.png.PNGImageReader.readImage(Unknown Source)
      at com.sun.imageio.plugins.png.PNGImageReader.read(Unknown Source)
      at javax.imageio.ImageIO.read(Unknown Source)
      at javax.imageio.ImageIO.read(Unknown Source)
      at DecodeSignatureFile.generateImage(DecodeSignatureFile.java:252)
      at DecodeSignatureFile.getContents(DecodeSignatureFile.java:176)
      at DecodeSignatureFile.process(DecodeSignatureFile.java:322)
      at DecodeSignatureFile.main(DecodeSignatureFile.java:334)
Caused by: java.io.EOFException: Unexpected end of ZLIB input stream
      at java.util.zip.InflaterInputStream.fill(Unknown Source)
      at java.util.zip.InflaterInputStream.read(Unknown Source)
      at java.io.BufferedInputStream.fill(Unknown Source)
      at java.io.BufferedInputStream.read1(Unknown Source)
      at java.io.BufferedInputStream.read(Unknown Source)
      at java.io.DataInputStream.readFully(Unknown Source)
      at com.sun.imageio.plugins.png.PNGImageReader.decodePass(Unknown Source)
      at com.sun.imageio.plugins.png.PNGImageReader.decodeImage(Unknown Source)
      ... 8 more

1 个答案:

答案 0 :(得分:0)

之前可能发生错误。在Java中,字符串encodedStr通常不适合保存二进制数据。将imgBytes与原始图片进行比较。

当然这取决于编码和解码。但其余的看起来还不错。