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