StreamUtil { public static int read(final InputStream input, final byte[] dst) throws IOException { return read(input, dst, 0); }  static MessageDigest getDigest(final String algorithm); static MessageDigest getSha1Digest(); static MessageDigest updateDigest(
      final MessageDigest messageDigest, final InputStream data); static String digestAsHex(final MessageDigest messageDigest); static int copy(final InputStream input, final OutputStream output); static void write(final File file, final String data); static void write(
      final File file, final InputStream data, final MessageDigest messageDigest); static int read(final InputStream input, final byte[] dst); static int read(
      final InputStream input, final MutableDirectBuffer buffer, final int offset); static int read(final InputStream input, final byte[] dst, final int offset); static byte[] read(final InputStream input); static void write(final DirectBuffer source, final OutputStream destination); static void write(
      final DirectBuffer source, final OutputStream destination, final int offset, final int length); static void writeLong(final OutputStream outputStream, final long longValue); static long readLong(final InputStream inputStream);  }
@Test public void shouldReadStreamIntoExpandableBuffer() throws IOException { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(2); final byte[] thingsToRead = new byte[] {1, 2, 3, 4}; final InputStream stream = new RepeatedlyFailingInputStream(new ByteArrayInputStream(thingsToRead), 2); StreamUtil.read(stream, buffer, 4); assertThat(buffer.capacity()).isGreaterThanOrEqualTo(4 + thingsToRead.length); assertThat(buffer.getByte(4)).isEqualTo((byte) 1); assertThat(buffer.getByte(5)).isEqualTo((byte) 2); assertThat(buffer.getByte(6)).isEqualTo((byte) 3); assertThat(buffer.getByte(7)).isEqualTo((byte) 4); }
@Test public void shouldNotReadIntoDirectBuffer() throws IOException { final ExpandableDirectByteBuffer buffer = new ExpandableDirectByteBuffer(2); final byte[] thingsToRead = new byte[] {1, 2, 3, 4}; final InputStream stream = new ByteArrayInputStream(thingsToRead); exception.expect(RuntimeException.class); exception.expectMessage("Cannot be used with direct byte buffers"); StreamUtil.read(stream, buffer, 4); }