wiki-scraper/cache: Fix NPE

This commit is contained in:
Owain van Brakel
2019-08-15 23:47:59 +02:00
parent 8239be4b75
commit 1c45af2404
2 changed files with 26 additions and 5 deletions

View File

@@ -112,8 +112,13 @@ public class DiskStorage implements Storage
public byte[] readIndex(int indexId) throws IOException
{
IndexEntry entry = index255.read(indexId);
byte[] indexData = data.read(index255.getIndexFileId(), entry.getId(), entry.getSector(), entry.getLength());
return indexData;
if (entry != null)
{
byte[] indexData = data.read(index255.getIndexFileId(), entry.getId(), entry.getSector(), entry.getLength());
return indexData;
}
return null;
}
private void loadIndex(Index index) throws IOException
@@ -121,6 +126,12 @@ public class DiskStorage implements Storage
logger.trace("Loading index {}", index.getId());
byte[] indexData = readIndex(index.getId());
if (indexData == null)
{
return;
}
Container res = Container.decompress(indexData, null);
byte[] data = res.data;

View File

@@ -27,6 +27,9 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import net.runelite.cache.fs.Store;
import net.runelite.data.dump.MediaWiki;
import net.runelite.data.dump.wiki.NpcStatsDumper;
@@ -40,9 +43,16 @@ public class App
public static void main(String[] args) throws IOException
{
final File home = new File(System.getProperty("user.home"));
final Store cacheStore = new Store(new File(home,
"jagexcache" + File.separator + "oldschool" + File.separator + "LIVE"));
Path path = Paths.get(System.getProperty("user.home"), "jagexcache" + File.separator + "oldschool" + File.separator + "LIVE");
final File jagexcache = new File(String.valueOf(path));
if (!Files.exists(path))
{
return;
}
final Store cacheStore = new Store(jagexcache);
cacheStore.load();
// Try to make this go faster (probably not very smart)