That sounds weird. As far as I know the servlet response data section contains exactly the bytes you write to it.

Are you using a browser to access the servlet ?

Are you 100% sure that the browser is not pretty printing the XML
and the removing the enconding attribute (it is redundant since UTF-8 is the standard encoding).

Try using netcat, curl or wget to access the servlet. This way you can be...