<p>I currently use the following function to do a simple HTTP GET.</p>

<pre><code>public static String download(String url) throws java.io.IOException {
    java.io.InputStream s = null;
    java.io.InputStreamReader r = null;
    //java.io.BufferedReader b = null;
    StringBuilder content = new StringBuilder();
    try {
        s = (java.io.InputStream)new URL(url).getContent();

        r = new java.io.InputStreamReader(s);
        //b = new java.io.BufferedReader(r);

        char[] buffer = new char[4*1024];
        int n = 0;
        while (n &gt;= 0) {
            n = r.read(buffer, 0, buffer.length);
            if (n &gt; 0) {
                content.append(buffer, 0, n);
            }
        }
    }
    finally {
        //if (b != null) b.close();
        if (r != null) r.close();
        if (s != null) s.close();
    }
    return content.toString();
}
</code></pre>

<p>I see no reason to use the <code>BufferedReader</code> since I am just going to download everything in sequence. Am I right in thinking there is no use for the <code>BufferedReader</code> in this case?</p>

[{'answer_id': 31392, 'author': 'mmattax', 'author_id': 1638, 'author_profile': 'https://Stackoverflow.com/users/1638', 'pm_score': 1, 'selected': False, 'text': '<p>You are correct, if you use BufferedReader for reading HTTP content and headers you will want InputStreamReader so you can read byte for byte. </p>\n\n<p>BufferedReader in this scenario sometimes does weird things...escpecially when it comes to reading HTTP POST headers, sometimes you will be unable to read the POST data, if you use the InputStreamReader you can read the content length and read that many bytes...</p>\n'}, {'answer_id': 31395, 'author': 'Allain Lalonde', 'author_id': 2443, 'author_profile': 'https://Stackoverflow.com/users/2443', 'pm_score': 0, 'selected': False, 'text': "<p>My gut tells me that since you're already performing buffering by using the byte array, it's redundant to use the BufferedReader.</p>\n"}, {'answer_id': 32509, 'author': 'McDowell', 'author_id': 304, 'author_profile': 'https://Stackoverflow.com/users/304', 'pm_score': 3, 'selected': True, 'text': '<p>In this case, I would do as you are doing (use a byte array for buffering and not one of the stream buffers).</p>\n\n<p>There are exceptions, though. One place you see buffers (output this time) is in the servlet API. Data isn\'t written to the underlying stream until <em>flush()</em> is called, allowing you to buffer output but then dump the buffer if an error occurs and write an error page instead. You might buffer input if you needed to reset the stream for rereading using <em>mark(int)</em> and <em>reset()</em>. For example, maybe you\'d inspect the file header before deciding on which content handler to pass the stream to.</p>\n\n<p>Unrelated, but I think you should rewrite your stream handling. This pattern works best to avoid resource leaks:</p>\n\n<pre><code>    InputStream stream = new FileInputStream("in");\n    try { //no operations between open stream and try block\n        //work\n    } finally { //do nothing but close this one stream in the finally\n        stream.close();\n    }\n</code></pre>\n\n<p>If you are opening multiple streams, nest try/finally blocks.</p>\n\n<p>Another thing your code is doing is making the assumption that the returned content is encoded in your VM\'s default character set (though that might be adequate, depending on the use case).</p>\n'}, {'answer_id': 2087785, 'author': 'Harsh Bandlish', 'author_id': 253376, 'author_profile': 'https://Stackoverflow.com/users/253376', 'pm_score': 1, 'selected': False, 'text': '<p>Each invocation of one of an <a href="http://docs.oracle.com/javase/8/docs/api/java/io/InputStreamReader.html" rel="nofollow noreferrer">InputStreamReader</a>\'s read() methods may cause one or more bytes to be read from the underlying byte-input stream. To enable the efficient conversion of bytes to characters, more bytes may be read ahead from the underlying stream than are necessary to satisfy the current read operation.</p>\n'}]
['https://Stackoverflow.com/questions/31380', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/338/']