code: private void fillBuffer(int minNeededBytes) throws IOException {
      int lengthToReallyRead = Math.min(BUF_SIZE, Math.max(super.available(), minNeededBytes));
      end = super.read(buf, 0, lengthToReallyRead);
      pos = 0;
    }
docs: Fill buffer with required length, or available bytes.
  
  @param minNeededBytes  asked number of bytes
  @throws IOException in case of failing reading stream.