### Question:
IOUtils { public static long copyStream(InputStream in, OutputStream out) throws IOException { Reject.ifNull(in, out); final byte[] buffer = new byte[BUFFER_SIZE]; long bytesCopied = 0L; for (int bytesRead = in.read(buffer); bytesRead != -1; bytesRead = in.read(buffer)) { out.write(buffer, 0, bytesRead); bytesCopied += bytesRead; } return bytesCopied; } private  IOUtils(); static String getFileContent(String path); static String getFileContent(String path, String encoding); static String getFileContentFromClassPath(Class classInSameModule, String path); static String getFileContentFromClassPath(Class classInSameModule, String path, String encoding); static String readStream(InputStream is); static String readStream(InputStream is, String encoding); static void writeToFile(String fileName, String content); static void closeIfNotNull(Closeable closeable); static void closeIfNotNull(Closeable... o); static long copyStream(InputStream in, OutputStream out); static T deserialise(byte[] bytes, boolean compressed); static T deserialise(byte[] bytes, boolean compressed, ClassLoader classLoader);  }### Answer:
@Test public void shouldCopyStreamsFully() throws Exception { final byte[] input = new byte[8 * 1024 + 1]; for (int i = 0; i < input.length; ++i) { input[i] = (byte) i; } try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Arrays.copyOf(input, input.length)); ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { long bytesCopied = IOUtils.copyStream(inputStream, outputStream); assertThat(outputStream.toByteArray()).isEqualTo(input); assertThat(bytesCopied).isEqualTo((long) input.length); } }
@Test public void shouldCopyEmptyStreams() throws Exception { try (ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]); ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { long bytesCopied = IOUtils.copyStream(inputStream, outputStream); assertThat(bytesCopied).isEqualTo(0L); assertThat(outputStream.toByteArray()).isEqualTo(new byte[0]); } }
@Test(expectedExceptions = NullPointerException.class) public void shouldRejectNullInputStreamForCopy() throws Exception { IOUtils.copyStream(null, new ByteArrayOutputStream()); }
@Test(expectedExceptions = NullPointerException.class) public void shouldRejectNullOutputStreamForCopy() throws Exception { IOUtils.copyStream(new ByteArrayInputStream(new byte[0]), null); }