1package com.runehive.fs.cache;
3import com.google.common.base.Preconditions;
5import java.io.IOException;
6import java.nio.ByteBuffer;
7import java.nio.channels.SeekableByteChannel;
81 public ByteBuffer
get(
final int indexId)
throws IOException {
91 byte[] data =
new byte[index.getLength()];
92 int next = index.getId();
95 for (
int chunk = 0; offset < index.getLength(); chunk++) {
96 int read = Math.min(index.getLength() - offset, 512);
99 sector.
check(
id, indexId, chunk);
105 return ByteBuffer.wrap(data);
136 private Sector readSector(
int sectorId,
byte[] data,
int offset,
int length)
throws IOException {
Sector readSector(int sectorId, byte[] data, int offset, int length)
Reads a Sector for the specified sectorId and returns the decoded data.
static final int INDEX_SIZE
Represents the size of a index file.
final int id
Represents the id of this Cache.
final SeekableByteChannel indexChannel
A byte channel that contains a series of variable-length bytes which represent a index.
Index readIndex(int indexId)
Reads an Index for the specified indexId and returns the decoded data.
static final int SECTOR_HEADER_SIZE
Represents the size of a Sectors header.
static final int SECTOR_SIZE
Represents the size of a Sectors header.
Cache(SeekableByteChannel sectorChannel, SeekableByteChannel indexChannel, int id)
Constructs a new Cache with the specified sector and index channels and id.
final ByteBuffer buffer
A ByteBuffer allocated to SECTOR_SIZE.
final SeekableByteChannel sectorChannel
A byte channel that contains a series of variable-length bytes which represent a sector.
Represents an index within some Cache.
static Index decode(ByteBuffer buffer)
Decodes an Index from the specified ByteBuffer.
Represents a sector within some Cache.
void check(int cacheId, int indexId, int chunk)
Tests whether or not this sector is valid.
int getNextIndexId()
Returns the next index within this sector.
static Sector decode(ByteBuffer buffer, byte[] data, int offset, int length)
Decodes a Sector from the specified ByteBuffer.