This commit is contained in:
Glavo 2025-08-01 22:42:14 +08:00
parent b7705df2a4
commit 081f01b9ae
4 changed files with 9 additions and 7 deletions

View File

@ -35,7 +35,12 @@ import static org.jackhuang.hmcl.util.logging.Logger.LOG;
* *
* @author Glavo * @author Glavo
*/ */
public class CacheFileTask extends FetchTask<Path> { public final class CacheFileTask extends FetchTask<Path> {
public CacheFileTask(@NotNull URI uri) {
super(List.of(uri), DEFAULT_RETRY);
}
public CacheFileTask(@NotNull URI uri, int retry) { public CacheFileTask(@NotNull URI uri, int retry) {
super(List.of(uri), retry); super(List.of(uri), retry);
} }
@ -103,5 +108,4 @@ public class CacheFileTask extends FetchTask<Path> {
} }
}; };
} }
} }

View File

@ -44,6 +44,8 @@ import static org.jackhuang.hmcl.util.Lang.threadPool;
import static org.jackhuang.hmcl.util.logging.Logger.LOG; import static org.jackhuang.hmcl.util.logging.Logger.LOG;
public abstract class FetchTask<T> extends Task<T> { public abstract class FetchTask<T> extends Task<T> {
protected static final int DEFAULT_RETRY = 3;
protected final List<URI> uris; protected final List<URI> uris;
protected final int retry; protected final int retry;
protected CacheRepository repository = CacheRepository.getInstance(); protected CacheRepository repository = CacheRepository.getInstance();
@ -60,8 +62,6 @@ public abstract class FetchTask<T> extends Task<T> {
setExecutor(download()); setExecutor(download());
} }
public void setCacheRepository(CacheRepository repository) { public void setCacheRepository(CacheRepository repository) {
this.repository = repository; this.repository = repository;
} }

View File

@ -133,7 +133,7 @@ public class FileDownloadTask extends FetchTask<Void> {
* @param integrityCheck the integrity check to perform, null if no integrity check is to be performed * @param integrityCheck the integrity check to perform, null if no integrity check is to be performed
*/ */
public FileDownloadTask(List<URI> uris, Path path, IntegrityCheck integrityCheck) { public FileDownloadTask(List<URI> uris, Path path, IntegrityCheck integrityCheck) {
this(uris, path, integrityCheck, 3); this(uris, path, integrityCheck, DEFAULT_RETRY);
} }
/** /**

View File

@ -36,8 +36,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
*/ */
public final class GetTask extends FetchTask<String> { public final class GetTask extends FetchTask<String> {
private static final int DEFAULT_RETRY = 3;
private final Charset charset; private final Charset charset;
public GetTask(URI url) { public GetTask(URI url) {