// TODO: optimization work:
// use ByteBuffer.get(byte[],int,int)
// and ByteBuffer.hasArray() methods
int len = (length < available) ? length : available;
available -= len;
consumed += len;
byte[] res = new byte[len];
int pos = 0;
loop:
for (; offset<limit; offset++) {
while (srcs[offset].hasRemaining()) {
res[pos++] = srcs[offset].get();
len --;
if (len == 0) {
break loop;
}
}
}
return res;