本帖最后由 何竹冬 于 2013-1-6 13:42 编辑
在查看字节缓冲输出流的源码时候发现这段代码看不懂,谁能解释一下啊- /**
- * Writes <code>len</code> bytes from the specified byte array
- * starting at offset <code>off</code> to this buffered output stream.
- *
- * <p> Ordinarily this method stores bytes from the given array into this
- * stream's buffer, flushing the buffer to the underlying output stream as
- * needed. If the requested length is at least as large as this stream's
- * buffer, however, then this method will flush the buffer and write the
- * bytes directly to the underlying output stream. Thus redundant
- * <code>BufferedOutputStream</code>s will not copy data unnecessarily.
- *
- * @param b the data.
- * @param off the start offset in the data.
- * @param len the number of bytes to write.
- * @exception IOException if an I/O error occurs.
- */
- public synchronized void write(byte b[], int off, int len) throws IOException {
- if (len >= buf.length) {
- /* If the request length exceeds the size of the output buffer,
- flush the output buffer and then write the data directly.
- In this way buffered streams will cascade harmlessly. */
- flushBuffer();
- out.write(b, off, len);
- return;
- }
- if (len > buf.length - count) {
- flushBuffer();
- }
- System.arraycopy(b, off, buf, count, len);
- count += len;
- }
复制代码 首先在写字节数组的时候又调用了写字节数组的方法,这样不会无限递归吗
下面第二个if我怎么感觉不会执行到呢count默认值是0啊,如果第一个if不满足第二个if应该也不会满足条件的啊。
还有下面的几行麻烦代价解释一下
|