Use try-close
@@ -402,13 +402,13 @@ public abstract class IOUtils {
* Reads all data from a reader into a string. Uses a buffer to speed up reading.
*/
public static String readAll(Reader reader) throws IOException {
- StringBuilder ret=new StringBuilder();
- BufferedReader buffered = new BufferedReader(reader);
+ StringBuilder sb = new StringBuilder();
+ try (BufferedReader buffered = new BufferedReader(reader)) {
int c;
while ((c = buffered.read()) != -1)
- ret.appendCodePoint(c);
- buffered.close();
- return ret.toString();
+ sb.appendCodePoint(c);
+ }
+ return sb.toString();
}
/** Read an input stream completely into a string */
