Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package server.clip.region;
- public class MemoryArchive {
- private ByteStream cache;
- private ByteStream index;
- private static final int INDEX_DATA_CHUNK_SIZE = 12;
- public MemoryArchive(ByteStream cache, ByteStream index)
- {
- this.cache = cache;
- this.index = index;
- }
- public byte[] get(int dataIndex)
- {
- try {
- if(index.length() < (dataIndex * INDEX_DATA_CHUNK_SIZE))
- return null;
- index.setOffset(dataIndex * INDEX_DATA_CHUNK_SIZE);
- long fileOffset = index.getLong();
- int fileSize = index.getInt();
- if(fileOffset>0)
- cache.setOffset(fileOffset);
- byte[] buffer = cache.read(fileSize);
- return buffer;
- } catch(Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- public int contentSize()
- {
- return index.length() / 12;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement