@Test public void testToString() { try { String inputWithNewLines = "test" + LINE_SEPARATOR + "test2" + LINE_SEPARATOR + "test3"; String result = IOUtil.toString(new ByteArrayInputStream(inputWithNewLines.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); assertEquals(inputWithNewLines, result); String singleLineInput = "This is a test"; result = IOUtil.toString(new ByteArrayInputStream(singleLineInput.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); assertEquals(singleLineInput, result); } catch (IOException e) { fail("Should not fail"); } }
public static String toString(InputStream input, Charset encoding) throws IOException { StringBuilder builder = new StringBuilder(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, encoding))) { String line = reader.readLine(); while (line != null) { builder.append(line).append(System.lineSeparator()); line = reader.readLine(); } } if (builder.length() > 0) builder.setLength(builder.length() - System.lineSeparator().length()); return builder.toString(); }
IOUtil { public static String toString(InputStream input, Charset encoding) throws IOException { StringBuilder builder = new StringBuilder(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, encoding))) { String line = reader.readLine(); while (line != null) { builder.append(line).append(System.lineSeparator()); line = reader.readLine(); } } if (builder.length() > 0) builder.setLength(builder.length() - System.lineSeparator().length()); return builder.toString(); } }
IOUtil { public static String toString(InputStream input, Charset encoding) throws IOException { StringBuilder builder = new StringBuilder(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, encoding))) { String line = reader.readLine(); while (line != null) { builder.append(line).append(System.lineSeparator()); line = reader.readLine(); } } if (builder.length() > 0) builder.setLength(builder.length() - System.lineSeparator().length()); return builder.toString(); } private  IOUtil(); }
IOUtil { public static String toString(InputStream input, Charset encoding) throws IOException { StringBuilder builder = new StringBuilder(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, encoding))) { String line = reader.readLine(); while (line != null) { builder.append(line).append(System.lineSeparator()); line = reader.readLine(); } } if (builder.length() > 0) builder.setLength(builder.length() - System.lineSeparator().length()); return builder.toString(); } private  IOUtil(); static String getUTF8ResourceAsString(String path); static String getResourceAsString(String path, Charset encoding); static String toString(InputStream input, Charset encoding); static String expandDirectoryPath(String path); static String expandFilePath(String path); }
IOUtil { public static String toString(InputStream input, Charset encoding) throws IOException { StringBuilder builder = new StringBuilder(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, encoding))) { String line = reader.readLine(); while (line != null) { builder.append(line).append(System.lineSeparator()); line = reader.readLine(); } } if (builder.length() > 0) builder.setLength(builder.length() - System.lineSeparator().length()); return builder.toString(); } private  IOUtil(); static String getUTF8ResourceAsString(String path); static String getResourceAsString(String path, Charset encoding); static String toString(InputStream input, Charset encoding); static String expandDirectoryPath(String path); static String expandFilePath(String path);  }