-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b63
-
x86
-
windows_xp
A DESCRIPTION OF THE REQUEST :
PipedInputStrea.read(byte[], int, int) copies one buffer into another, byte by byte, which is much slower than using System.arraycopy().
JUSTIFICATION :
This enhancement would improve the performance of reding from a piped input stream.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would like PipedInputStream.read(byte[], int, int) to use System.arraycopy for bulk copy operations.
ACTUAL -
public synchronized int read(byte b[], int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
/* possibly wait on the first character */
int c = read();
if (c < 0) {
return -1;
}
b[off] = (byte) c;
int rlen = 1;
while ((in >= 0) && (--len > 0)) {
b[off + rlen] = buffer[out++];
rlen++;
if (out >= buffer.length) {
out = 0;
}
if (in == out) {
/* now empty */
in = -1;
}
}
return rlen;
}
CUSTOMER SUBMITTED WORKAROUND :
public synchronized int read(byte b[], int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
/* possibly wait on the first character */
int c = read();
if (c < 0) {
return -1;
}
b[off] = (byte) c;
int rlen = 1;
while (in >= 0 && len > 1) {
int count;
if (out < in) {
count = Math.min(bufferFieldLen - out, in - out);
} else {
count = bufferFieldLen - out;
}
if (count > len - 1) {
count = len - 1;
}
System.arraycopy(bufferField, out, b, off + rlen, count);
out += count;
rlen += count;
len -= count;
if (out >= bufferFieldLen) {
out = 0;
}
if (in == out) {
// now empty
in = -1;
}
}
return rlen;
}
###@###.### 2005-03-28 11:01:59 GMT
PipedInputStrea.read(byte[], int, int) copies one buffer into another, byte by byte, which is much slower than using System.arraycopy().
JUSTIFICATION :
This enhancement would improve the performance of reding from a piped input stream.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would like PipedInputStream.read(byte[], int, int) to use System.arraycopy for bulk copy operations.
ACTUAL -
public synchronized int read(byte b[], int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
/* possibly wait on the first character */
int c = read();
if (c < 0) {
return -1;
}
b[off] = (byte) c;
int rlen = 1;
while ((in >= 0) && (--len > 0)) {
b[off + rlen] = buffer[out++];
rlen++;
if (out >= buffer.length) {
out = 0;
}
if (in == out) {
/* now empty */
in = -1;
}
}
return rlen;
}
CUSTOMER SUBMITTED WORKAROUND :
public synchronized int read(byte b[], int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
/* possibly wait on the first character */
int c = read();
if (c < 0) {
return -1;
}
b[off] = (byte) c;
int rlen = 1;
while (in >= 0 && len > 1) {
int count;
if (out < in) {
count = Math.min(bufferFieldLen - out, in - out);
} else {
count = bufferFieldLen - out;
}
if (count > len - 1) {
count = len - 1;
}
System.arraycopy(bufferField, out, b, off + rlen, count);
out += count;
rlen += count;
len -= count;
if (out >= bufferFieldLen) {
out = 0;
}
if (in == out) {
// now empty
in = -1;
}
}
return rlen;
}
###@###.### 2005-03-28 11:01:59 GMT
- relates to
-
JDK-4404700 PipedInputStream too slow due to polling (alt implementation proposed)
-
- Open
-