This is a typical use for CompletableFuture - downloading a number of numbers of files from one or more servers in the background, and processing the content once they all have been downloaded. All downloads are performed asynchrounously.
If its not clear from the code and the debug output, the sequence is:
- the file which contains the list of the other files is downloaded first
- after that completes, the file is parsed for the names of the other files
- downloading is prepared for each of the listed files
- all files are downloaded in parallel
- the files which are smaller and faster to download (typically) complete first
- after all the files have been downloaded, the function which consumes the files is called
The interesting bit is the downloadFiles method which defines the processing chain