byte[] buffer;
int bufferPos = 0;
while (bufferPos != len) {
int bufferNumber = pointer/BUFFER_SIZE;
int bufferOffset = pointer%BUFFER_SIZE;
int bytesInBuffer = BUFFER_SIZE - bufferOffset;
int remainInSrcBuffer = len - bufferPos;
int bytesToCopy = bytesInBuffer >= remainInSrcBuffer ? remainInSrcBuffer : bytesInBuffer;
if (bufferNumber == file.buffers.size()) {
buffer = new byte[BUFFER_SIZE];
file.buffers.addElement(buffer);
} else {
buffer = (byte[]) file.buffers.elementAt(bufferNumber);
}
System.arraycopy(src, bufferPos, buffer, bufferOffset, bytesToCopy);
bufferPos += bytesToCopy;
pointer += bytesToCopy;
}
if (pointer > file.length)
file.length = pointer;
file.lastModified = System.currentTimeMillis();