// Path: src/org/jgroups/raft/util/pmem/FileProvider.java
// public class FileProvider {
// 
//    private static final boolean ATTEMPT_PMEM;
// 
//    static {
//       boolean attemptPmem = false;
//       try {
//          Class.forName("io.mashona.logwriting.PmemUtil");
//          // use persistent memory if available, otherwise fallback to regular file.
//          attemptPmem = true;
//       } catch (ClassNotFoundException e) {
//          //no op
//       }
//       ATTEMPT_PMEM = attemptPmem;
//    }
// 
//    public static FileChannel openChannel(File file, int length, boolean create, boolean readSharedMetadata) throws IOException {
//       FileChannel fileChannel = ATTEMPT_PMEM ? PmemUtilWrapper.pmemChannelFor(file, length, create, readSharedMetadata) : null;
// 
//       if (fileChannel == null) {
//          if (!file.exists() && !create) {
//             return null;
//          }
//          return FileChannel.open(file.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.READ);
//       }
// 
//       return fileChannel;
//    }
// 
// }


import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Objects;
import org.jgroups.logging.Log;
import org.jgroups.logging.LogFactory;
import org.jgroups.raft.util.pmem.FileProvider;
   public synchronized void close() throws IOException {
      if (channel != null) {
         channel.close();
         channel = null;
      }
   }

   public synchronized void delete() throws IOException {
      if (channel != null) {
         channel.close();
         channel = null;
      }
      if (storageFile.exists()) {
         if (!storageFile.delete()) {
            log.warn("Failed to delete file " + storageFile.getAbsolutePath());
         }
      }
   }

   protected FileChannel checkOpen() throws IOException {
      FileChannel fileChannel = channel;
      if (fileChannel == null) {
         throw new IOException("File " + storageFile.getAbsolutePath() + " not open!");
      }
      return fileChannel;
   }

   protected synchronized void truncateUntil(long position) throws IOException {
      FileChannel existing = checkOpen();
      File tmpFile = new File(storageFile.getParentFile(), storageFile.getName() + ".tmp");
// Path: src/org/jgroups/raft/util/pmem/FileProvider.java
// public class FileProvider {
// 
//    private static final boolean ATTEMPT_PMEM;
// 
//    static {
//       boolean attemptPmem = false;
//       try {
//          Class.forName("io.mashona.logwriting.PmemUtil");
//          // use persistent memory if available, otherwise fallback to regular file.
//          attemptPmem = true;
//       } catch (ClassNotFoundException e) {
//          //no op
//       }
//       ATTEMPT_PMEM = attemptPmem;
//    }
// 
//    public static FileChannel openChannel(File file, int length, boolean create, boolean readSharedMetadata) throws IOException {
//       FileChannel fileChannel = ATTEMPT_PMEM ? PmemUtilWrapper.pmemChannelFor(file, length, create, readSharedMetadata) : null;
// 
//       if (fileChannel == null) {
//          if (!file.exists() && !create) {
//             return null;
//          }
//          return FileChannel.open(file.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.READ);
//       }
// 
//       return fileChannel;
//    }
// 
// }


// Path: src/org/jgroups/raft/filelog/BaseStorage.java
import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Objects;
import org.jgroups.logging.Log;
import org.jgroups.logging.LogFactory;
import org.jgroups.raft.util.pmem.FileProvider;

   public synchronized void close() throws IOException {
      if (channel != null) {
         channel.close();
         channel = null;
      }
   }

   public synchronized void delete() throws IOException {
      if (channel != null) {
         channel.close();
         channel = null;
      }
      if (storageFile.exists()) {
         if (!storageFile.delete()) {
            log.warn("Failed to delete file " + storageFile.getAbsolutePath());
         }
      }
   }

   protected FileChannel checkOpen() throws IOException {
      FileChannel fileChannel = channel;
      if (fileChannel == null) {
         throw new IOException("File " + storageFile.getAbsolutePath() + " not open!");
      }
      return fileChannel;
   }

   protected synchronized void truncateUntil(long position) throws IOException {
      FileChannel existing = checkOpen();
      File tmpFile = new File(storageFile.getParentFile(), storageFile.getName() + ".tmp");
      FileChannel newChannel = FileProvider.openChannel(tmpFile, (int) existing.size(), true, true);