Interface SaveUtils


public interface SaveUtils
Provides utility methods for saving and downloading files.
Author:
Besmir Beqiri
  • Method Details

    • save

      static CompletableFuture<File> save(@NotNull @NotNull File fileToSave, @Nullable @Nullable String fileType, @NotNull @NotNull Function<File,CompletableFuture<File>> saveFunction)
      Saves a file using the provided save function. This method should be used only for desktop/native applications.
      Parameters:
      fileToSave - the file to be saved
      fileType - the file extension to be appended to the file name if it does not already have it
      saveFunction - the save function to be used to save the file
      Returns:
      a CompletableFuture representing the asynchronous operation of saving the file
      Throws:
      NullPointerException - if the fileToSave parameter is null
    • saveAs

      static CompletableFuture<File> saveAs(@NotNull @NotNull javafx.stage.Stage stage, @NotNull @NotNull String fileName, @Nullable @Nullable String fileType, @NotNull @NotNull Function<File,CompletableFuture<File>> saveFunction)
      Saves a file with the given name and type using the provided save function. This method should be used only for desktop/native applications.
      Parameters:
      stage - The stage where the save dialog will be shown.
      fileName - The initial file name.
      fileType - The file type (extension) of the file to save.
      saveFunction - The function to be called to save the file. This function takes a File parameter representing the file to save and returns a CompletableFuture<File> that will complete with the saved file.
      Returns:
      A CompletableFuture<File> that will complete with the saved file if the user selects a file to save, or fail with a NullPointerException if the user cancels the save operation.
    • download

      static CompletableFuture<File> download(@NotNull @NotNull javafx.stage.Stage stage, @NotNull @NotNull String fileName, @Nullable @Nullable String fileType, @NotNull @NotNull Function<File,CompletableFuture<Void>> saveFunction) throws IOException
      Downloads a file with the given name and type using the provided save function.
      Parameters:
      stage - The stage is needed to initialise the WebAPI. This is required to show the download dialog in a browser environment.
      fileName - The name of the file to be downloaded.
      fileType - The file type (extension) of the file to be downloaded.
      saveFunction - The function to be called to save the file. This function takes a File parameter representing the file to save and returns a CompletableFuture<File> that will complete with the saved file.
      Returns:
      A CompletableFuture<File> that will complete with the downloaded file if the download is successful, or fail with an exception if the download fails or if the operation is not supported in the current environment.
      Throws:
      UnsupportedOperationException - If the download operation is not supported in the current environment.
      IOException
    • download

      static CompletableFuture<File> download(@NotNull @NotNull javafx.stage.Stage stage, @NotNull @NotNull File tmpDir, @NotNull @NotNull String fileName, @Nullable @Nullable String fileType, @NotNull @NotNull Function<File,CompletableFuture<Void>> saveFunction) throws IOException
      Downloads a file with the given name and type using the provided save function.
      Parameters:
      stage - The stage is needed to initialise the WebAPI. This is required to show the download dialog in a browser environment.
      tmpDir - The temporary directory where the file will be saved before being offered for download.
      fileName - The name of the file to be downloaded.
      fileType - The file type (extension) of the file to be downloaded.
      saveFunction - The function to be called to save the file. This function takes a File parameter representing the file to save and returns a CompletableFuture<File> that will complete with the saved file.
      Returns:
      A CompletableFuture<Void> that will complete with the downloaded file if the download is successful, or fail with an exception if the download fails or if the operation is not supported in the current environment.
      Throws:
      UnsupportedOperationException - If the download operation is not supported in the current environment.
      IOException