Read characters into a portion of an array.
// Allocate a private buffer to speed up reading
int bbuflen = (len > BBUF_LEN) ? BBUF_LEN : len;
byte bbuf[] = new byte[bbuflen];
int count = 0;
while (count < len) {
int nbytes = len - count;
if (nbytes > bbuflen) nbytes = bbuflen;
nbytes = in.read(bbuf, 0, nbytes);
if (nbytes == -1) {
return (count == 0) ? -1 : count;
}
for (int i = 0; i < nbytes; i++) {
cbuf[off++] = (char)(bbuf[i] & 0xFF);
}
count += nbytes;
}
return len;