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

    int result = in.read();
    if (result != -1) {
      --left;
    }
    return result;
  }
@Test
  public void testRead() throws IOException {
    try (LimitInputStream limitInputStream =
      new LimitInputStream(new RandomInputStream(), 0)) {
      assertEquals("Reading byte after reaching limit should return -1", -1,
          limitInputStream.read());
    }
    try (LimitInputStream limitInputStream =
      new LimitInputStream(new RandomInputStream(), 4)) {
      assertEquals("Incorrect byte returned", new Random(0).nextInt(),
          limitInputStream.read());
    }
  }