Search in sources :

Example 6 with Container

use of net.runelite.cache.fs.Container in project runelite by runelite.

the class DiskStorage method saveIndex.

private void saveIndex(Index index) throws IOException {
    IndexData indexData = index.toIndexData();
    byte[] data = indexData.writeIndexData();
    // index data revision is always -1
    Container container = new Container(index.getCompression(), -1);
    container.compress(data, null);
    byte[] compressedData = container.data;
    DataFileWriteResult res = this.data.write(index255.getIndexFileId(), index.getId(), compressedData);
    index255.write(new IndexEntry(index255, index.getId(), res.sector, res.compressedLength));
    Crc32 crc = new Crc32();
    crc.update(compressedData, 0, compressedData.length);
    index.setCrc(crc.getHash());
}
Also used : Container(net.runelite.cache.fs.Container) IndexData(net.runelite.cache.index.IndexData) Crc32(net.runelite.cache.util.Crc32)

Example 7 with Container

use of net.runelite.cache.fs.Container in project runelite by runelite.

the class DiskStorage method loadIndex.

private void loadIndex(Index index) throws IOException {
    logger.trace("Loading index {}", index.getId());
    byte[] indexData = readIndex(index.getId());
    Container res = Container.decompress(indexData, null);
    byte[] data = res.data;
    IndexData id = new IndexData();
    id.load(data);
    index.setProtocol(id.getProtocol());
    index.setRevision(id.getRevision());
    index.setNamed(id.isNamed());
    for (ArchiveData ad : id.getArchives()) {
        Archive archive = index.addArchive(ad.getId());
        archive.setNameHash(ad.getNameHash());
        archive.setCrc(ad.getCrc());
        archive.setRevision(ad.getRevision());
        archive.setFileData(ad.getFiles());
        assert ad.getFiles().length > 0;
    }
    index.setCrc(res.crc);
    index.setCompression(res.compression);
    assert res.revision == -1;
}
Also used : Container(net.runelite.cache.fs.Container) Archive(net.runelite.cache.fs.Archive) IndexData(net.runelite.cache.index.IndexData) ArchiveData(net.runelite.cache.index.ArchiveData)

Example 8 with Container

use of net.runelite.cache.fs.Container 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 9 with Container

use of net.runelite.cache.fs.Container in project runelite by runelite.

the class DataFileTest method test2.

@Test
public void test2() throws IOException {
    byte[] b = new byte[1024];
    for (int i = 0; i < 1024; ++i) {
        b[i] = (byte) i;
    }
    File file = folder.newFile();
    DataFile df = new DataFile(file);
    Container container = new Container(CompressionType.BZ2, 42);
    container.compress(b, null);
    byte[] compressedData = container.data;
    DataFileWriteResult res = df.write(42, 0x1FFFF, compressedData);
    compressedData = df.read(42, 0x1FFFF, res.sector, res.compressedLength);
    Container res2 = Container.decompress(compressedData, null);
    byte[] buf = res2.data;
    Assert.assertArrayEquals(b, buf);
}
Also used : Container(net.runelite.cache.fs.Container) File(java.io.File) Test(org.junit.Test)

Example 10 with Container

use of net.runelite.cache.fs.Container in project runelite by runelite.

the class DataFileTest method testBZip2Compression.

@Test
public void testBZip2Compression() throws IOException {
    DataFile df = new DataFile(folder.newFile());
    Container container = new Container(CompressionType.BZ2, 5);
    container.compress("test".getBytes(), null);
    byte[] compressedData = container.data;
    DataFileWriteResult res = df.write(41, 4, compressedData);
    compressedData = df.read(41, 4, res.sector, res.compressedLength);
    Container res2 = Container.decompress(compressedData, null);
    byte[] buf = res2.data;
    String str = new String(buf);
    Assert.assertEquals("test", str);
}
Also used : Container(net.runelite.cache.fs.Container) Test(org.junit.Test)

Aggregations

Container (net.runelite.cache.fs.Container)14 Test (org.junit.Test)8 File (java.io.File)5 Archive (net.runelite.cache.fs.Archive)3 Index (net.runelite.cache.fs.Index)2 FileData (net.runelite.cache.index.FileData)2 IndexData (net.runelite.cache.index.IndexData)2 ByteBuf (io.netty.buffer.ByteBuf)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)1 FSFile (net.runelite.cache.fs.FSFile)1 Storage (net.runelite.cache.fs.Storage)1 Store (net.runelite.cache.fs.Store)1 ArchiveData (net.runelite.cache.index.ArchiveData)1 Crc32 (net.runelite.cache.util.Crc32)1 FileEntry (net.runelite.http.service.cache.beans.FileEntry)1 ArchiveResponsePacket (net.runelite.protocol.api.update.ArchiveResponsePacket)1 ArchiveResponseDecoder (net.runelite.protocol.update.decoders.ArchiveResponseDecoder)1 Connection (org.sql2o.Connection)1