RuneHive-Game
Loading...
Searching...
No Matches
Index.java
Go to the documentation of this file.
1package dev.advo.fs.fs;
2
3/**
4 * An {@link Index} points to a file in the {@code main_file_cache.dat} file.
5 * @author Graham
6 */
7public final class Index {
8
9 /**
10 * Decodes a buffer into an index.
11 * @param buffer The buffer.
12 * @return The decoded {@link Index}.
13 * @throws IllegalArgumentException if the buffer length is invalid.
14 */
15 public static Index decode(byte[] buffer) {
16 if (buffer.length != FileSystemConstants.INDEX_SIZE) {
17 throw new IllegalArgumentException("Incorrect buffer length.");
18 }
19
20 int size = ((buffer[0] & 0xFF) << 16) | ((buffer[1] & 0xFF) << 8) | (buffer[2] & 0xFF);
21 int block = ((buffer[3] & 0xFF) << 16) | ((buffer[4] & 0xFF) << 8) | (buffer[5] & 0xFF);
22
23 return new Index(size, block);
24 }
25
26 /**
27 * The size of the file.
28 */
29 private final int size;
30
31 /**
32 * The first block of the file.
33 */
34 private final int block;
35
36 /**
37 * Creates the index.
38 * @param size The size of the file.
39 * @param block The first block of the file.
40 */
41 public Index(int size, int block) {
42 this.size = size;
43 this.block = block;
44 }
45
46 /**
47 * Gets the size of the file.
48 * @return The size of the file.
49 */
50 public int getSize() {
51 return size;
52 }
53
54 /**
55 * Gets the first block of the file.
56 * @return The first block of the file.
57 */
58 public int getBlock() {
59 return block;
60 }
61
62}
Holds file system related constants.
static final int INDEX_SIZE
The size of an index.
static Index decode(byte[] buffer)
Decodes a buffer into an index.
Definition Index.java:15
Index(int size, int block)
Creates the index.
Definition Index.java:41
final int size
The size of the file.
Definition Index.java:29
int getSize()
Gets the size of the file.
Definition Index.java:50
int getBlock()
Gets the first block of the file.
Definition Index.java:58
final int block
The first block of the file.
Definition Index.java:34