1 18 package org.apache.activemq.kaha.impl.index; 19 20 import java.io.IOException ; 21 import java.io.RandomAccessFile ; 22 23 import org.apache.activemq.util.DataByteArrayInputStream; 24 29 class StoreIndexReader{ 30 protected RandomAccessFile file; 31 protected DataByteArrayInputStream dataIn; 32 protected byte[] buffer=new byte[IndexItem.INDEX_SIZE]; 33 34 39 StoreIndexReader(RandomAccessFile file){ 40 this.file=file; 41 this.dataIn=new DataByteArrayInputStream(); 42 } 43 44 protected IndexItem readItem(long offset) throws IOException { 45 file.seek(offset); 46 file.readFully(buffer); 47 dataIn.restart(buffer); 48 IndexItem result=new IndexItem(); 49 result.setOffset(offset); 50 result.read(dataIn); 51 return result; 52 } 53 54 void updateIndexes(IndexItem indexItem) throws IOException { 55 if (indexItem != null){ 56 file.seek(indexItem.getOffset()); 57 file.readFully(buffer,0,IndexItem.INDEXES_ONLY_SIZE); 58 dataIn.restart(buffer); 59 indexItem.readIndexes(dataIn); 60 } 61 } 62 } 63 | Popular Tags |