public static void testReadLine() throws IOException { final String input = " hello world\nthis is \r\n just an example\r\nthis is line 2 \r\n"; String line; InputStream in = new BufferedInputStream(new ByteArrayInputStream(input.getBytes())); List<String> list = new ArrayList<>(4); for (int i = 0; i < 4; i++) { line = Util.readLine(in); System.out.println("line = \"" + line + "\""); list.add(line); } assert list.size() == 4; }