@Override
  public int read(byte[] b, int off, int len) throws IOException {
    if (pos >= limit) {
      return -1;
    }
    int toRead = (int) Math.min(len, limit - pos);
    int readBytes = IOUtils.read(in, b, off, toRead);
    // increase pos by however many we actually read
    pos += readBytes;

    if (readBytes != toRead) {
      // This is trick here, we will always try to read enough bytes to fill the buffer passed in,
      // or we reach the end of this compression block, if there are not enough bytes, we just
      // return -1 to let the upper layer fail with EOF
      // In WAL value decompression this is OK as if we can not read all the data, we will finally
      // get an EOF somewhere
      LOG.debug("Got EOF while we want to read {} bytes from stream, but only read {}", toRead,
        readBytes);
      return -1;
    }
    return toRead;
  }
This class is only used by WAL ValueCompressor for decompression.
<p>
<strong>WARNING: </strong>The implementation is very tricky and does not follow typical
InputStream pattern, so do not use it in any other places.
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALDecompressionBoundedDelegatingInputStream.java