-
Enhancement
-
Resolution: Fixed
-
P4
-
14
-
b27
-
Verified
A DESCRIPTION OF THE PROBLEM :
The default implementation of java.io.InputStream.skipNBytes (as described in the javadoc) first calls skip(long) once and then repeatedly calls read().
This can probably be implemented more efficiently by repeatedly calling skip(long) and only calling read() if 0 is returned by skip(long):
public void skipNBytes(long n) throws IOException {
while (n > 0) {
long ns = skip(n);
if (ns < 0 || (n -= ns) < 0) { // skipped negative or too many bytes
throw new IOException("Unable to skip exactly");
}
// Don't know if EOF, have to read one byte to be sure
if (ns == 0) {
if (read() == -1) {
throw new EOFException();
}
n--; // skipped one byte by read()
}
}
}
The default implementation of java.io.InputStream.skipNBytes (as described in the javadoc) first calls skip(long) once and then repeatedly calls read().
This can probably be implemented more efficiently by repeatedly calling skip(long) and only calling read() if 0 is returned by skip(long):
public void skipNBytes(long n) throws IOException {
while (n > 0) {
long ns = skip(n);
if (ns < 0 || (n -= ns) < 0) { // skipped negative or too many bytes
throw new IOException("Unable to skip exactly");
}
// Don't know if EOF, have to read one byte to be sure
if (ns == 0) {
if (read() == -1) {
throw new EOFException();
}
n--; // skipped one byte by read()
}
}
}
- csr for
-
JDK-8256698 InputStream.skipNBytes could be implemented more efficiently
- Closed