public long skip(long n) throws IOException {
    if (n < 0) {
      throw new IllegalArgumentException("negative skip length");
    }

    if (closed) { throw new IOException("Stream closed"); }

    int max = (int)Math.min(n, Integer.MAX_VALUE);
    int total = 0;
    while (total < max) {
      int len = max - total;
      if (len > b.length) {
        len = b.length;
      }
      len = read(b, 0, len);
      if (len == -1) {
        eof = true;
        break;
      }
      total += len;
    }
    return total;
  }