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