Failure to read JPEG file from byte[]

半腔热情 提交于 2019-12-29 09:15:07

问题


Has anyone ever had an issue with Loading JPEG files in java? One of our clients is sending files that cannot be resolved, but these same files can be opened in windows. (the other 99% of jpeg files we recieve, process without any problems)

I have tried a couple of libraries to read these:

itextpdf : com.itextpdf.text.Jpeg (getInstance(imageData) - gives  "java.io.IOException: Premature EOF while reading JPG."
sanselan : org.apache.sanselan.ImageInfo ( Sanselan.getImageInfo(imageData) gives "java.io.IOException: Invalid Segment: insufficient data")
where imageData is a byte[]

The errors here suggest to me that the jpegs are broken, however, this does not explain why they are still viewable.

If anyone has any suggestions, I would be most grateful

Thanks


回答1:


The "solution" I have gone for is to run the byte array we recieve through our current process which identifies type. If this can't identify the type, then I take the byte array and forcably save it to a JPEG. This can then be re read and pushed back through the current process.

Bit hacky, but its just a work around for a couple of months.

Thanks for everyone's help here!



来源:https://stackoverflow.com/questions/11885853/failure-to-read-jpeg-file-from-byte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!