[FIX] Ещё 1 способ при загрузке группы URL (в основном для модулей).

This commit is contained in:
Zaxar163 2019-12-18 17:02:56 +01:00
parent c6dad02c9b
commit c6e6dd672f
No known key found for this signature in database
GPG key ID: 1FE4F2E1F053831B
2 changed files with 26 additions and 1 deletions

View file

@ -79,6 +79,13 @@ public void downloadListInOneThread(List<SizedFile> files, String baseURL, Path
downloadFile(url, targetDir.resolve(currentFile.filePath), currentFile.size);
}
}
public void downloadListInOneThreadSimple(List<SizedFile> files, String baseURL, Path targetDir) throws URISyntaxException, IOException {
for(AsyncDownloader.SizedFile currentFile : files)
{
downloadFile(new URL(baseURL + currentFile.urlPath), targetDir.resolve(currentFile.filePath), currentFile.size);
}
}
public List<List<SizedFile>> sortFiles(List<SizedFile> files, int threads)
{
files.sort(Comparator.comparingLong((f) -> -f.size));
@ -116,6 +123,24 @@ public CompletableFuture[] runDownloadList(List<List<SizedFile>> files, String b
return futures;
}
@SuppressWarnings("rawtypes")
public CompletableFuture[] runDownloadListSimple(List<List<SizedFile>> files, String baseURL, Path targetDir, Executor executor) {
int threads = files.size();
CompletableFuture[] futures = new CompletableFuture[threads];
for(int i=0;i<threads;++i)
{
List<SizedFile> currentTasks = files.get(i);
futures[i] = CompletableFuture.runAsync(() -> {
try {
downloadListInOneThreadSimple(currentTasks, baseURL, targetDir);
} catch (URISyntaxException | IOException e) {
throw new CompletionException(e);
}
}, executor);
}
return futures;
}
public void transfer(InputStream input, Path file, long size) throws IOException {
try (OutputStream fileOutput = IOHelper.newOutput(file)) {
long downloaded = 0L;

@ -1 +1 @@
Subproject commit a3c8661d7e6f2af4fc64748945aec73dc55e0a7b
Subproject commit dd140777b7b27989a9e40b31590ca5345a963970