private void checkCrucialFileHeaderParamsEagerly(@NotNull Path storagePath) throws IOException {
    ByteBuffer headerBuffer = ByteBuffer.allocate(ExtendibleHashMap.HeaderLayout.STATIC_HEADER_SIZE)
      .order(nativeOrder())
      .clear();

    try (FileChannel channel = FileChannel.open(storagePath, READ)) {
      try {
        int actuallyRead = channel.read(headerBuffer);
        if (actuallyRead != ExtendibleHashMap.HeaderLayout.STATIC_HEADER_SIZE) {
          throw new CorruptedException(
            "[" + storagePath + "]: file is not empty, but < HEADER_SIZE(=" + ExtendibleHashMap.HeaderLayout.STATIC_HEADER_SIZE + ")"
          );
        }

        int magicWord = ExtendibleHashMap.HeaderLayout.magicWord(headerBuffer);
        if (magicWord != ExtendibleHashMap.MAGIC_WORD) {
          throw new IOException(
            "[" + storagePath + "] is of incorrect type: " +
            ".magicWord(=" + magicWord + ", '" + IOUtil.magicWordToASCII(magicWord) + "') " +
            "!= " + ExtendibleHashMap.MAGIC_WORD + " expected"
          );
        }

        int implVersion = ExtendibleHashMap.HeaderLayout.version(headerBuffer);
        if (implVersion != ExtendibleHashMap.IMPLEMENTATION_VERSION) {
          throw new IOException(
            "[" + storagePath + "]: version(=" + implVersion + ") " +
            "!= current impl version(=" + ExtendibleHashMap.IMPLEMENTATION_VERSION + ")"
          );
        }

        int segmentSize = ExtendibleHashMap.HeaderLayout.segmentSize(headerBuffer);
        if (segmentSize != this.segmentSize) {
          throw new IOException(
            "[" + storagePath + "]: segmentSize(=" + this.segmentSize + ") != segmentSize(=" + segmentSize + ")" +
            " storage was initialized with"
          );
        }
      }
      catch (IOException ex) {
        if (cleanFileIfIncompatible) {
          LOG.info("[" + storagePath + "] is incompatible with current format " +
                   "-> delete it, and pretend never seen it incompatible " +
                   "(incompatibility: " + ex.getMessage() + ")"
          );
          FileUtil.delete(storagePath);
        }
        else {
          throw ex;
        }
      }

      byte fileStatus = ExtendibleHashMap.HeaderLayout.fileStatus(headerBuffer);
      boolean wasProperlyClosed = (fileStatus == ExtendibleHashMap.HeaderLayout.FILE_STATUS_PROPERLY_CLOSED);
      if (!wasProperlyClosed) {
        switch (notClosedProperlyAction) {
          case FAIL_SPECTACULARLY -> throw new CorruptedException(
            "Storage [" + storagePath + "] was not closed properly, can't be trusted -- could be corrupted"
          );
          case DROP_AND_CREATE_EMPTY_MAP -> {
            LOG.info("[" + storagePath + "] was not closed properly, can't be trusted -> delete it, and re-create from 0");
            FileUtil.delete(storagePath);
          }
          case IGNORE_AND_HOPE_FOR_THE_BEST -> {
            //nothing
          }
        }
      }
    }
  }
private void checkCrucialFileHeaderParamsEagerly(@NotNull Path storagePath)