{
// too large ... so we wrap and insert (zero-copy)
if(available == 0)
{
// buffer was actually full ... return a fresh buffer
return new LinkedBuffer(session.nextBufferSize,
new LinkedBuffer(value, offset, offset+valueLen, lb));
}
// continue with the existing byte array of the previous buffer
return new LinkedBuffer(lb,
new LinkedBuffer(value, offset, offset+valueLen, lb));
}
// copy what can fit
System.arraycopy(value, offset, lb.buffer, lb.offset, available);
lb.offset += available;
// grow
lb = new LinkedBuffer(session.nextBufferSize, lb);
final int leftover = valueLen - available;
// copy what's left
System.arraycopy(value, offset+available, lb.buffer, 0, leftover);