Created
December 23, 2015 21:57
Revisions
-
Jezza created this gist
Dec 23, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ public class IO { public static final int EOL = -1; public static final int DEFAULT_BUFFER_SIZE = 4096; public static final String SCANNER_END_OF_FILE_TOKEN = "\\A"; public static String toString(Reader in) throws IOException { char[] arr = new char[DEFAULT_BUFFER_SIZE]; StringBuilder buffer = new StringBuilder(); int numCharsRead; while ((numCharsRead = in.read(arr, 0, DEFAULT_BUFFER_SIZE)) != EOL) buffer.append(arr, 0, numCharsRead); return buffer.toString(); } public static String toString(InputStream in) throws IOException { try (Scanner s = new Scanner(in).useDelimiter(SCANNER_END_OF_FILE_TOKEN)) { return s.hasNext() ? s.next() : ""; } } }