RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.fs.cache.archive.Archive Class Reference

Represents an archive within the Cache. More...

Public Member Functions

ByteBuffer getData (String name)
 Returns the data within the ArchiveSector for the specified String name.

Static Public Member Functions

static Archive decode (ByteBuffer data) throws IOException
 Decodes the data within this Archive.

Private Member Functions

 Archive (Int2ObjectMap< ArchiveSector > sectors)
 Constructs a new Archive with the specified Map of ArchiveSectors.
Optional< ArchiveSectorgetSector (int hash)
 Retrieves an Optional<ArchiveSector> for the specified hash.
Optional< ArchiveSectorgetSector (String name)
 Retrieves an Optional<ArchiveSector> for the specified name.

Private Attributes

final Int2ObjectMap< ArchiveSectorsectors
 A Map of ArchiveSector hashes to ArchiveSectors.

Detailed Description

Represents an archive within the Cache.

An archive contains varied amounts of ArchiveSectors which contain compressed file system data.

Author
Ryley Kimmel ryley.nosp@m..kim.nosp@m.mel@l.nosp@m.ive..nosp@m.com

Definition at line 25 of file Archive.java.

Constructor & Destructor Documentation

◆ Archive()

com.runehive.fs.cache.archive.Archive.Archive ( Int2ObjectMap< ArchiveSector > sectors)
private

Constructs a new Archive with the specified Map of ArchiveSectors.

Parameters
sectorsThe Map of sectors within this archive.

Definition at line 36 of file Archive.java.

36 {
37 this.sectors = sectors;
38 }

References sectors.

Referenced by decode().

Here is the caller graph for this function:

Member Function Documentation

◆ decode()

Archive com.runehive.fs.cache.archive.Archive.decode ( ByteBuffer data) throws IOException
static

Decodes the data within this Archive.

Parameters
dataThe encoded data within this archive.
Returns
Returns an Archive with the decoded data, never
null
.
Exceptions
IOExceptionIf some I/O exception occurs.

Definition at line 48 of file Archive.java.

48 {
49 int length = ByteBufferUtil.getMedium(data);
50 int compressedLength = ByteBufferUtil.getMedium(data);
51
52 byte[] uncompressedData = data.array();
53
54 if (compressedLength != length) {
55 uncompressedData = CompressionUtil.unbzip2Headerless(data.array(), INDEX_SIZE, compressedLength);
56 data = ByteBuffer.wrap(uncompressedData);
57 }
58
59 int total = data.getShort() & 0xFF;
60 int offset = data.position() + total * 10;
61
62 Int2ObjectMap<ArchiveSector> sectors = new Int2ObjectOpenHashMap<>(total);
63 for (int i = 0; i < total; i++) {
64 int hash = data.getInt();
65 length = ByteBufferUtil.getMedium(data);
66 compressedLength = ByteBufferUtil.getMedium(data);
67
68 byte[] sectorData = new byte[length];
69
70 if (length != compressedLength) {
71 sectorData = CompressionUtil.unbzip2Headerless(uncompressedData, offset, compressedLength);
72 } else {
73 System.arraycopy(uncompressedData, offset, sectorData, 0, length);
74 }
75
76 sectors.put(hash, new ArchiveSector(ByteBuffer.wrap(sectorData), hash));
77 offset += compressedLength;
78 }
79
80 return new Archive(sectors);
81 }

References Archive(), com.runehive.fs.util.ByteBufferUtil.getMedium(), sectors, and com.runehive.fs.util.CompressionUtil.unbzip2Headerless().

Referenced by com.runehive.fs.cache.FileSystem.create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getData()

ByteBuffer com.runehive.fs.cache.archive.Archive.getData ( String name)

Returns the data within the ArchiveSector for the specified String name.

Parameters
nameThe name of the ArchiveSector.
Returns
The data within the ArchiveSector or nothing, this method fails-fast if no ArchiveSector exists for the specified
name
.

Definition at line 113 of file Archive.java.

113 {
114 Optional<ArchiveSector> optionalData = getSector(name);
115 Preconditions.checkArgument(optionalData.isPresent());
116 ArchiveSector dataSector = optionalData.get();
117 return dataSector.getData();
118 }

References com.runehive.fs.cache.archive.ArchiveSector.getData(), and getSector().

Here is the call graph for this function:

◆ getSector() [1/2]

Optional< ArchiveSector > com.runehive.fs.cache.archive.Archive.getSector ( int hash)
private

Retrieves an Optional<ArchiveSector> for the specified hash.

Parameters
hashThe archive sectors hash.
Returns
The optional container.

Definition at line 89 of file Archive.java.

89 {
90 return Optional.ofNullable(sectors.get(hash));
91 }

References sectors.

Referenced by getData(), and getSector().

Here is the caller graph for this function:

◆ getSector() [2/2]

Optional< ArchiveSector > com.runehive.fs.cache.archive.Archive.getSector ( String name)
private

Retrieves an Optional<ArchiveSector> for the specified name.

Parameters
nameThe archive sectors name.
Returns
The optional container.

Definition at line 99 of file Archive.java.

99 {
100 int hash = StringUtils.hashArchive(name);
101 return getSector(hash);
102 }

References getSector(), and com.runehive.util.StringUtils.hashArchive().

Here is the call graph for this function:

Member Data Documentation

◆ sectors

final Int2ObjectMap<ArchiveSector> com.runehive.fs.cache.archive.Archive.sectors
private

A Map of ArchiveSector hashes to ArchiveSectors.

Definition at line 28 of file Archive.java.

Referenced by Archive(), decode(), and getSector().


The documentation for this class was generated from the following file: