1

I faced Broken Pipe Exception while read file from my folder directory. Please go through my following code...

FileInputStream inputStream = new FileInputStream(file);
ServletOutputStream outputStream = response.getOutputStream();        
IOUtils.copy(inputStream, outputStream);
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(outputStream);

Broken Pipe occurred while copying inputStream and outputStream in IOUtils.copy(inputStream, outputStream);

How can i solve Broken Pipe? can i use PipedInputStream? Is this proper way to handle this exception.

SENTHIL SARAVANAN
  • 719
  • 1
  • 12
  • 28

1 Answers1

2

It's caused by writing to a connection that has already been closed by the peer.

In this case, the peer is either a Web browser or a Web client application.

If the former, there is nothing you can do. The user can cancel the download any time, and that will cause a broken pipe exception.

In the second case, the client application may be at fault.

In either case, there is nothing you can do about it in the server code, except log it and forget about it.

riddle_me_this
  • 8,575
  • 10
  • 55
  • 80
user207421
  • 305,947
  • 44
  • 307
  • 483
  • I accept your points.. it's correct only... But i want to fix this problem if client has good browser... – SENTHIL SARAVANAN Feb 22 '14 at 08:40
  • 1
    I don't think you can have understood. It has nothing whatsoever to do with whether the 'client has a good browser'. If the user browses away from the page, or cancels the download, that's what the user wants to do. The browser shouldn't try to keep downloading something the user no longer wants. Result at the server: broken pipe. Period. – user207421 Feb 22 '14 at 10:33