Class RemoteDatasourceDownloader


  • public class RemoteDatasourceDownloader
    extends Object
    A utility class for downloading data from a remote datasource via HTTP GET requests. You must always provide a URL, and may customize the HTTP GET executor, status code checks, and data validity checks.

    The default behavior is to allow only HTTP status code 200 (OK) and to check if the downloaded data is a valid CSV file.

    Since:
    8.4.0
    • Field Detail

      • LOG

        protected static final org.slf4j.Logger LOG
    • Constructor Detail

      • RemoteDatasourceDownloader

        public RemoteDatasourceDownloader​(String url)
        Creates a new remote data source downloader with the specified URL.
        Parameters:
        url - The URL to download data from. Must not be null or empty.
        Throws:
        IllegalArgumentException - if the URL is null or empty
    • Method Detail

      • allowStatusCodes

        public RemoteDatasourceDownloader allowStatusCodes​(Set<Integer> allowedStatusCodes)
        Sets the allowed HTTP status codes for the download. If the response status code is not one of the these codes, the download will fail with a DatasourceDownloadException.
        Parameters:
        allowedStatusCodes - the set of allowed HTTP status codes
        Returns:
        This instance for method chaining
      • allowStatusCodes

        public RemoteDatasourceDownloader allowStatusCodes​(IntPredicate allowedStatusCodes)
        Sets the allowed HTTP status codes for the download. If the response status code is not one of the these codes, the download will fail with a DatasourceDownloadException.
        Parameters:
        allowedStatusCodes - the set of allowed HTTP status codes
        Returns:
        This instance for method chaining
      • validityChecker

        public RemoteDatasourceDownloader validityChecker​(Predicate<byte[]> validityChecker)
        Sets the validity checker for the downloaded data. This checker is a function that takes the raw bytes and checks if the data is valid according to the specific requirements of the datasource. It must return true when the data is valid, and false if the data is invalid. If the data is invalid, the download method will throw a DatasourceDownloadException.
        Parameters:
        validityChecker - The predicate to check the validity of the downloaded data.
      • createCsvValidityChecker

        public static Predicate<byte[]> createCsvValidityChecker​(CSVFormatWrapper formatWrapper)
        Creates a validity checker that checks whether the downloaded binary data is a valid UTF-8 encoded CSV file. Uses the given format wrapper to parse the CSV data.
        Parameters:
        formatWrapper - The CSV format wrapper to use for parsing the data
        Returns:
        A predicate that checks if the data is a valid CSV file according to the specified format.