Inability to read JPEG file from byte []

Has anyone had a problem loading jpeg files in java? One of our clients sends files that cannot be resolved, but the same files can be opened in windows. (the remaining 99% of the jpeg files we receive are processed without problems)

I tried several libraries to read them:

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 tell me that jpegs are broken, however this does not explain why they are still viewable.

If anyone has any suggestions, I would be very grateful

thanks

0
source share
1 answer

The "solution" that I spent is to run an array of bytes, which we get through our current process, which identifies the type. If this cannot determine the type, I take an array of bytes and force it to be saved in JPEG format. This can then be re-read and pushed through the current process.

A bit hacked, but it's just a couple of months of work.

Thank you all for your help!

0
source

Source: https://habr.com/ru/post/1269089/


All Articles