public void close() throws BlockStoreException {
   ensureOpen();
   try {
     file.close();
   } catch (IOException e) {
     throw new BlockStoreException(e);
   } finally {
     semaphores.release(this.fileName);
     file = null;
   }
 }
 private void lock() throws IOException, BlockStoreException {
   if (!semaphores.tryAcquire(fileName)) {
     throw new BlockStoreException("File in use");
   }
   try {
     lock = channel.tryLock();
   } catch (OverlappingFileLockException e) {
     semaphores.release(fileName);
     lock = null;
   }
   if (lock == null) {
     try {
       this.file.close();
     } finally {
       this.file = null;
     }
     throw new BlockStoreException("Could not lock file");
   }
 }