开发者

Java: IOException on write in HttpServlet

I've written a proxy of sorts in Java (and Jetty). Anyway, it works great, but sometimes

...
final OutputStream realOs = res.getOutputStream();
...
InputStream is = url.openStream();
int i;
while ((i = is.rea开发者_JS百科d(buffer)) != -1) {
  realOs.write(buffer, 0, i);
}

fails with IOException. I've noticed that it mostly happens with large binary files, i.e. flash and Safari browser...

I'm puzzled...


This can happen if the browser is closed (or the user cancels the download) while you're still writing to the socket. The browser closes the socket, so your OutputStream no longer has anything to write to.

Unfortunately it's hard to tell for sure whether this is really the case - in which case it's not an issue - or whether there's something more insidious going on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜