Retry reading the string from disk in downloadString.

Will hopefully make it a bit more reliable.
This commit is contained in:
modmuss50
2022-09-05 19:28:49 +01:00
parent c5def7a594
commit d2ece2e409
2 changed files with 25 additions and 12 deletions

View File

@@ -114,22 +114,21 @@ public class DownloadBuilder {
}
public String downloadString(Path cache) throws DownloadException {
withRetries(() -> {
return withRetries(() -> {
build().downloadPath(cache);
return null;
});
try {
return Files.readString(cache, StandardCharsets.UTF_8);
} catch (IOException e) {
try {
Files.delete(cache);
} catch (IOException ex) {
// Ignored
}
return Files.readString(cache, StandardCharsets.UTF_8);
} catch (IOException e) {
try {
Files.deleteIfExists(cache);
} catch (IOException ex) {
// Ignored
}
throw new DownloadException("Failed to download and read string", e);
}
throw new DownloadException("Failed to download and read string", e);
}
});
}
private <T> T withRetries(DownloadSupplier<T> supplier) throws DownloadException {