java - converting streams to blocks of strings and vice-versa -


i have developed java/scala xmpp client app sends data asynchronously using (say) write method , receives data using listener method. listener method receives data discrete xmpp message packets , processes them using processpacket method (which can modify based on want received data)

i want hook 3rd party library reads data inputstream , writes outputstream. specifically, want inputstream of 3rd party library emulated using data received via listener method , outputstream emulated write method.

what easiest way this? know requires conversion stream chunks of strings , vice-versa. hints appreciated.

the xmpp message packet structure follows (though can changed if needed):

<message = ... = ...><body>data</body></message> 

use bytearrayinputstream create input stream given string. have think encoding, because sending bytes instead of characters.

string text = message.getbody();  // that's need? inputstream = new bytearrayinputstream(text.getbytes("utf-8")); 

for other way round, write bytearrayoutputstream , create new string it's bytes:

string text = new string( baos.tobytearray(), "utf-8" ); 

again - don't forget think character encoding.


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? -