protected void _doAppendChunked(long[] buffer, int offset, int length)
{
// first: append length prefix
if (!_head.tryAppend(length)) {
final LongsSegment seg = _head;
seg.finishWriting();
// and allocate, init-for-writing new one:
LongsSegment newSeg = _reuseFree().initForWriting();
seg.relink(newSeg);
_head = newSeg;
if (!_head.tryAppend(length)) {
throw new IllegalStateException();
}
}
// then payload
if (length > 0) {
LongsSegment seg = _head;
while (true) {
int actual = seg.tryAppend(buffer, offset, length);
offset += actual;
length -= actual;
if (length == 0) { // complete, can leave
return;
}
// otherwise, need another segment, so complete current write
seg.finishWriting();
// and allocate, init-for-writing new one:
LongsSegment newSeg = _reuseFree().initForWriting();
seg.relink(newSeg);
_head = seg = newSeg;
}
}
}