public interface SaveUtils
Provides utility methods for saving and downloading files.
- Author:
- Besmir Beqiri
-
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic CompletableFuture<File> download(@NotNull javafx.stage.Stage stage, @NotNull File tmpDir, @NotNull String fileName, @Nullable String fileType, @NotNull Function<File, CompletableFuture<Void>> saveFunction) Downloads a file with the given name and type using the provided save function.static CompletableFuture<File> download(@NotNull javafx.stage.Stage stage, @NotNull String fileName, @Nullable String fileType, @NotNull Function<File, CompletableFuture<Void>> saveFunction) Downloads a file with the given name and type using the provided save function.static CompletableFuture<File> save(@NotNull File fileToSave, @Nullable String fileType, @NotNull Function<File, CompletableFuture<File>> saveFunction) Saves a file using the provided save function.static CompletableFuture<File> saveAs(@NotNull javafx.stage.Stage stage, @NotNull String fileName, @Nullable String fileType, @NotNull Function<File, CompletableFuture<File>> saveFunction) Saves a file with the given name and type using the provided save function.
-
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 savedfileType- the file extension to be appended to the file name if it does not already have itsaveFunction- 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 aCompletableFuture<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 IOExceptionDownloads 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 aCompletableFuture<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 IOExceptionDownloads 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 aCompletableFuture<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
-