title: If a Tomcat server says "Client Aborted", and the client says "Premature EOF", who is right?
body: <p>I have a Tomcat server streaming data to a Java client over http. It is copying bytes from a file to HTTPServletResponse's outputstream in a servlet.  </p>
  
  <p>A client uses HttpURLConnection to connect and read the data.</p>
  
  <p>Sometimes all is fine, other times both the client and server throw an exception.<br>
  The client says there is a "Premature EOF".<br>
  The server claims "ClientAbortException". </p>
  
  <p>Isn't just one of the above possible?  </p>
  
  <p><strong>CLIENT:</strong></p>
  
  <pre><code>java.io.IOException: Premature EOF
         at sun.net.www.http.ChunkedInputStream.fastRead(ChunkedInputStream.java:234)
         at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:662)
         at java.io.FilterInputStream.read(FilterInputStream.java:116)
         at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2669)
         at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2664)java.io.IOException: Premature EOF
         at sun.net.www.http.ChunkedInputStream.fastRead(ChunkedInputStream.java:234)
         at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:662)
         at java.io.FilterInputStream.read(FilterInputStream.java:116)
         at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2669)
         at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2664)  
  </code></pre>
  
  <p><strong>SERVER:</strong></p>
  
  <pre><code>ClientAbortException:  java.io.IOException
      at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:358)
      at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:434)
      at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:349)
      at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:381)
      at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:370)
      at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89)
      ...
  Caused by: java.io.IOException
          at org.apache.coyote.ajp.AjpAprProcessor.flush(AjpAprProcessor.java:1223)
          at org.apache.coyote.ajp.AjpAprProcessor$SocketOutputBuffer.doWrite(AjpAprProcessor.java:1310)
          at org.apache.coyote.Response.doWrite(Response.java:560)
          at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:353)
          ... 23 more
  </code></pre>