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 testReadFullySmallReadsWithStartAndLength() throws IOException {
    byte[] buffer = new byte[10];

    MockInputStream stream = new MockInputStream(2, 2, 3);
    IOUtil.readFully(stream, buffer, 2, 5);

    assertThat(Arrays.copyOfRange(buffer, 2, 7))
        .as("Byte array contents should match")
        .isEqualTo(Arrays.copyOfRange(MockInputStream.TEST_ARRAY, 0, 5));

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