Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. package server.clip.region;
  2.  
  3.  
  4. public class MemoryArchive {
  5.  
  6.     private ByteStream cache;
  7.     private ByteStream index;
  8.     private static final int INDEX_DATA_CHUNK_SIZE = 12;
  9.  
  10.     public MemoryArchive(ByteStream cache, ByteStream index)
  11.     {
  12.         this.cache = cache;
  13.         this.index = index;
  14.     }
  15.  
  16.     public byte[] get(int dataIndex)
  17.     {
  18.         try {
  19.             if(index.length() < (dataIndex * INDEX_DATA_CHUNK_SIZE))
  20.                 return null;
  21.             index.setOffset(dataIndex * INDEX_DATA_CHUNK_SIZE);
  22.             long fileOffset = index.getLong();
  23.             int fileSize = index.getInt();
  24.             if(fileOffset>0)
  25.             cache.setOffset(fileOffset);
  26.             byte[] buffer = cache.read(fileSize);
  27.             return buffer;
  28.         } catch(Exception e) {
  29.             e.printStackTrace();
  30.             return null;
  31.         }
  32.     }
  33.  
  34.     public int contentSize()
  35.     {
  36.         return index.length() / 12;
  37.     }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement