java.lang.Object
com.currencycalc.currencycalculatorjavafx.utils.ApiKeyManager

public class ApiKeyManager extends Object
Utility class for managing the storage and retrieval of the API key. The API key is stored in a serialized file within the operating system's designated application data folder. The class ensures cross-platform compatibility for Windows, macOS, and Linux.

The folder structure and file name are as follows:

  • Windows: %LOCALAPPDATA%/exchange-calculator/api_key.ser
  • macOS: ~/Library/Application Support/exchange-calculator/api_key.ser
  • Linux: ~/.config/exchange-calculator/api_key.ser

Version:
1.0.0
Autor:
Tim Platzer
  • Felddetails

    • APP_FOLDER_NAME

      private static final String APP_FOLDER_NAME
      The folder name where the application data is stored.
      Siehe auch:
    • API_KEY_FILE_NAME

      private static final String API_KEY_FILE_NAME
      The file name for storing the API key.
      Siehe auch:
  • Konstruktordetails

    • ApiKeyManager

      public ApiKeyManager()
  • Methodendetails

    • getAppDataFolder

      private static File getAppDataFolder()
      Retrieves the path to the application data folder based on the operating system.
      Gibt zurück:
      A File object representing the application data folder.
    • getApiKeyFile

      private static File getApiKeyFile()
      Retrieves the file where the API key is stored. Ensures the application data folder exists, creating it if necessary.
      Gibt zurück:
      A File object representing the API key file.
      Löst aus:
      RuntimeException - if the application data directory cannot be created.
    • saveApiKey

      public static void saveApiKey(String apiKey) throws IOException
      Saves the provided API key to the storage file.
      Parameter:
      apiKey - The API key to save.
      Löst aus:
      IOException - If an I/O error occurs while saving the key.
    • loadApiKey

      public static String loadApiKey() throws IOException, ClassNotFoundException
      Loads the API key from the storage file.
      Gibt zurück:
      The stored API key as a String.
      Löst aus:
      IOException - If the file does not exist or an I/O error occurs.
      ClassNotFoundException - If the serialized object cannot be deserialized.