use of net.runelite.cache.index.FileData in project runelite by runelite.
the class DiskStorageTest method testSaveArchive.
@Test
public void testSaveArchive() throws Exception {
File file = folder.newFolder();
DiskStorage storage = new DiskStorage(file);
Archive archive;
Archive archive2;
try (Store store = new Store(storage)) {
Index index = store.addIndex(0);
archive = index.addArchive(0);
archive2 = index.addArchive(1);
FileData[] fileData = new FileData[1];
archive.setFileData(fileData);
fileData[0] = new FileData();
FileData[] fileData2 = new FileData[1];
archive2.setFileData(fileData2);
fileData2[0] = new FileData();
byte[] data = "test".getBytes();
Container container = new Container(archive.getCompression(), -1);
container.compress(data, null);
byte[] compressedData = container.data;
storage.saveArchive(archive, compressedData);
container = new Container(archive.getCompression(), 42);
container.compress(data, null);
compressedData = container.data;
archive2.setRevision(42);
storage.saveArchive(archive2, compressedData);
store.save();
}
storage = new DiskStorage(file);
try (Store store = new Store(storage)) {
store.load();
Index index = store.findIndex(0);
Archive archive2_1 = index.getArchive(0);
Archive archive2_2 = index.getArchive(1);
byte[] comprsesedData = storage.loadArchive(archive2_1);
byte[] data = archive2_1.decompress(comprsesedData);
assertArrayEquals("test".getBytes(), data);
assertEquals(archive.getCrc(), archive2_1.getCrc());
assertEquals(archive.getRevision(), archive2_1.getRevision());
comprsesedData = storage.loadArchive(archive2_2);
data = archive2_2.decompress(comprsesedData);
assertArrayEquals("test".getBytes(), data);
assertEquals(archive2.getCrc(), archive2_2.getCrc());
assertEquals(archive2.getRevision(), archive2_2.getRevision());
}
}
use of net.runelite.cache.index.FileData in project runelite by runelite.
the class CacheServerTest method addInitialFilesToStore.
private void addInitialFilesToStore(Store store) throws FileNotFoundException, IOException {
Storage storage = store.getStorage();
Index index = store.addIndex(0);
Archive archive = index.addArchive(0);
FileData[] files = new FileData[1];
archive.setFileData(files);
FileData file = files[0] = new FileData();
file.setNameHash(7);
byte[] data = "test".getBytes();
Container container = new Container(archive.getCompression(), -1);
container.compress(data, null);
byte[] compressedData = container.data;
storage.saveArchive(archive, compressedData);
}
use of net.runelite.cache.index.FileData in project runelite by runelite.
the class CacheServerTest method testServer.
@Test
public void testServer() throws Exception {
try (Store store = new Store(folder.newFolder());
CacheServer server = new CacheServer(store, REVISION)) {
addInitialFilesToStore(store);
store.save();
server.start();
try (Store store2 = new Store(folder.newFolder());
CacheClient client = new CacheClient(store2, HOST, REVISION)) {
client.connect();
client.handshake().get();
client.download();
Index index = store2.findIndex(0);
Archive archive = index.getArchive(0);
FileData[] files = archive.getFileData();
FileData file = files[0];
assertEquals(7, file.getNameHash());
Storage storage = store2.getStorage();
byte[] data = storage.loadArchive(archive);
data = archive.decompress(data);
assertArrayEquals("test".getBytes(), data);
assertEquals(store.getIndexes().get(0).getArchive(0).getCrc(), archive.getCrc());
}
}
}
use of net.runelite.cache.index.FileData in project runelite by runelite.
the class CacheStorage method save.
@Override
public void save(Store store) throws IOException {
for (Index index : store.getIndexes()) {
IndexEntry entry = cacheDao.createIndex(con, cacheEntry, index.getId(), index.getCrc(), index.getRevision());
for (Archive archive : index.getArchives()) {
ArchiveEntry archiveEntry = cacheDao.findArchive(con, entry, archive.getArchiveId(), archive.getNameHash(), archive.getCrc(), archive.getRevision());
if (archiveEntry == null) {
byte[] hash = archive.getHash();
archiveEntry = cacheDao.createArchive(con, entry, archive.getArchiveId(), archive.getNameHash(), archive.getCrc(), archive.getRevision(), hash);
for (FileData file : archive.getFileData()) {
cacheDao.associateFileToArchive(con, archiveEntry, file.getId(), file.getNameHash());
}
}
cacheDao.associateArchiveToIndex(con, archiveEntry, entry);
}
}
}
Aggregations