Tuning the performance of reading a large InputStream in java
<p>I want to <strong>read a large InputStream</strong> and return it as a String.
This InputStream is a large one. So, normally it takes much time and a lot of memory while it is excuting. 
The following code is the one that I've developed so far.
I need to convert this code as it does the job in a lesser time consuming lesser memory.</p>

<p>Can you give me any idea to do this.</p>

<pre><code>BufferedReader br =
    new BufferedReader(
        new InputStreamReader(
            connection.getInputStream(),
            "UTF-8")
        );

StringBuilder response = new StringBuilder(1000);

char[] buffer = new char[4096];

int n = 0;
while(n &gt;= 0){
    n = br.read(buffer, 0, buffer.length);
    if(n &gt; 0){
        response.append(buffer, 0, n);
    }
}
return response.toString();
</code></pre>

<p>Thank you!</p>
