long r=getNextReadIndex(timeout,mark);
if(mark>r){
return res;
}
if(mark<minIndex){
throw new BufferUnderflowException();
}
int k;
if(mark < 0){
mark = -1;
}
k = (int)((mark+1)%bufferSize);
int c=(int)(r-mark);
for(int i=0;i<c;i++){
int x=(k+i)%(int) bufferSize;
readBuffer.limit(x*streamMaxSize+lengths[x]);
readBuffer.position(x*streamMaxSize);
ByteBuffer bb=readBuffer.slice();
try {
factory.add(bb);
} catch (PacketBufferValidationError e) {
validationErrorControl(e);
}
res+=lengths[x];
}
if(mark<minIndex){
throw new BufferUnderflowException();
}
mark=r;
return res;
}