KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > log > SearchFileReader


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: SearchFileReader.java,v 1.38 2006/10/30 21:14:20 bostic Exp $
7  */

8
9 package com.sleepycat.je.log;
10
11 import java.io.IOException JavaDoc;
12 import java.nio.ByteBuffer JavaDoc;
13
14 import com.sleepycat.je.DatabaseException;
15 import com.sleepycat.je.dbi.EnvironmentImpl;
16 import com.sleepycat.je.log.entry.LogEntry;
17 import com.sleepycat.je.utilint.DbLsn;
18
19 /**
20  * SearchFileReader searches for the a given entry type.
21  */

22 public class SearchFileReader extends FileReader {
23
24     private LogEntryType targetType;
25     private LogEntry logEntry;
26
27     /**
28      * Create this reader to start at a given LSN.
29      */

30     public SearchFileReader(EnvironmentImpl env,
31                             int readBufferSize,
32                             boolean forward,
33                             long startLsn,
34                             long endOfFileLsn,
35                             LogEntryType targetType)
36     throws IOException JavaDoc, DatabaseException {
37
38         super(env, readBufferSize, forward, startLsn, null,
39           endOfFileLsn, DbLsn.NULL_LSN);
40
41         this.targetType = targetType;
42         logEntry = targetType.getNewLogEntry();
43     }
44
45     /**
46      * @return true if this is a targetted entry.
47      */

48     protected boolean isTargetEntry(byte logEntryTypeNumber,
49                                     byte logEntryTypeVersion) {
50         return (targetType.equalsType(logEntryTypeNumber,
51                                       logEntryTypeVersion));
52     }
53     
54     /**
55      * This reader instantiate the first object of a given log entry.
56      */

57     protected boolean processEntry(ByteBuffer JavaDoc entryBuffer)
58         throws DatabaseException {
59
60         logEntry.readEntry(entryBuffer, currentEntrySize,
61                            currentEntryTypeVersion, true);
62         return true;
63     }
64
65     /**
66      * @return the last object read.
67      */

68     public Object JavaDoc getLastObject() {
69         return logEntry.getMainItem();
70     }
71 }
72
Popular Tags