java.io.EOFException: Unexpected end of ZLIB input stream解决
来源:互联网 发布:java方法泛型 t.class 编辑:程序博客网 时间:2024/05/23 19:35
EOFException
表示异常文件结尾,说明读取的数据是不完整的。我在线上就遇到过类似的问题,在请求高峰时期就抛出了这个异常。下面是我的代码:
FileOutputStream fileOutputStream = null; try { //得到文件 File file = new File(fileName); fileOutputStream = new FileOutputStream(file); IOUtils.write(dataByte, fileOutputStream); // 在这里及时的close掉fileOutputStream //读取图片 BufferedImage bi = ImageIO.read(file); pictureProcessVo.setWidth(bi.getWidth()); //获得 宽度 pictureProcessVo.setHeight(bi.getHeight()); //获得 高度 // other operation // delete file FileUtils.deleteQuietly(file); } catch (Exception e) { LOGGER.error("get pic width and height error", e); } finally { IOUtils.closeQuietly(fileOutputStream); }
出现的异常:
javax.imageio.IIOException: Error reading PNG image data at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1345) at com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1614) at javax.imageio.ImageIO.read(ImageIO.java:1448) at javax.imageio.ImageIO.read(ImageIO.java:1308) at me.ele.commodity.spu.service.impl.CommodityDataProcessServiceImpl.downloadPicture(CommodityDataProcessServiceImpl.java:164) at me.ele.commodity.spu.service.impl.CommodityDataProcessServiceImpl.getCheckedPicList(CommodityDataProcessServiceImpl.java:207) at me.ele.commodity.spu.service.impl.CommodityDataProcessServiceImpl.asyncPictureListAndDataLog(CommodityDataProcessServiceImpl.java:88) at sun.reflect.GeneratedMethodAccessor327.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:115) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:748)Caused by: java.io.EOFException: Unexpected end of ZLIB input stream at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:240) at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158) at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) at java.io.BufferedInputStream.read1(BufferedInputStream.java:286) at java.io.BufferedInputStream.read(BufferedInputStream.java:345) at java.io.DataInputStream.readFully(DataInputStream.java:195) at com.sun.imageio.plugins.png.PNGImageReader.decodePass(PNGImageReader.java:1119) at com.sun.imageio.plugins.png.PNGImageReader.decodeImage(PNGImageReader.java:1223) at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1338) ... 17 more
当往输出流fileOutputStream里写数据的时候,如果fileOutputStream没有及时的close掉,导致数据不完整。在一个流里,close操作可以将缓冲的数据给冲出来,或会在生成的文件里填充一些信息。所以往输出流里写数据然后到一个具体的文件,及时的close掉输出流是很有必要的。
另外这个代码也是有问题的,并发访问的时候,如果图片文件名相同也会导致生成的图片出现问题,线程1
读取data byte array生成了图片1
,准备去读取图片1
,然后线程2
开始生成相同文件名的图片去覆盖图片1
,然后线程1
读取到了数据不完整的图片1
而出现异常。
可以参考另外一个例子:
http://blog.csdn.net/Revivedsun/article/details/52073554
阅读全文
0 0
- java.io.EOFException: Unexpected end of ZLIB input stream解决
- java.io.EOFException: Unexpected end of ZLIB input stream
- java.io.EOFException: Unexpected end of ZLIB input stream异常处理
- java.io.EOFException: Unexpected end of input stream
- hive Caused by: java.io.EOFException: Unexpected end of input stream排查
- JAVA_SAE_Fatal_error: Unexpected end of ZLIB input stream
- Unexpected end of ZLIB input stream
- Unexpected end of ZLIB input stream的解决办法
- java.io.IOException: unexpected end of stream
- 使用GZIPOutputStream解压byte[]出现Unexpected end of ZLIB input stream的解决方法
- maven打包异常, Error creating shaded jar: Unexpected end of ZLIB input stream
- java.io.IOException: unexpected end of stream on okhttp3.Address
- Unexpected end of stream.
- java.net.ProtocolException: unexpected end of stream
- java.io.EOFException: No content to map to Object due to end of input
- java.io.EOFException: No content to map to Object due to end of input
- java.io.EOFException: No content to map to Object due to end of input
- java.io.IOException: unexpected end of stream on okhttp3.Address@33c2c47
- 综合影响力模型InfG算法
- HDU6053TrickGCD
- jquery 获取 input 名为数组
- Ubuntu安装中文输入法
- matlab中findstr 与 strfind的两个函数举例
- java.io.EOFException: Unexpected end of ZLIB input stream解决
- pycharm常用设置(keymap设置及eclipse常用快捷键总结)
- 状态模式
- JVM虚拟机学习笔记01:类的加载、连接、初始化
- Kotlin学习笔记(1):标签
- mysql 如何定义游标-存储过程
- 二维数组中有关指针总结
- SSM框架搭建流程(本小白个人用)
- Android 自定义漂亮的圆形进度条