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.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* The download provider that changes the real download source in need. * The download provider that changes the real download source in need.
@ -59,26 +60,25 @@ public class AdaptedDownloadProvider implements DownloadProvider {
return getPreferredDownloadProvider().injectURL(baseURL); return getPreferredDownloadProvider().injectURL(baseURL);
} }
@Override
public List<URL> getAssetObjectCandidates(String assetObjectLocation) {
return downloadProviderCandidates.stream()
.flatMap(d -> d.getAssetObjectCandidates(assetObjectLocation).stream())
.collect(Collectors.toList());
}
@Override @Override
public List<URL> injectURLWithCandidates(String baseURL) { public List<URL> injectURLWithCandidates(String baseURL) {
List<DownloadProvider> d = downloadProviderCandidates; return downloadProviderCandidates.stream()
List<URL> results = new ArrayList<>(d.size()); .flatMap(d -> d.injectURLWithCandidates(baseURL).stream())
for (DownloadProvider downloadProvider : d) { .collect(Collectors.toList());
results.add(NetworkUtils.toURL(downloadProvider.injectURL(baseURL)));
}
return results;
} }
@Override @Override
public List<URL> injectURLsWithCandidates(List<String> urls) { public List<URL> injectURLsWithCandidates(List<String> urls) {
List<DownloadProvider> d = downloadProviderCandidates; return downloadProviderCandidates.stream()
List<URL> results = new ArrayList<>(d.size()); .flatMap(d -> d.injectURLsWithCandidates(urls).stream())
for (DownloadProvider downloadProvider : d) { .collect(Collectors.toList());
for (String baseURL : urls) {
results.add(NetworkUtils.toURL(downloadProvider.injectURL(baseURL)));
}
}
return results;
} }
@Override @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. * @return the URL that is equivalent to [baseURL], but belongs to your own service provider.
*/ */
default List<URL> injectURLWithCandidates(String baseURL) { 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) { default List<URL> injectURLsWithCandidates(List<String> urls) {

View File

@ -151,7 +151,7 @@ public class LibraryDownloadTask extends Task<Void> {
try { try {
return NetworkUtils.urlExists(xzURL); return NetworkUtils.urlExists(xzURL);
} catch (IOException e) { } 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);
} }
} }
} }