Search in sources :

Example 1 with Container

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

the class DataFileTest method testGZipCompression.

@Test
public void testGZipCompression() throws IOException {
    DataFile df = new DataFile(folder.newFile());
    Container container = new Container(CompressionType.GZ, 0);
    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)

Example 2 with Container

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

the class DataFileTest method testEncGz.

@Test
public void testEncGz() throws IOException {
    File file = folder.newFile();
    int[] keys = new int[] { 4, 8, 15, 16 };
    DataFile df = new DataFile(file);
    Container container = new Container(CompressionType.GZ, 42);
    container.compress("testtesttesttest1".getBytes(), keys);
    byte[] compressedData = container.data;
    DataFileWriteResult res = df.write(42, 3, compressedData);
    compressedData = df.read(42, 3, res.sector, res.compressedLength);
    Container res2 = Container.decompress(compressedData, keys);
    byte[] buf = res2.data;
    String str = new String(buf);
    Assert.assertEquals("testtesttesttest1", str);
    Assert.assertEquals(42, res2.revision);
}
Also used : Container(net.runelite.cache.fs.Container) File(java.io.File) Test(org.junit.Test)

Example 3 with Container

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

the class DataFileTest method test1.

@Test
public void test1() throws IOException {
    File file = folder.newFile();
    DataFile df = new DataFile(file);
    Container container = new Container(CompressionType.NONE, 0);
    container.compress("test".getBytes(), null);
    byte[] compressedData = container.data;
    DataFileWriteResult res = df.write(42, 3, compressedData);
    compressedData = df.read(42, 3, 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) File(java.io.File) Test(org.junit.Test)

Example 4 with Container

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

the class DataFileTest method testEnc.

@Test
public void testEnc() throws IOException {
    File file = folder.newFile();
    int[] keys = new int[] { 4, 8, 15, 16 };
    DataFile df = new DataFile(file);
    Container container = new Container(CompressionType.NONE, 42);
    container.compress("testtesttesttest1".getBytes(), keys);
    byte[] compressedData = container.data;
    DataFileWriteResult res = df.write(42, 3, compressedData);
    compressedData = df.read(42, 3, res.sector, res.compressedLength);
    Container res2 = Container.decompress(compressedData, keys);
    byte[] buf = res2.data;
    String str = new String(buf);
    Assert.assertEquals("testtesttesttest1", str);
    Assert.assertEquals(42, res2.revision);
}
Also used : Container(net.runelite.cache.fs.Container) File(java.io.File) Test(org.junit.Test)

Example 5 with Container

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

the class ArchiveResponseEncoderTest method testEncode.

@Test
public void testEncode() throws Exception {
    byte[] data = new byte[1000];
    Random random = new Random(42L);
    random.nextBytes(data);
    Container container = new Container(CompressionType.NONE, -1);
    container.compress(data, null);
    byte[] compressedData = container.data;
    ArchiveResponsePacket archiveResponse = new ArchiveResponsePacket();
    archiveResponse.setIndex(0);
    archiveResponse.setArchive(1);
    archiveResponse.setData(compressedData);
    ByteBuf buf = Unpooled.buffer(1024);
    ArchiveResponseEncoder encoder = new ArchiveResponseEncoder();
    encoder.encode(null, archiveResponse, buf);
    ArchiveResponseDecoder decoder = new ArchiveResponseDecoder();
    List<Object> out = new ArrayList<>();
    decoder.decode(null, buf, out);
    Assert.assertEquals(1, out.size());
    ArchiveResponsePacket response = (ArchiveResponsePacket) out.get(0);
    Assert.assertEquals(archiveResponse.getIndex(), response.getIndex());
    Assert.assertEquals(archiveResponse.getArchive(), response.getArchive());
    Assert.assertArrayEquals(archiveResponse.getData(), response.getData());
    byte[] decompressedData = Container.decompress(response.getData(), null).data;
    Assert.assertArrayEquals(data, decompressedData);
}
Also used : Container(net.runelite.cache.fs.Container) Random(java.util.Random) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) ArchiveResponsePacket(net.runelite.protocol.api.update.ArchiveResponsePacket) ArchiveResponseDecoder(net.runelite.protocol.update.decoders.ArchiveResponseDecoder) 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