Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top