* @return the number of bytes read
*/
public int read(long readIndex, int readOffset, int readLength,
byte[] b, int offset){
if(readIndex<minIndex){
throw new BufferUnderflowException();
}
if(readIndex>=index){
throw new BufferOverflowException();
}
int k=(int)(readIndex%bufferSize);
readBuffer.position(k*streamMaxSize+readOffset);
int l=lengths[k];
if(readLength<0){
l-=readOffset;
readBuffer.get(b,offset,l);
}
else{
if(l-readOffset<readLength){
throw new BufferOverflowException();
}
l=readLength;
readBuffer.get(b,offset,l);
}
// cross check for concurent access
if(readIndex<minIndex){
throw new BufferUnderflowException();
}
return l;
}