/**
   * This method deletes a data file or resets its free position. this is used only for nio files -
   * not OOo files
   */
  public static void deleteOrResetFreePos(Database database, String filename) {

    ScaledRAFile raFile = null;

    try {
      database.getFileAccess().removeElement(filename);
    } catch (IOException e) {
      database.logger.appLog.logContext(e);
    }

    if (database.isStoredFileAccess()) {
      return;
    }

    if (!database.getFileAccess().isStreamElement(filename)) {
      return;
    }

    try {
      raFile = new ScaledRAFile(filename, false);

      raFile.seek(LONG_FREE_POS_POS);
      raFile.writeLong(INITIAL_FREE_POS);
    } catch (IOException e) {
      database.logger.appLog.logContext(e);
    } finally {
      if (raFile != null) {
        try {
          raFile.close();
        } catch (IOException e) {
          database.logger.appLog.logContext(e);
        }
      }
    }
  }