我正在开发一个模块,用作其他REST服务的代理(用于访问控制等内容)。我的代理( P )后面的一项服务(假设 S )返回分组响应,范围从20KB到5MB。
在我的代理模块中,当我尝试将inputStream从 S 复制到 P 的outputStream时,我遇到以下异常:
2014-05-29 00:19:49,841 [] - org.eclipse.jetty.io.EofException
2014-05-29 00:19:49,841 [] - org.eclipse.jetty.io.EofException
2014-05-29 00:19:49,841 [] - at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:187)
2014-05-29 00:19:49,841 [] - at org.eclipse.jetty.io.WriteFlusher.write(WriteFlusher.java:335)
2014-05-29 00:19:49,841 [] - at org.eclipse.jetty.io.AbstractEndPoint.write(AbstractEndPoint.java:125)
2014-05-29 00:19:49,841 [] - at org.eclipse.jetty.server.HttpConnection$ContentCallback.process(HttpConnection.java:639)
2014-05-29 00:19:49,841 [] - at org.eclipse.jetty.util.IteratingCallback.iterate(IteratingCallback.java:80)
2014-05-29 00:19:49,841 [] - at org.eclipse.jetty.server.HttpConnection.send(HttpConnection.java:296)
2014-05-29 00:19:49,841 [] - at org.eclipse.jetty.server.HttpChannel.sendResponse(HttpChannel.java:703)
2014-05-29 00:19:49,841 [] - at org.eclipse.jetty.server.HttpChannel.write(HttpChannel.java:733)
2014-05-29 00:19:49,841 [] - at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:294)
由于某种原因,outputStream似乎关闭了(破坏管道错误),而inputStream已被部分复制到其中。
copyStream方法就像这样 -
public static void copyStream(InputStream input, OutputStream output)
throws IOException {
byte[] buffer = new byte[1024];
int bytesRead;
if (input == null)
return;
while ((bytesRead = input.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
}
任何关于此的指示都会有所帮助。