1package com.runehive.fs.cache.archive;
3import com.google.common.base.Preconditions;
4import com.runehive.fs.cache.Cache;
5import com.runehive.fs.util.ByteBufferUtil;
6import com.runehive.fs.util.CompressionUtil;
7import com.runehive.util.StringUtils;
8import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
9import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
11import java.io.IOException;
12import java.nio.ByteBuffer;
14import java.util.Optional;
16import static com.runehive.fs.cache.Cache.INDEX_SIZE;
28 private final Int2ObjectMap<ArchiveSector>
sectors;
52 byte[] uncompressedData = data.array();
54 if (compressedLength != length) {
56 data = ByteBuffer.wrap(uncompressedData);
59 int total = data.getShort() & 0xFF;
60 int offset = data.position() + total * 10;
62 Int2ObjectMap<ArchiveSector>
sectors =
new Int2ObjectOpenHashMap<>(total);
63 for (
int i = 0; i < total; i++) {
64 int hash = data.getInt();
68 byte[] sectorData =
new byte[length];
70 if (length != compressedLength) {
73 System.arraycopy(uncompressedData, offset, sectorData, 0, length);
77 offset += compressedLength;
89 private Optional<ArchiveSector>
getSector(
int hash) {
90 return Optional.ofNullable(
sectors.get(hash));
99 private Optional<ArchiveSector>
getSector(String name) {
114 Optional<ArchiveSector> optionalData =
getSector(name);
115 Preconditions.checkArgument(optionalData.isPresent());
Optional< ArchiveSector > getSector(int hash)
Retrieves an Optional<ArchiveSector> for the specified hash.
static Archive decode(ByteBuffer data)
Decodes the data within this Archive.
Optional< ArchiveSector > getSector(String name)
Retrieves an Optional<ArchiveSector> for the specified name.
final Int2ObjectMap< ArchiveSector > sectors
A Map of ArchiveSector hashes to ArchiveSectors.
Archive(Int2ObjectMap< ArchiveSector > sectors)
Constructs a new Archive with the specified Map of ArchiveSectors.
ByteBuffer getData(String name)
Returns the data within the ArchiveSector for the specified String name.
Represents a sector within an Archive.
ByteBuffer getData()
Returns the data within this sector.
A static-utility class containing extension or helper methods for ByteBuffers.
static int getMedium(ByteBuffer buffer)
Gets a 24-bit medium integer from the specified ByteBuffer, this method does not mark the ByteBuffers...
A static-utility class containing containing extension or helper methods for compressor-deccompressor...
static byte[] unbzip2Headerless(byte[] data, int offset, int length)
Uncompresses a byte array of b-zipped data that does not contain a header.
static int hashArchive(String string)
Hashes a String using Jagex's algorithm, this method should be used to convert actual names to hashed...