IoUtils { public static byte[] from( final InputStream in) throws IOException { final ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); final byte[] bytes = new byte[10000]; int readBytes; while (0 < (readBytes = in.read(bytes))) { byteOut.write(bytes, 0, readBytes); } return byteOut.toByteArray(); }  static void tryFlush(final Object... flushable); static int stream(final InputStream in, final StreamConsumer consumer); static int redirect(final InputStream from, final OutputStream to); static int redirect(final Reader from, final Writer to); static byte[] from(
      final InputStream in); static String from(
      final Reader reader); static byte[] getChecksum(final InputStream in); static String getChecksumAsString(final InputStream in);  }
@Test public void testFromOnByte() throws IOException { final Object[][] testParameters = new Object[][] {{new ByteArrayInputStream(new byte[] {1, 2, 3}), new byte[] {1, 2, 3}}, {new ByteArrayInputStream(new byte[] {4, 5, 6, 7, 8}), new byte[] {4, 5, 6, 7, 8}}, {new ByteArrayInputStream(new byte[] {9, 10, 11, 12, 13, 14, 15}), new byte[] {9, 10, 11, 12, 13, 14, 15}}}; for (final Object[] testParameter : testParameters) { byte[] expected = (byte[]) testParameter[1]; InputStream in = (InputStream) testParameter[0]; byte[] actual = IoUtils.from(in); for (int i = 0; i < actual.length; ++i) { assertEquals(expected[i], actual[i]); } } }
@Test public void testFromOnString() throws IOException { final Object[][] testParameters = new Object[][] {{new CharArrayReader(new char[] {'a', 'b', 'c'}), "abc"}, {new StringReader("hello"), "hello"}}; for (final Object[] testParameter : testParameters) { String expected = (String) testParameter[1]; Reader reader = (Reader) testParameter[0]; assertEquals(expected, IoUtils.from(reader)); } }