src/share/classes/java/io/ByteArrayInputStream.java

Print this page

        

*** 177,190 **** if (b == null) { throw new NullPointerException(); } else if (off < 0 || len < 0 || len > b.length - off) { throw new IndexOutOfBoundsException(); } if (pos >= count) { return -1; } ! if (pos + len > count) { len = count - pos; } if (len <= 0) { return 0; } --- 177,194 ---- if (b == null) { throw new NullPointerException(); } else if (off < 0 || len < 0 || len > b.length - off) { throw new IndexOutOfBoundsException(); } + if (pos >= count) { return -1; } ! ! int newpos = pos + len; ! if (newpos - count > 0) { ! // overflow-conscious code len = count - pos; } if (len <= 0) { return 0; }
*** 204,222 **** * * @param n the number of bytes to be skipped. * @return the actual number of bytes skipped. */ public synchronized long skip(long n) { ! if (pos + n > count) { ! n = count - pos; } ! if (n < 0) { ! return 0; } - pos += n; - return n; - } /** * Returns the number of remaining bytes that can be read (or skipped over) * from this input stream. * <p> --- 208,225 ---- * * @param n the number of bytes to be skipped. * @return the actual number of bytes skipped. */ public synchronized long skip(long n) { ! long k = count - pos; ! if (n < k) { ! k = n < 0 ? 0 : n; } ! ! pos += k; ! return k; } /** * Returns the number of remaining bytes that can be read (or skipped over) * from this input stream. * <p>