title: ServletOutputStream taking too long to write
body: <p>I am trying to write a large XML file(in excess of 1.5M) to a ServletOutputStream and it takes really long time, close to 7mins or so or even longer.<br>
  What I am doing is something as follows -  </p>
  
  <pre><code>1. SOAPMessage soapRes; // Consider this is populated somewhere and we have the value here  
  2. ServletResponse res; // Consider this is populated somewhere and we have the value here  
  3. ServletOutputStream os = res.getOutputStream();  
  4. ByteArrayOutputStream baos = new ByteArrayOutputStream();  
  5. soapRes.writeTo(baos);  
  6. os.write(baos.toByteArray());  
  </code></pre>
  
  <p>in the finally -   </p>
  
  <pre><code>7. baos.close();  
  8. os.flush();  
  9. os.clse(); 
  </code></pre>
  
  <p>I thought about sub-class of <code>ServletOutputStream</code> and overriding the <code>write()</code> but cant due to class cast issue at line# 3.<br>
  I also tried with extracting the length of the content from the <code>SOAPMessage</code> and passing that value in <code>write()</code> method at line# 6 and even as a constructor argument for <code>ByteArrayOutputStream</code> line# 4 but none work.<br>
  Any suggestion is most welcome.</p>
  
  <p>NB. Forgot to mention this earlier, I am running this on a Apache Tomcat. A JUnit test has no such problem, with it this processing is very fast and is done within secs but when I run it over Tomcat, takes a long long time.</p>