So, I ran the profiler on my (albeit fairly simple) Java application and was surprised that the second only for methods that required making HTTP requests in terms of time is my inputStreamToString method. It is currently defined as follows:
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(); }
How can I do it faster? (And yes, I really need strings, and no, InputStrings are not that big, and no, this method is called less often than most methods in the program, and no, I canβt avoid the need for conversion.)
source share