And here comes the fixes:
OutputStream:
/**
* Writes an array of bytes.
*
* @param b
* the bytes to write
* @param length
* the number of bytes to write
* @see InputStream#readBytes(byte[],int,int)
*/
public final void writeBytes(byte[] b, int length)
throws IOException {
// for (int i = 0; i < length; i++) writeByte(b[i]);
if (bufferPosition > 0) // flush buffer
flush();
if (length < BUFFER_SIZE) {
flushBuffer(b, length);
} else {
int pos = 0;
int size;
while (pos < length) {
if (length - pos < BUFFER_SIZE) {
size = length - pos;
} else {
size = BUFFER_SIZE;
}
System.arraycopy(b, pos,
buffer, 0, size); pos += size;
flushBuffer(buffer, size);
bufferStart += size;
}
}
}
InputStream:
public final void readBytes(byte[] b, int offset, int len)
throws IOException {
// if (len < BUFFER_SIZE) { // not required
// for (int i = 0; i < len; i++)
// // read byte-by-byte
// b[i + offset] = (byte) readByte();
// } else { // read all-at-once
long start = getFilePointer();
seekInternal(start);
readInternal(b, offset, len);
bufferStart = start + len;
bufferPosition = 0;
bufferLength = 0;
// }
}
You can try to test it in the SVN version in BufferedIndexInput and
BufferedIndexOutput, there are these methods too.
There is significant time improvement for writing and slight for
reading. I also recommend set the buffer to 8 or 16 kilobytes.
--
S pozdravem / Best regards
Lukas Zapletal
sefredaktor / editor-in-chief
LinuxEXPRES - opravdovy linuxovy magazin
www.LinuxEXPRES.cz
tel.:+420 777 003 843
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]