1 /*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002, 2014 Oracle and/or its affiliates. All rights reserved. 5 * 6 */ 7 8 package com.sleepycat.je.log; 9 10 import java.nio.ByteBuffer; 11 12 import com.sleepycat.je.DatabaseException; 13 import com.sleepycat.je.dbi.EnvironmentImpl; 14 import com.sleepycat.je.log.entry.LogEntry; 15 16 /** 17 * The PrintFileReader prints out the target log entries. 18 */ 19 public class PrintFileReader extends DumpFileReader { 20 21 /** 22 * Create this reader to start at a given LSN. 23 */ PrintFileReader(EnvironmentImpl env, int readBufferSize, long startLsn, long finishLsn, long endOfFileLsn, String entryTypes, String txnIds, boolean verbose, boolean repEntriesOnly, boolean forwards)24 public PrintFileReader(EnvironmentImpl env, 25 int readBufferSize, 26 long startLsn, 27 long finishLsn, 28 long endOfFileLsn, 29 String entryTypes, 30 String txnIds, 31 boolean verbose, 32 boolean repEntriesOnly, 33 boolean forwards) 34 throws DatabaseException { 35 36 super(env, 37 readBufferSize, 38 startLsn, 39 finishLsn, 40 endOfFileLsn, 41 entryTypes, 42 txnIds, 43 verbose, 44 repEntriesOnly, 45 forwards); 46 } 47 48 /** 49 * This reader prints the log entry item. 50 */ processEntry(ByteBuffer entryBuffer)51 protected boolean processEntry(ByteBuffer entryBuffer) 52 throws DatabaseException { 53 54 /* Figure out what kind of log entry this is */ 55 byte curType = currentEntryHeader.getType(); 56 LogEntryType lastEntryType = LogEntryType.findType(curType); 57 58 /* Print out a common header for each log item */ 59 StringBuilder sb = new StringBuilder(); 60 sb.append("<entry lsn=\"0x").append 61 (Long.toHexString(window.currentFileNum())); 62 sb.append("/0x").append(Long.toHexString(currentEntryOffset)); 63 sb.append("\" "); 64 currentEntryHeader.dumpLogNoTag(sb, verbose); 65 sb.append("\">"); 66 67 /* Read the entry and dump it into a string buffer. */ 68 LogEntry entry = lastEntryType.getSharedLogEntry(); 69 entry.readEntry(envImpl, currentEntryHeader, entryBuffer); 70 boolean dumpIt = true; 71 if (targetTxnIds.size() > 0) { 72 if (lastEntryType.isTransactional()) { 73 if (!targetTxnIds.contains 74 (Long.valueOf(entry.getTransactionId()))) { 75 /* Not in the list of txn ids. */ 76 dumpIt = false; 77 } 78 } else { 79 /* If -tx spec'd and not a transactional entry, don't dump. */ 80 dumpIt = false; 81 } 82 } 83 84 if (dumpIt) { 85 entry.dumpEntry(sb, verbose); 86 sb.append("</entry>"); 87 System.out.println(sb.toString()); 88 } 89 90 return true; 91 } 92 } 93