Reading JPEG with comments

Hello,

I want to read some jpeg images from a FTP server. Some files contains a xml comment at the beginning of the file.

If i try to read the file with eitherImageIO.read(..) or anImageReader, an exception is thrown in the form: "Not a JPEG file: starts with 0x01 0x11".

Each image throwing this exception contains a xml comment at the top. I cannot write the image temporary on the hard disk, but have to parse it on the fly.

Does anyone know how that problem can be solved? There is no really solution, what to do with comments in a jpeg.

I already tried to get the MetaData information from the ImageReader, but that call has thrown the exception, too.

Any support is welcome !

sincerly

andremo

[777 byte] By [andremoa] at [2007-11-27 5:12:55]
# 1

It's because the XML data is not valid JPEG data. The reader is testing to see that the image is a JPEG by checking the first couple of bytes. Which in the XML commenting cases, is not considered "JPEG" data. Therefore, the readers are rejecting the image as invalid. The JAI and ImageIO readers don't know how to skip past your custom XML.

Is this standard practice? Mixing a bunch of XML comments before a JPEG file? That sounds really strange to me... But I don't work with JPEG much.

In any case, you'll have to first parse the XML from the file using regular Java IO (plus sax, dom, or whatever you're using to read XML). Remove the bytes occupied by the XML data, and then read the remaining data with JAI or ImageIO (which should be just JPEG data after you've stripped the XML out).

CowKing

IamCowKinga at 2007-7-12 10:34:16 > top of Java-index,Security,Cryptography...