This commit is contained in:
huanghongxun 2020-06-21 17:12:51 +08:00
parent c24ef2a200
commit 63082f5a5e
3 changed files with 16 additions and 16 deletions

View File

@ -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<URL> getAssetObjectCandidates(String assetObjectLocation) {
return downloadProviderCandidates.stream()
.flatMap(d -> d.getAssetObjectCandidates(assetObjectLocation).stream())
.collect(Collectors.toList());
}
@Override
public List<URL> injectURLWithCandidates(String baseURL) {
List<DownloadProvider> d = downloadProviderCandidates;
List<URL> 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<URL> injectURLsWithCandidates(List<String> urls) {
List<DownloadProvider> d = downloadProviderCandidates;
List<URL> 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

View File

@ -60,7 +60,7 @@ public interface DownloadProvider {
* @return the URL that is equivalent to [baseURL], but belongs to your own service provider.
*/
default List<URL> injectURLWithCandidates(String baseURL) {
return Collections.singletonList(NetworkUtils.toURL(baseURL));
return Collections.singletonList(NetworkUtils.toURL(injectURL(baseURL)));
}
default List<URL> injectURLsWithCandidates(List<String> urls) {

View File

@ -151,7 +151,7 @@ public class LibraryDownloadTask extends Task<Void> {
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);
}
}
}