Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why org.apache.xerces.parsers.SAXParser does not skip BOM in utf8 encoded xml?

I have an xml with utf8 encoding. And this file contains BOM a beginning of the file. So during parsing I am facing with org.xml.sax.SAXParseException: Content is not allowed in prolog. I can not remove those 3 bytes from the files. I can not load file into memory and remove them here (files are big). So for performance reasons I'm using SAX parser and want just to skip those 3 bytes if they are present before "" tag. Should I inherit InputStreamReader for this?

I'm new in java - show me the right way please.

like image 564
denys Avatar asked Mar 18 '11 14:03

denys


1 Answers

This has come up before, and I found the answer on Stack Overflow when it happened to me. The linked answer uses a PushbackInputStream to test for the BOM.

like image 98
Adrian Cox Avatar answered Oct 21 '22 07:10

Adrian Cox