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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations