I have two queries as follows: a) What is the difference between response content types text/pdf and application/pdf ? 2) In my application i am generating a xml.In the generated XML the encoding is alreadys specified as "UTF-8".
Now using this xml, i want to generated a PDF.For generating this PDF i am using JasperReport's class net.sf.jasperreports.engine.data.JRXmlDataSource.
The code snippet for the same is as follows:
Buw when the following line is executed :
i am getting this exception :
Can anybody please explain me why this is happening and how to resolve this ?
The Art Of Life Is To Know When To Be Useless And When To Be Useful - CHUANG TZU
The first two bytes of a Unicode file are a marker code to determine byte ordering in the file. It appears, as a preliminary guess, that you are getting a xmlDataBuffer and using it as a JRXmlDataSource, the UTFDataFormatException tells us that this first and second byte are not an 0xfe 0xff pair. The obvious place to look is dig deep in the documentaion for the two data types looking for any and all information on the BOM implementation ( BOM == byte order mark )
Byte Order Mark. The Unicode character U+FEFF when used to indicate the byte order of a text
Your XML document declares that it is encoded in UTF-8. But you disregarded that, and encoded it to bytes using your system's default encoding, which is not UTF-8. So if the document contained non-ASCII characters, they would have been mangled. Here's what you want instead:
Actually I would try to avoid what you are doing, which is to convert chars to bytes and then have the parser convert the bytes back to chars. Even if you do it right, it's wasteful. If JRXmlDataSource has a constructor that takes a Reader, or an InputSource, then use a StringReader containing xmlDataBuffer.toString().