1 21 package com.db4o.test.performance; 22 23 import java.io.*; 24 25 import com.db4o.io.*; 26 27 31 public class RecordingIoAdapter extends VanillaIoAdapter { 32 private int _runningId; 36 37 private String _logPath; 38 39 private RandomAccessFile _writer; 40 41 private long _pos; 42 43 private int _runs; 44 45 public RecordingIoAdapter(IoAdapter adapter, String logPath) { 46 super(adapter); 47 _logPath = logPath; 48 _runningId=0; 49 } 50 51 protected RecordingIoAdapter(IoAdapter adapter, String logPath, 52 String file, boolean append, long initialLength) throws IOException { 53 super(adapter, file, append, initialLength); 54 _writer = new RandomAccessFile(logPath, "rw"); 55 _runs=0; 56 } 57 58 public void close() throws IOException { 59 super.close(); 60 writeLogChar('q'); 61 } 63 64 public IoAdapter open(String path, boolean lockFile, long initialLength) 65 throws IOException { 66 _runningId++; 67 return new RecordingIoAdapter(_delegate, _logPath+"."+_runningId, path, lockFile, 68 initialLength); 69 } 70 71 public int read(byte[] buffer, int length) throws IOException { 72 writeLog('r',_pos,length); 73 return super.read(buffer,length); 74 75 } 76 77 public void seek(long pos) throws IOException { 78 _pos = pos; 79 super.seek(pos); 80 } 81 82 public void write(byte[] buffer, int length) throws IOException { 83 writeLog('w',_pos,length); 84 super.write(buffer,length); 85 } 86 87 public void sync() throws IOException { 88 writeLogChar('f'); 89 super.sync(); 90 } 91 92 private void writeLog(char type,long pos,int length) throws IOException { 93 _writer.writeChar(type); 94 _writer.writeLong(pos); 95 _writer.writeInt(length); 96 _runs++; 97 } 98 99 private void writeLogChar(char c) throws IOException { 100 _writer.writeChar(c); 101 _runs++; 102 } 103 } | Popular Tags |