java - Can I create a DOM Document from an encoded UTF-8 byte array? -


my situation: have method accepts byte array. array in question encoded using utf-8 , xml message. able re-construct message using dom parser. know can create document byte array through use of bytebuffer. problem if put directly action on passed byte array, create corrupted document (if possible @ all). because array encoded xml message, encoded in utf-8. however, when decode array use of decode() method, charbuffer returned:

bytebuffer encodeddata = bytebuffer.wrap(data); charbuffer decodeddata = charset.forname("utf-8").decode(encodeddata); 

i don't know how construct document this, there no parse() methods defined in documentbuilder accept charbuffer....

could me this?

documentbuilder has parse(inputstream is) method, can create document passing in bytearrayinputstream created bytes.

document doc = documentbuilder.parse(new bytearrayinputstream(data)); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -