publicsynchronizedintread(byte b[], int off, int len) throws IOException { getBufIfOpen(); // Check for closed stream if ((off | len | (off + len) | (b.length - (off + len))) < 0) { thrownewIndexOutOfBoundsException(); } elseif (len == 0) { return0; }
intn=0; for (;;) { intnread= read1(b, off + n, len - n); if (nread <= 0) return (n == 0) ? nread : n; n += nread; if (n >= len) return n; // if not closed but no bytes available, return InputStreaminput= in; if (input != null && input.available() <= 0) return n; } } }
/** * See the general contract of the <code>mark</code> * method of <code>InputStream</code>. * * @param readlimit the maximum limit of bytes that can be read before * the mark position becomes invalid. * @see java.io.BufferedInputStream#reset() */ publicsynchronizedvoidmark(int readlimit) { marklimit = readlimit; markpos = pos; }
按照doc的意思,markpos应该在读取的字节数超过了readlimit的时候就应该失效。
但是实际上,只有fill方法中的这一段代码让markpos失效了:
1 2 3 4
if (buffer.length >= marklimit) { markpos = -1; /* buffer got too big, invalidate mark */ pos = 0; /* drop buffer contents */ }