Init of store loading, what is datafile id

This commit is contained in:
Adam
2015-10-13 09:59:37 -04:00
parent 4f1f75c88f
commit 2e118bb391
3 changed files with 35 additions and 4 deletions

View File

@@ -1,5 +1,36 @@
package net.runelite.cache.fs;
public class Store
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Store implements Closeable
{
private static final String MAIN_FILE_CACHE_DAT = "main_file_cache.dat2";
private static final String MAIN_FILE_CACHE_IDX = "main_file_cache.idx";
private final DataFile data;
private final IndexFile index255;
private final List<IndexFile> indexFiles = new ArrayList<>();
public Store(File folder) throws IOException
{
data = new DataFile(this, -1/*wtfisthis*/, new File(folder, MAIN_FILE_CACHE_DAT));
index255 = new IndexFile(this, 255, new File(folder, MAIN_FILE_CACHE_IDX + "255"));
for (int i = 0; i < index255.getIndexCount(); ++i)
indexFiles.add(new IndexFile(this, i, new File(folder, MAIN_FILE_CACHE_IDX + i)));
}
@Override
public void close() throws IOException
{
data.close();
index255.close();
for (IndexFile i : indexFiles)
i.close();
}
}

View File

@@ -17,7 +17,7 @@ public class DataFileTest
public void test1() throws IOException
{
File file = folder.newFile();
Store store = new Store();
Store store = new Store(folder.getRoot());
DataFile df = new DataFile(store, 42, file);
int sector = df.write(3, ByteBuffer.wrap("test".getBytes()));
ByteBuffer buf = df.read(3, sector, 4);
@@ -33,7 +33,7 @@ public class DataFileTest
for (int i = 0; i < 1024; ++i) b[i] = (byte) i;
File file = folder.newFile();
Store store = new Store();
Store store = new Store(folder.getRoot());
DataFile df = new DataFile(store, 42, file);
int sector = df.write(0x1FFFF, ByteBuffer.wrap(b));
ByteBuffer buf = df.read(0x1FFFF, sector, b.length);

View File

@@ -16,7 +16,7 @@ public class IndexFileTest
public void test1() throws IOException
{
File file = folder.newFile();
Store store = new Store();
Store store = new Store(folder.getRoot());
IndexFile index = new IndexFile(store, 5, file);
IndexEntry entry = new IndexEntry(index, 7, 8, 9);
index.write(entry);