title: efficient input stream to string method in java
body: <p>So I was running a profiler on my (admittedly pretty simple) application in Java, and was surprised that second only to methods that required making HTTP requests in terms of time was my <code>inputStreamToString</code> method. It's currently defined like this:</p>
  
  <pre><code>public static String inputStreamToString(InputStream in) throws IOException {
      BufferedReader reader = new BufferedReader(new InputStreamReader(in));
      StringBuilder sb = new StringBuilder();
      String line = null;
      while ((line = reader.readLine()) != null) {
          sb.append(line).append("\n");
      }
      in.close();
      return sb.toString();
  }
  </code></pre>
  
  <p>How can I make this faster? (And yes, I really do need strings, and no, the InputStrings aren't that large, and no, this method is being called less frequently than most methods in the program, and no, I there is no way to avoid the need of conversion.)</p>