View Javadoc
1   package net.logAnalyzer.handlers;
2   
3   import java.io.FileNotFoundException;
4   import java.io.IOException;
5   
6   import net.logAnalyzer.utils.FilesSetReader;
7   
8   /***
9    * This log handler does not save messages. It is useful for analyzers but can
10   * not be used for GUI because it only can to go forward and does not support
11   * backward or random access to the log file.
12   * <p>
13   * For random access, for example for a GUI, use
14   * {@link net.logAnalyzer.handlers.MemoryLogHandler} for small log files and
15   * {@link net.logAnalyzer.handlers.OnDemandLogHandler} for large files.
16   * 
17   * @author Karim REFEYTON
18   * @version 0.1
19   */
20  public class ForwardOnlyLogHandler extends AbstractLogHandler {
21      /***
22       * Parsed log messages.
23       */
24      private LAMessage currentMessage = null;
25  
26      /***
27       * Number of messages.
28       */
29      private int numberOfMessages = 0;
30  
31      /***
32       * @param input
33       * @param pattern
34       * @throws FileNotFoundException
35       * @throws NoConverterException
36       */
37      public ForwardOnlyLogHandler(FilesSetReader input, String pattern)
38              throws FileNotFoundException, NoConverterException {
39          super(input, pattern);
40      }
41  
42      /***
43       * Returns the number of messages read.
44       * 
45       * @see net.logAnalyzer.handlers.LALogHandler#getSize()
46       */
47      public int getSize() {
48          return numberOfMessages;
49      }
50  
51      /***
52       * Modification to the inherited behavior.
53       * 
54       * @see AbstractLogHandler#loadMessage(int)
55       */
56      protected LAMessage loadMessage(int index) {
57          return currentMessage;
58      }
59  
60      /***
61       * Modification to the inherited behavior.
62       * 
63       * @see AbstractLogHandler#saveMessage(LAMessage, long)
64       */
65      protected void saveMessage(LAMessage message, long pointer) {
66          numberOfMessages++;
67      }
68  
69      /***
70       * Modification to the inherited behavior.
71       * 
72       * @see AbstractLogHandler#initParsing()
73       */
74      protected void initParsing() throws IOException {
75          super.initParsing();
76          currentMessage = null;
77          numberOfMessages = 0;
78      }
79  }