When I was trying to parse xml using sax over sockets I came across a strange occurence.
Upon analysing I noticed that DataOutputStream adds 2 bytes in front of my data.
Always use the same type of stream when reading and writing data. If you are feeding the stream directly into a sax parser, then you should not use a DataOutputStream.
Just use
BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
bos.write(os.getBytes("UTF-8"));