### Question:
IoUtil { public static byte[] readBytes( InputStream stream ) throws IOException { if (stream == null) return new byte[] {}; byte[] buffer = new byte[1024]; ByteArrayOutputStream output = new ByteArrayOutputStream(); boolean error = false; try { int numRead = 0; while ((numRead = stream.read(buffer)) > -1) { output.write(buffer, 0, numRead); } } catch (IOException e) { error = true; throw e; } catch (RuntimeException e) { error = true; throw e; } finally { try { stream.close(); } catch (IOException e) { if (!error) throw e; } } output.flush(); return output.toByteArray(); } private  IoUtil(); static byte[] readBytes( InputStream stream ); static byte[] readBytes( File file ); static String read( Reader reader ); static String read( InputStream stream ); static String read( File file ); static void write( String content,
                              OutputStream stream ); static void write( String content,
                              Writer writer ); static void write( InputStream input,
                              OutputStream stream ); static void write( Reader input,
                              Writer writer ); static boolean isSame( InputStream input1,
                                  InputStream input2 ); static InputStream getResourceAsStream( String resourcePath,
                                                   ClassLoader classLoader,
                                                   Class<?> clazz );  }### Answer:
@Test public void readBytesShouldReturnEmptyByteArrayForNullInputStream() throws Exception { assertThat(IoUtil.readBytes((InputStream)null), is(new byte[] {})); }
@Test public void readBytesShouldReadInputStreamCorrectlyAndShouldCloseStream() throws Exception { String content = "This is the way to grandma's house."; InputStream stream = new ByteArrayInputStream(content.getBytes()); InputStreamWrapper wrapper = new InputStreamWrapper(stream); assertThat(wrapper.isClosed(), is(false)); byte[] bytes = IoUtil.readBytes(wrapper); String output = new String(bytes); assertThat(output, is(content)); assertThat(wrapper.isClosed(), is(true)); for (int i = 0; i != 10; ++i) { content += content; } stream = new ByteArrayInputStream(content.getBytes()); wrapper = new InputStreamWrapper(stream); assertThat(wrapper.isClosed(), is(false)); bytes = IoUtil.readBytes(wrapper); output = new String(bytes); assertThat(output, is(content)); assertThat(wrapper.isClosed(), is(true)); }