public ByteBuffer flushAndReleaseBuffer() throws IOException {
  _lock.lock();
  try {
    _flushPending=true;
    while (_bufferUseCount != 0) {
      _flushReady.await();
    }
    _buffer.flip();
    if (_buffer.limit() != 0 && _modified) {
      if (_backingFile == null) {
        _backingFile=Files.createTempFile("tablebuffer",".tmp");
      }
      _log.debug("Flushing buffer for index {} to {} ({}/{} bytes)",_startIndex,_backingFile,_buffer.limit(),_blockSize);
      try (ByteChannel out=Files.newByteChannel(_backingFile,WRITE)){
        out.write(_buffer);
      }
     }
 else {
      _log.debug("Releasing unmodified buffer for index {}",_startIndex);
    }
    ByteBuffer oldBuffer=_buffer;
    _buffer=null;
    _loaded=false;
    return oldBuffer;
  }
 catch (  InterruptedException e) {
    throw Throwables.propagate(e);
  }
 finally {
    _flushPending=false;
    _flushComplete.signalAll();
    _lock.unlock();
  }
}

public ByteBuffer flushAndReleaseBuffer ( ) throws IOException { _lock . lock ( ) ; try { _flushPending = true ; while ( _bufferUseCount != 0 ) { _flushReady . await ( ) ; } _buffer . flip ( ) ; if ( _buffer . limit ( ) != 0 && _modified ) { if ( _backingFile == null ) { _backingFile = Files . createTempFile ( "tablebuffer" , ".tmp" ) ; } _log . debug ( "Flushing buffer for index {} to {} ({}/{} bytes)" , _startIndex , _backingFile , _buffer . limit ( ) , _blockSize ) ; try ( ByteChannel out = Files . newByteChannel ( _backingFile , WRITE ) ) { out . write ( _buffer ) ; } } else { _log . debug ( "Releasing unmodified buffer for index {}" , _startIndex ) ; } ByteBuffer oldBuffer = _buffer ; _buffer = null ; _loaded = false ; return oldBuffer ; } catch ( InterruptedException e ) { throw Throwables . propagate ( e ) ; } finally { _flushPending = false ; _flushComplete . signalAll ( ) ; _lock . unlock ( ) ; } }
flushes the block ' s buffer to disk and releases the buffer for use by another block . this method is called when another block requires a buffer , all buffers have been allocated and this block is the least recently used .
