Add basic store object

This commit is contained in:
Adam
2015-10-12 21:16:03 -04:00
parent 57a55d43e1
commit 50a30553b9
5 changed files with 19 additions and 7 deletions

View File

@@ -15,12 +15,14 @@ public class DataFile implements Closeable
private static final int SECTOR_SIZE = 520;
private final Store store;
private final int datafileId;
private final RandomAccessFile dat;
private final byte[] readCachedBuffer = new byte[SECTOR_SIZE];
public DataFile(int id, File file) throws FileNotFoundException
public DataFile(Store store, int id, File file) throws FileNotFoundException
{
this.store = store;
this.datafileId = id;
dat = new RandomAccessFile(file, "rw");
}

View File

@@ -12,12 +12,14 @@ public class IndexFile
private static final Logger logger = LoggerFactory.getLogger(IndexFile.class);
private static final int INDEX_ENTRY_LEN = 6;
private int indexFileId;
private RandomAccessFile idx;
private final Store store;
private final int indexFileId;
private final RandomAccessFile idx;
private final byte[] buffer = new byte[6];
public IndexFile(int indexFileId, File file) throws FileNotFoundException
public IndexFile(Store store, int indexFileId, File file) throws FileNotFoundException
{
this.store = store;
this.indexFileId = indexFileId;
this.idx = new RandomAccessFile(file, "rw");
}

View File

@@ -0,0 +1,5 @@
package net.runelite.cache.fs;
public class Store
{
}

View File

@@ -12,7 +12,8 @@ public class DataFileTest
public void test1() throws IOException
{
File file = new File("d:/rs/07/test/test.dat");
DataFile df = new DataFile(42, file);
Store store = new Store();
DataFile df = new DataFile(store, 42, file);
int sector = df.write(3, ByteBuffer.wrap("test".getBytes()));
ByteBuffer buf = df.read(3, sector, 4);
String str = new String(buf.array());
@@ -27,7 +28,8 @@ public class DataFileTest
for (int i = 0; i < 1024; ++i) b[i] = (byte) i;
File file = new File("d:/rs/07/test/test.dat");
DataFile df = new DataFile(42, file);
Store store = new Store();
DataFile df = new DataFile(store, 42, file);
int sector = df.write(0x1FFFF, ByteBuffer.wrap(b));
ByteBuffer buf = df.read(0x1FFFF, sector, b.length);
Assert.assertArrayEquals(b, buf.array());

View File

@@ -11,7 +11,8 @@ public class IndexFileTest
public void test1() throws IOException
{
File file = new File("d:/rs/07/test/test.dat");
IndexFile index = new IndexFile(5, file);
Store store = new Store();
IndexFile index = new IndexFile(store, 5, file);
IndexEntry entry = new IndexEntry(index, 7, 8, 9);
index.write(entry);
IndexEntry entry2 = index.read(7);