Permalink
Browse files

added better stream closing

  • Loading branch information...
jeichar
jeichar committed Apr 20, 2010
1 parent 3d05eb1 commit c00933b029f3b87096c64665eb5acc5f2d6363aa
Showing with 24 additions and 7 deletions.
  1. +24 −7 owsproxyclient/src/com/camptocamp/owsproxy/OWSProxyServlet.java
@@ -92,18 +92,15 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
Header[] headers = method.getResponseHeaders();
for (Header h : headers) {
// XXX override some headers?
if("Transfer-Encoding".equalsIgnoreCase(h.getName()) && "chunked".equalsIgnoreCase(h.getValue()))
continue;
if (!ieBugCausingHeader(h)) {
response.setHeader(h.getName(), h.getValue());
}
}
byte[] cache = new byte[response.getBufferSize()];
InputStream in = method.getResponseBodyAsStream();
ServletOutputStream out = response.getOutputStream();
for (int read = in.read(cache); read > 0; read = in.read(cache)) {
out.write(cache, 0, read);
}
efficientWrite(response, method);
if (statusCode != HttpStatus.SC_OK) {
handleError(method, statusCode, method.getResponseBody());
return;
@@ -127,6 +124,26 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
}
}
private void efficientWrite(HttpServletResponse response, HttpMethod method)
throws IOException {
byte[] cache = new byte[response.getBufferSize()];
InputStream in = method.getResponseBodyAsStream();
ServletOutputStream out = response.getOutputStream();
try {
for (int read = in.read(cache); read > 0; read = in.read(cache)) {
out.write(cache, 0, read);
}
} finally {
try {
in.close();
}finally {
out.close();
}
}
}
private void configureSSH() throws MalformedURLException {
File keystore = new File(connectionParams.keystore);

0 comments on commit c00933b

Please sign in to comment.