IOUtil { public static String toString(@NonNull InputStream input) throws IOException { final ByteArrayOutputStream output = new ByteArrayOutputStream(); final byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = input.read(buffer)) != -1) { output.write(buffer, 0, bytesRead); } input.close(); return output.toString(StandardCharsets.UTF_8.name()); }  static void copy(@NonNull InputStream input, @NonNull OutputStream output); static String toString(@NonNull InputStream input);  }
@Test public void streamToString() throws IOException { InputStream is = new ByteArrayInputStream("BASE".getBytes()); String out = IOUtil.toString(is); assertEquals("BASE", out); }