@Override
  public int read() throws IOException {
    if (left == 0) {
      return -1;
    }

    int result = in.read();
    if (result != -1) {
      --left;
    }
    return result;
  }
@Test
  public void testReadBytes() throws IOException {
    try (LimitInputStream limitInputStream =
      new LimitInputStream(new RandomInputStream(), 128)) {
      Random r = new Random(0);
      byte[] data = new byte[4];
      byte[] expected = { (byte) r.nextInt(), (byte) r.nextInt(),
                          (byte) r.nextInt(), (byte) r.nextInt() };
      limitInputStream.read(data, 0, 4);
      assertArrayEquals("Incorrect bytes returned", expected, data);
    }
  }