Add caching for the h3 values on remote accesses

This commit is contained in:
Maschell 2019-04-30 12:03:39 +02:00
parent 532501f3a5
commit 3296b1befe

View File

@ -18,6 +18,8 @@ package de.mas.wiiu.jnus.implementations;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import de.mas.wiiu.jnus.Settings;
@ -46,16 +48,25 @@ public class NUSDataProviderRemote implements NUSDataProvider, Parallelizable {
return String.format("%016x/%08X", titleID, content.getID());
}
Map<Integer, Optional<byte[]>> h3Hashes = new HashMap<>();
@Override
public Optional<byte[]> getContentH3Hash(Content content) throws IOException {
Optional<byte[]> resOpt = h3Hashes.get(content.getID());
if (resOpt == null) {
NUSDownloadService downloadService = NUSDownloadService.getDefaultInstance();
String url = getRemoteURL(content) + Settings.H3_EXTENTION;
System.out.println(url);
byte[] res = downloadService.downloadToByteArray(url);
if (res == null || res.length == 0) {
return Optional.empty();
resOpt = Optional.empty();
} else {
resOpt = Optional.of(res);
}
return Optional.of(res);
h3Hashes.put(content.getID(), resOpt);
}
return resOpt;
}
@Override