1 8 9 package com.sleepycat.je.log; 10 11 import java.io.IOException ; 12 import java.io.RandomAccessFile ; 13 import java.nio.ByteBuffer ; 14 15 import com.sleepycat.je.DatabaseException; 16 import com.sleepycat.je.dbi.EnvironmentImpl; 17 18 22 class FileSource implements LogSource { 23 24 private RandomAccessFile file; 25 private int readBufferSize; 26 private FileManager fileManager; 27 28 FileSource(RandomAccessFile file, 29 int readBufferSize, 30 FileManager fileManager) { 31 this.file = file; 32 this.readBufferSize = readBufferSize; 33 this.fileManager = fileManager; 34 } 35 36 39 public void release() 40 throws DatabaseException { 41 } 42 43 46 public ByteBuffer getBytes(long fileOffset) 47 throws IOException { 48 49 50 ByteBuffer destBuf = ByteBuffer.allocate(readBufferSize); 51 fileManager.readFromFile(file, destBuf, fileOffset); 52 53 assert EnvironmentImpl.maybeForceYield(); 54 55 destBuf.flip(); 56 return destBuf; 57 } 58 59 62 public ByteBuffer getBytes(long fileOffset, int numBytes) 63 throws IOException { 64 65 66 ByteBuffer destBuf = ByteBuffer.allocate(numBytes); 67 fileManager.readFromFile(file, destBuf, fileOffset); 68 69 assert EnvironmentImpl.maybeForceYield(); 70 71 destBuf.flip(); 72 73 assert destBuf.remaining() >= numBytes: 74 "remaining=" + destBuf.remaining() + 75 " numBytes=" + numBytes; 76 return destBuf; 77 } 78 } 79 | Popular Tags |