private void fillBuffer(long amount,boolean reload){
  try {
    if (amount > bufferSize) {
      amount=bufferSize;
    }
    if (channelSize - channel.position() < amount) {
      amount=channelSize - channel.position();
    }
    if (in == null) {
switch (bufferType) {
case HEAP:
        in=IoBuffer.allocate(bufferSize,false);
      break;
case DIRECT:
    in=IoBuffer.allocate(bufferSize,true);
  break;
default :
in=IoBuffer.allocate(bufferSize);
}
channel.read(in.buf());
in.flip();
useLoadBuf=true;
}
if (!useLoadBuf) {
return;
}
if (reload || in.remaining() < amount) {
if (!reload) {
in.compact();
}
 else {
in.clear();
}
channel.read(in.buf());
in.flip();
}
}
 catch (Exception e) {
log.error("Error fillBuffer",e);
}
}

private void fillBuffer ( long amount , boolean reload ) { try { if ( amount > bufferSize ) { amount = bufferSize ; } if ( channelSize - channel . position ( ) < amount ) { amount = channelSize - channel . position ( ) ; } if ( in == null ) { switch ( bufferType ) { case HEAP : in = IoBuffer . allocate ( bufferSize , false ) ; break ; case DIRECT : in = IoBuffer . allocate ( bufferSize , true ) ; break ; default : in = IoBuffer . allocate ( bufferSize ) ; } channel . read ( in . buf ( ) ) ; in . flip ( ) ; useLoadBuf = true ; } if ( ! useLoadBuf ) { return ; } if ( reload || in . remaining ( ) < amount ) { if ( ! reload ) { in . compact ( ) ; } else { in . clear ( ) ; } channel . read ( in . buf ( ) ) ; in . flip ( ) ; } } catch ( Exception e ) { log . error ( "Error fillBuffer" , e ) ; } }
load enough bytes from channel to buffer . after the loading process , the caller can make sure the amount in buffer is of size ' amount ' if we haven ' t reached the end of channel .
