title: converting streams to blocks of strings and vice-versa
body: <p>I have developed a java/scala XMPP client app that sends data asynchronously using (say) a <code>write</code> method and receives data using a <code>listener</code> method. The <code>listener</code> method receives data as discrete XMPP message packets and processes them using a <code>processPacket</code> method (which I can modify based on what I want to do with the received data)</p>
  
  <p>I want to hook up a 3rd party library that reads data from an <code>inputstream</code> and writes to an <code>outputstream</code>. Specifically, I want the <code>inputstream</code> of the 3rd party library to be emulated using the data received via my <code>listener</code> method and the <code>outputstream</code> to be emulated by my <code>write</code> method.</p>
  
  <p>What would be the easiest way to do this? I know that this requires conversion from a stream to chunks of strings and vice-versa. Some hints would be appreciated. </p>
  
  <p>The XMPP message packet structure is as follows (though this can be changed if needed):</p>
  
  <pre><code>&lt;message to = ... from = ...&gt;&lt;body&gt;data&lt;/body&gt;&lt;/message&gt;
  </code></pre>