mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[FIX] Ещё 1 способ при загрузке группы URL (в основном для модулей).
This commit is contained in:
parent
c6dad02c9b
commit
c6e6dd672f
2 changed files with 26 additions and 1 deletions
|
@ -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;
|
||||
|
|
2
modules
2
modules
|
@ -1 +1 @@
|
|||
Subproject commit a3c8661d7e6f2af4fc64748945aec73dc55e0a7b
|
||||
Subproject commit dd140777b7b27989a9e40b31590ca5345a963970
|
Loading…
Reference in a new issue