Class DownloadResource

java.lang.Object
dev.dosya.sdk.resource.DownloadResource

public final class DownloadResource extends Object
Provides operations for downloading files from Dosya.

Supports retrieving download URLs, downloading file content as byte arrays, and streaming file content via InputStream.

Since:
0.1.0
  • Constructor Details

    • DownloadResource

      public DownloadResource(@NotNull @NotNull DosyaHttpClient http)
      Creates a new DownloadResource backed by the given HTTP client.
      Parameters:
      http - the HTTP client used to make API requests
  • Method Details

    • getUrl

      @NotNull public @NotNull String getUrl(@NotNull @NotNull String fileId, @Nullable @Nullable Integer version, @Nullable @Nullable String unlockToken)
      Retrieves a pre-signed download URL for a file.
      Parameters:
      fileId - the unique identifier of the file
      version - the file version number, or null for the latest version
      unlockToken - the unlock token for locked files, or null if not locked
      Returns:
      the pre-signed download URL
      Throws:
      DosyaException - if the download URL cannot be extracted from the response
      DosyaApiException - if the API returns an error
    • getUrl

      @NotNull public @NotNull String getUrl(@NotNull @NotNull String fileId)
      Retrieves a pre-signed download URL for the latest version of a file.
      Parameters:
      fileId - the unique identifier of the file
      Returns:
      the pre-signed download URL
      Throws:
      DosyaException - if the download URL cannot be extracted from the response
      DosyaApiException - if the API returns an error
    • downloadBytes

      public byte @NotNull [] downloadBytes(@NotNull @NotNull String fileId, @Nullable @Nullable Integer version, @Nullable @Nullable String unlockToken)
      Downloads the file content as a byte array.
      Parameters:
      fileId - the unique identifier of the file
      version - the file version number, or null for the latest version
      unlockToken - the unlock token for locked files, or null if not locked
      Returns:
      the file content as a byte array
      Throws:
      DosyaException - if the download fails
      DosyaApiException - if the API returns an error
    • downloadBytes

      public byte @NotNull [] downloadBytes(@NotNull @NotNull String fileId)
      Downloads the latest version of a file as a byte array.
      Parameters:
      fileId - the unique identifier of the file
      Returns:
      the file content as a byte array
      Throws:
      DosyaException - if the download fails
      DosyaApiException - if the API returns an error
    • downloadStream

      @NotNull public @NotNull InputStream downloadStream(@NotNull @NotNull String fileId, @Nullable @Nullable Integer version, @Nullable @Nullable String unlockToken)
      Downloads the file content as a streaming InputStream.

      The caller is responsible for closing the returned stream, which will also disconnect the underlying HTTP connection.

      Parameters:
      fileId - the unique identifier of the file
      version - the file version number, or null for the latest version
      unlockToken - the unlock token for locked files, or null if not locked
      Returns:
      an input stream of the file content
      Throws:
      DosyaException - if the download fails
      DosyaApiException - if the API returns an error
    • downloadStream

      @NotNull public @NotNull InputStream downloadStream(@NotNull @NotNull String fileId)
      Downloads the latest version of a file as a streaming InputStream.

      The caller is responsible for closing the returned stream.

      Parameters:
      fileId - the unique identifier of the file
      Returns:
      an input stream of the file content
      Throws:
      DosyaException - if the download fails
      DosyaApiException - if the API returns an error