SOLR-4210: More efficient stream copying

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1452069 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-03-03 17:30:05 +00:00
parent 2e7651f407
commit ffc06b1a16
1 changed files with 15 additions and 24 deletions

View File

@ -20,6 +20,8 @@ package org.apache.solr.servlet;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
@ -350,22 +352,14 @@ public class SolrDispatchFilter implements Filter
}
try {
con.connect();
int theByte;
if (req.getMethod().equals("POST")) {
BufferedInputStream bis = new BufferedInputStream(
req.getInputStream());
BufferedOutputStream os = new BufferedOutputStream(
con.getOutputStream());
try {
while ((theByte = bis.read()) != -1) {
os.write(theByte);
}
os.flush();
} finally {
IOUtils.closeQuietly(os);
IOUtils.closeQuietly(bis);
}
InputStream is = req.getInputStream();
OutputStream os = con.getOutputStream();
try {
IOUtils.copyLarge(is, os);
} finally {
IOUtils.closeQuietly(os);
IOUtils.closeQuietly(is); // TODO: I thought we weren't supposed to explicitly close servlet streams
}
resp.setStatus(con.getResponseCode());
@ -380,16 +374,13 @@ public class SolrDispatchFilter implements Filter
resp.setCharacterEncoding(con.getContentEncoding());
resp.setContentType(con.getContentType());
BufferedInputStream bis = new BufferedInputStream(con.getInputStream());
ServletOutputStream os = resp.getOutputStream();
is = con.getInputStream();
os = resp.getOutputStream();
try {
while ((theByte = bis.read()) != -1) {
os.write(theByte);
}
os.flush();
IOUtils.copyLarge(is, os);
} finally {
IOUtils.closeQuietly(os);
IOUtils.closeQuietly(bis);
IOUtils.closeQuietly(os); // TODO: I thought we weren't supposed to explicitly close servlet streams
IOUtils.closeQuietly(is);
}
} finally {
con.disconnect();