title: How to solve "Connection reset by peer: socket write error"?
body: <p>When I am reading the file content from server it returns the following error message:</p>
  
  <pre><code>Caused by: java.net.SocketException: Connection reset by peer: socket write error
  at java.net.SocketOutputStream.socketWrite0(Native Method)
  at java.net.SocketOutputStream.socketWrite(Unknown Source)
  at java.net.SocketOutputStream.write(Unknown Source)
  at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:215)
  at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:462)
  at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:366)
  at org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:240)
  at org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:119)
  at org.apache.coyote.http11.AbstractOutputBuffer.doWrite(AbstractOutputBuffer.java:192)
  at org.apache.coyote.Response.doWrite(Response.java:504)
  at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:383)
  ... 28 more
  </code></pre>
  
  <p>and my servlet program is</p>
  
  <pre><code> response.setContentType("application/octet-stream");
   response.setHeader("Content-Disposition","attachment;filename="+filename);
   FileInputStream in = new FileInputStream(new File(filepath));
   ServletOutputStream output=response.getOutputStream();
   byte[] outputByte=new byte[4096];
   while(in.read(outputByte,0,4096)!=-1){
       output.write(outputByte,0,4096);//error indicates in this line
   }
   in.close();
   output.flush();
   output.close();
  </code></pre>
  
  <p>How to solve this issue?</p>