### Question:
ByteUtilities { public static int readNBytes(InputStream in, OutputStream out, int byteCount) throws IOException { int totalBytesRead = 0; int bytesRead; byte[] bytes = new byte[BUFFER_SIZE]; while (totalBytesRead < byteCount) { bytesRead = in.read(bytes, 0, Math.min(bytes.length, byteCount - totalBytesRead)); if (bytesRead > 0) { out.write(bytes, 0, bytesRead); totalBytesRead += bytesRead; } else if (bytesRead == -1) { break; } } return totalBytesRead; } private  ByteUtilities(); static int readNBytes(InputStream in, OutputStream out, int byteCount); static boolean readUntilInclusive(PushbackInputStream in, OutputStream out, byte[] marker);  }### Answer:
@Test public void testReadNBytes() throws IOException { ByteArrayInputStream in = new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }); ByteArrayOutputStream out = new ByteArrayOutputStream(); int bytesRead = ByteUtilities.readNBytes(in, out, 5); Assert.assertEquals(5, bytesRead); Assert.assertTrue(Arrays.equals(new byte[] { 1, 2, 3, 4, 5 }, out.toByteArray())); Assert.assertEquals(6, in.read()); out.reset(); bytesRead = ByteUtilities.readNBytes(in, out, 5); Assert.assertEquals(2, bytesRead); Assert.assertTrue(Arrays.equals(new byte[] { 7, 8 }, out.toByteArray())); Assert.assertEquals(-1, in.read()); }