public static void readFully(InputStream stream, byte[] bytes, int offset, int length)
      throws IOException {
    int bytesRead = readRemaining(stream, bytes, offset, length);
    if (bytesRead < length) {
      throw new EOFException(
          "Reached the end of stream with " + (length - bytesRead) + " bytes left to read");
    }
  }
@Test
  public void testReadFullyJustRight() throws Exception {
    final byte[] buffer = new byte[10];

    final MockInputStream stream = new MockInputStream(2, 3, 3);
    IOUtil.readFully(stream, buffer, 0, buffer.length);

    assertThat(buffer).as("Byte array contents should match").isEqualTo(MockInputStream.TEST_ARRAY);

    assertThat(stream.getPos()).as("Stream position should reflect bytes read").isEqualTo(10);

    assertThatThrownBy(() -> IOUtil.readFully(stream, buffer, 0, 1))
        .isInstanceOf(EOFException.class)
        .hasMessage("Reached the end of stream with 1 bytes left to read");
  }