From 63082f5a5e25cbdaecfa2fef140bb5eb28fcaf9a Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Sun, 21 Jun 2020 17:12:51 +0800 Subject: [PATCH] fix: #731 --- .../download/AdaptedDownloadProvider.java | 28 +++++++++---------- .../hmcl/download/DownloadProvider.java | 2 +- .../download/game/LibraryDownloadTask.java | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/AdaptedDownloadProvider.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/AdaptedDownloadProvider.java index 6f223553f..9dd64cc63 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/AdaptedDownloadProvider.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/AdaptedDownloadProvider.java @@ -22,6 +22,7 @@ import org.jackhuang.hmcl.util.io.NetworkUtils; import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** * The download provider that changes the real download source in need. @@ -59,26 +60,25 @@ public class AdaptedDownloadProvider implements DownloadProvider { return getPreferredDownloadProvider().injectURL(baseURL); } + @Override + public List getAssetObjectCandidates(String assetObjectLocation) { + return downloadProviderCandidates.stream() + .flatMap(d -> d.getAssetObjectCandidates(assetObjectLocation).stream()) + .collect(Collectors.toList()); + } + @Override public List injectURLWithCandidates(String baseURL) { - List d = downloadProviderCandidates; - List results = new ArrayList<>(d.size()); - for (DownloadProvider downloadProvider : d) { - results.add(NetworkUtils.toURL(downloadProvider.injectURL(baseURL))); - } - return results; + return downloadProviderCandidates.stream() + .flatMap(d -> d.injectURLWithCandidates(baseURL).stream()) + .collect(Collectors.toList()); } @Override public List injectURLsWithCandidates(List urls) { - List d = downloadProviderCandidates; - List results = new ArrayList<>(d.size()); - for (DownloadProvider downloadProvider : d) { - for (String baseURL : urls) { - results.add(NetworkUtils.toURL(downloadProvider.injectURL(baseURL))); - } - } - return results; + return downloadProviderCandidates.stream() + .flatMap(d -> d.injectURLsWithCandidates(urls).stream()) + .collect(Collectors.toList()); } @Override diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DownloadProvider.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DownloadProvider.java index 7ef333044..a1f6fd45d 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DownloadProvider.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DownloadProvider.java @@ -60,7 +60,7 @@ public interface DownloadProvider { * @return the URL that is equivalent to [baseURL], but belongs to your own service provider. */ default List injectURLWithCandidates(String baseURL) { - return Collections.singletonList(NetworkUtils.toURL(baseURL)); + return Collections.singletonList(NetworkUtils.toURL(injectURL(baseURL))); } default List injectURLsWithCandidates(List urls) { diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/LibraryDownloadTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/LibraryDownloadTask.java index 871d17942..106fbc367 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/LibraryDownloadTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/LibraryDownloadTask.java @@ -151,7 +151,7 @@ public class LibraryDownloadTask extends Task { try { return NetworkUtils.urlExists(xzURL); } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to test for url existence: " + rawUrl + ".pack.xz", e); + LOG.log(Level.WARNING, "Failed to test for url existence: " + url + ".pack.xz", e); } } }