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.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
@ -351,21 +353,13 @@ public class SolrDispatchFilter implements Filter
try { try {
con.connect(); con.connect();
int theByte; InputStream is = req.getInputStream();
if (req.getMethod().equals("POST")) { OutputStream os = con.getOutputStream();
BufferedInputStream bis = new BufferedInputStream(
req.getInputStream());
BufferedOutputStream os = new BufferedOutputStream(
con.getOutputStream());
try { try {
while ((theByte = bis.read()) != -1) { IOUtils.copyLarge(is, os);
os.write(theByte);
}
os.flush();
} finally { } finally {
IOUtils.closeQuietly(os); IOUtils.closeQuietly(os);
IOUtils.closeQuietly(bis); IOUtils.closeQuietly(is); // TODO: I thought we weren't supposed to explicitly close servlet streams
}
} }
resp.setStatus(con.getResponseCode()); resp.setStatus(con.getResponseCode());
@ -380,16 +374,13 @@ public class SolrDispatchFilter implements Filter
resp.setCharacterEncoding(con.getContentEncoding()); resp.setCharacterEncoding(con.getContentEncoding());
resp.setContentType(con.getContentType()); resp.setContentType(con.getContentType());
BufferedInputStream bis = new BufferedInputStream(con.getInputStream()); is = con.getInputStream();
ServletOutputStream os = resp.getOutputStream(); os = resp.getOutputStream();
try { try {
while ((theByte = bis.read()) != -1) { IOUtils.copyLarge(is, os);
os.write(theByte);
}
os.flush();
} finally { } finally {
IOUtils.closeQuietly(os); IOUtils.closeQuietly(os); // TODO: I thought we weren't supposed to explicitly close servlet streams
IOUtils.closeQuietly(bis); IOUtils.closeQuietly(is);
} }
} finally { } finally {
con.disconnect(); con.disconnect();