3

I am looking for an efficient solution to the following problem:

org.xml.sax.SAXParseException: Content is not allowed in prolog

The problem is skipping (or removing) the first 3 bom bytes (if present) before unmarshalling the file (using jaxb).

I can get it to work by checking the first three bytes and then writing everything after that to a new file and using the new file, however this seems horribly inefficient.

I have tried moving the file pointer over 3 bytes if the BOM is present (and verified the pointer position ofc.) , however when I pass the inputstream to jaxb it still throws the same exception; my gut instinct being that the file pointer is being reset.

Does anyone have any ideas for this?

Thanks

Community
  • 1
  • 1
Jay Mie
  • 65
  • 1
  • 2
  • 8
  • Related: http://stackoverflow.com/q/1835430/260633 and http://stackoverflow.com/q/5353783/260633 – Dev Aug 08 '13 at 14:32

1 Answers1

5

Use a InputStream decoractor that strips the BOM such as BOMInputStream from Apache Commons IO.

Dev
  • 11,919
  • 3
  • 40
  • 53