### Question:
IOUtils extends org.apache.commons.io.IOUtils { public static int copy(InputStream in, OutputStream out, byte[] buffer) throws IOException { final long count = copyLarge(in, out, buffer); return count > Integer.MAX_VALUE ? -1 : (int) count; } protected  IOUtils(); static int copy(InputStream in, OutputStream out, byte[] buffer); static long copyLarge(InputStream in, OutputStream out, byte[] buffer); static void copy(InputStream in, OutputStream out,
                          byte[] buffer, long length); static void closeQuietly(Closeable c); static int read(InputStream in, byte[] buf);  }### Answer:
@Test public void testCopyBuffer() throws IOException { final byte[] buf = new byte[1024]; final byte[] expected = new byte[10000]; final long seed = System.currentTimeMillis(); final Random rng = new Random(seed); rng.nextBytes(expected); final ByteArrayInputStream in = new ByteArrayInputStream(expected); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final int count = IOUtils.copy(in, out, buf); assertEquals("seed == " + seed, expected.length, count); assertArrayEquals("seed == " + seed, expected, out.toByteArray()); }
@Test public void testCopyExactFull() throws IOException { final byte[] buf = new byte[1024]; final byte[] expected = new byte[10000]; final long seed = System.currentTimeMillis(); final Random rng = new Random(seed); rng.nextBytes(expected); final ByteArrayInputStream in = new ByteArrayInputStream(expected); final ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(in, out, buf, 10000); assertArrayEquals("seed == " + seed, expected, out.toByteArray()); }
@Test public void testCopyExactNotFull() throws IOException { final byte[] buf = new byte[1024]; final byte[] expected = new byte[10000]; final long seed = System.currentTimeMillis(); final Random rng = new Random(seed); rng.nextBytes(expected); final ByteArrayInputStream in = new ByteArrayInputStream(expected); final ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(in, out, buf, 9999); final byte[] actual = out.toByteArray(); assertEquals("seed == " + seed, 9999, actual.length); for (int i = 0; i < actual.length; ++i) { assertEquals("seed == " + seed, expected[i], actual[i]); } }
@Test(expected=IOException.class) public void testCopyExactTooLittle() throws IOException { final byte[] buf = new byte[1024]; final byte[] expected = new byte[9999]; final long seed = System.currentTimeMillis(); final Random rng = new Random(seed); rng.nextBytes(expected); final ByteArrayInputStream in = new ByteArrayInputStream(expected); final ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(in, out, buf, 10000); }