Search in sources :

Example 6 with FileData

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());
    }
}
Also used : Container(net.runelite.cache.fs.Container) Archive(net.runelite.cache.fs.Archive) Store(net.runelite.cache.fs.Store) Index(net.runelite.cache.fs.Index) File(java.io.File) FileData(net.runelite.cache.index.FileData) Test(org.junit.Test)

Example 7 with FileData

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);
}
Also used : Container(net.runelite.cache.fs.Container) Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) Index(net.runelite.cache.fs.Index) FileData(net.runelite.cache.index.FileData)

Example 8 with FileData

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());
        }
    }
}
Also used : CacheClient(net.runelite.cache.client.CacheClient) Archive(net.runelite.cache.fs.Archive) Storage(net.runelite.cache.fs.Storage) Store(net.runelite.cache.fs.Store) Index(net.runelite.cache.fs.Index) FileData(net.runelite.cache.index.FileData) Test(org.junit.Test)

Example 9 with FileData

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);
        }
    }
}
Also used : Archive(net.runelite.cache.fs.Archive) IndexEntry(net.runelite.cache.updater.beans.IndexEntry) Index(net.runelite.cache.fs.Index) ArchiveEntry(net.runelite.cache.updater.beans.ArchiveEntry) FileData(net.runelite.cache.index.FileData)

Aggregations

FileData (net.runelite.cache.index.FileData)9 Test (org.junit.Test)5 Archive (net.runelite.cache.fs.Archive)4 Index (net.runelite.cache.fs.Index)4 File (java.io.File)3 Random (java.util.Random)2 Container (net.runelite.cache.fs.Container)2 Storage (net.runelite.cache.fs.Storage)2 Store (net.runelite.cache.fs.Store)2 CacheClient (net.runelite.cache.client.CacheClient)1 ArchiveData (net.runelite.cache.index.ArchiveData)1 IndexData (net.runelite.cache.index.IndexData)1 ArchiveEntry (net.runelite.cache.updater.beans.ArchiveEntry)1 IndexEntry (net.runelite.cache.updater.beans.IndexEntry)1