Class FileSource

java.lang.Object
one.jpro.platform.file.FileSource
Direct Known Subclasses:
NativeFileSource, WebFileSource

public abstract sealed class FileSource extends Object permits NativeFileSource, WebFileSource
Represents an abstract source for file operations, offering a unified interface for interacting with files that may originate from different platforms or locations (e.g., local file system, web-based storage).

This class encapsulates common file attributes such as name, size, and object URL, as well as actions like uploading. It employs the Property pattern for these attributes, allowing for easy binding and observation in a JavaFX application.

This is a sealed class, which can only be subclassed by specific types (NativeFileSource, WebFileSource), ensuring a controlled set of implementations. This makes it easier to handle file operations consistently across various types of file sources.

The class provides both synchronous and asynchronous methods for file uploading, allowing flexibility in how file operations are handled.

Author:
Besmir Beqiri
  • Property Summary

    Properties
    Type
    Property
    Description
    final javafx.beans.property.ReadOnlyStringProperty
    Returns the name property of the file.
    abstract javafx.beans.property.ReadOnlyDoubleProperty
    Returns a read-only double property representing the current upload progress.
    final javafx.beans.property.ReadOnlyLongProperty
    Returns the size property of the file.
    abstract javafx.beans.property.ReadOnlyObjectProperty<File>
    Returns a read-only object property representing the uploaded file.
  • Constructor Summary

    Constructors
    Constructor
    Description
    FileSource(Object platformFile)
    Constructor to initialize the FileSource.
  • Method Summary

    Modifier and Type
    Method
    Description
    final String
    Returns the name of the file.
    Returns the platform-specific file object.
    abstract double
    Gets the current upload progress.
    final long
    Returns the size of the file.
    abstract File
    Retrieves the File object representing the uploaded file.
    final javafx.beans.property.ReadOnlyStringProperty
    Returns the name property of the file.
    abstract javafx.beans.property.ReadOnlyDoubleProperty
    Returns a read-only double property representing the current upload progress.
    final javafx.beans.property.ReadOnlyLongProperty
    Returns the size property of the file.
    abstract javafx.beans.property.ReadOnlyObjectProperty<File>
    Returns a read-only object property representing the uploaded file.
    abstract void
    Initiates the file upload process synchronously.
    Initiates the file upload process asynchronously.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Property Details

    • name

      public final javafx.beans.property.ReadOnlyStringProperty nameProperty
      Returns the name property of the file.
      See Also:
    • size

      public final javafx.beans.property.ReadOnlyLongProperty sizeProperty
      Returns the size property of the file.
      See Also:
    • progress

      public abstract javafx.beans.property.ReadOnlyDoubleProperty progressProperty
      Returns a read-only double property representing the current upload progress.
      See Also:
    • uploadedFile

      public abstract javafx.beans.property.ReadOnlyObjectProperty<File> uploadedFileProperty
      Returns a read-only object property representing the uploaded file.
      See Also:
  • Constructor Details

    • FileSource

      public FileSource(Object platformFile)
      Constructor to initialize the FileSource.
      Parameters:
      platformFile - the platform-specific file object
  • Method Details

    • getPlatformFile

      public Object getPlatformFile()
      Returns the platform-specific file object.
      Returns:
      the platform-specific file object
    • getName

      public final String getName()
      Returns the name of the file.
      Returns:
      the name of the file
    • nameProperty

      public final javafx.beans.property.ReadOnlyStringProperty nameProperty()
      Returns the name property of the file.
      Returns:
      the ReadOnlyStringProperty for name
      See Also:
    • getSize

      public final long getSize()
      Returns the size of the file.
      Returns:
      the size of the file
    • sizeProperty

      public final javafx.beans.property.ReadOnlyLongProperty sizeProperty()
      Returns the size property of the file.
      Returns:
      the ReadOnlyLongProperty for size
      See Also:
    • getProgress

      public abstract double getProgress()
      Gets the current upload progress.
      Returns:
      the current upload progress as a double value between 0.0 and 1.0
    • progressProperty

      public abstract javafx.beans.property.ReadOnlyDoubleProperty progressProperty()
      Returns a read-only double property representing the current upload progress.
      Returns:
      the ReadOnlyDoubleProperty for the upload progress
      See Also:
    • getUploadedFile

      public abstract File getUploadedFile()
      Retrieves the File object representing the uploaded file.
      Returns:
      the uploaded File object, or null if the file has not been uploaded yet
    • uploadedFileProperty

      public abstract javafx.beans.property.ReadOnlyObjectProperty<File> uploadedFileProperty()
      Returns a read-only object property representing the uploaded file.
      Returns:
      the ReadOnlyObjectProperty for the uploaded file
      See Also:
    • uploadFile

      public abstract void uploadFile()
      Initiates the file upload process synchronously.

      This method will start the upload operation and should be called to begin the upload.

    • uploadFileAsync

      public abstract CompletableFuture<File> uploadFileAsync()
      Initiates the file upload process asynchronously.
      Returns:
      a CompletableFuture representing the result of the asynchronous upload operation, which will complete with the uploaded File object