IoUtils { public static String toUtf8String(InputStream is) { return new String(toByteArray(is), StandardCharsets.UTF_8); } private  IoUtils(); static byte[] toByteArray(InputStream is); static String toUtf8String(InputStream is); static String readUtf8File(String path); static String readUtf8File(Path path); static String readUtf8Resource(ClassLoader classLoader, String resourcePath); static String readUtf8Resource(Class<?> clazz, String resourcePath); static String readUtf8Url(URL url); static String runCommand(String command); static String runCommand(String command, Path directory); static int runCommand(String command, Path directory, Appendable output);  }
@Test public void testStringEmptyByteArray() throws Exception { String s = IoUtils.toUtf8String(new ByteArrayInputStream(new byte[0])); assertEquals("", s); }
@Test public void testStringZeroByteStream() throws Exception { String s = IoUtils.toUtf8String(new InputStream() { @Override public int read() throws IOException { return -1; } }); assertEquals("", s); }