简体   繁体   English

如何解决Java中的管道损坏?

[英]How to solve Broken Pipe in Java?

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); 在IOUtils.copy(inputStream,outputStream)中复制inputStream和outputStream时发生管道破裂。

How can i solve Broken Pipe? 我该如何解决断管问题? can i use PipedInputStream? 我可以使用PipedInputStream吗? Is this proper way to handle this exception. 这是处理此异常的正确方法。

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. 在这种情况下,对等方是Web浏览器或Web客户端应用程序。

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. 无论哪种情况,在服务器代码中您都无能为力,只能记录并忘记它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM