From ffc06b1a16b0d64fc88e80c664c9f3c33403399e Mon Sep 17 00:00:00 2001 From: Mark Robert Miller Date: Sun, 3 Mar 2013 17:30:05 +0000 Subject: [PATCH] SOLR-4210: More efficient stream copying git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1452069 13f79535-47bb-0310-9956-ffa450edef68 --- .../solr/servlet/SolrDispatchFilter.java | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java index 6226736559f..c927de3e127 100644 --- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java +++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java @@ -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();