1 18 package org.apache.activemq.kaha.impl.data; 19 20 import java.io.IOException ; 21 import java.io.RandomAccessFile ; 22 import org.apache.activemq.kaha.Marshaller; 23 import org.apache.activemq.kaha.StoreLocation; 24 import org.apache.activemq.util.DataByteArrayInputStream; 25 30 public final class SyncDataFileReader { 31 32 private DataManagerImpl dataManager; 33 private DataByteArrayInputStream dataIn; 34 35 40 SyncDataFileReader(DataManagerImpl fileManager){ 41 this.dataManager=fileManager; 42 this.dataIn=new DataByteArrayInputStream(); 43 } 44 45 48 public synchronized byte readDataItemSize(DataItem item) throws IOException { 49 RandomAccessFile file = dataManager.getDataFile(item).getRandomAccessFile(); 50 file.seek(item.getOffset()); byte rc = file.readByte(); 52 item.setSize(file.readInt()); 53 return rc; 54 } 55 56 59 public synchronized Object readItem(Marshaller marshaller,StoreLocation item) throws IOException { 60 RandomAccessFile file=dataManager.getDataFile(item).getRandomAccessFile(); 61 62 byte[] data=new byte[item.getSize()]; 65 file.seek(item.getOffset()+DataManagerImpl.ITEM_HEAD_SIZE); 66 file.readFully(data); 67 dataIn.restart(data); 68 return marshaller.readPayload(dataIn); 69 } 70 } 71 | Popular Tags |