1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.util;
15
16
17 import java.io.BufferedReader;
18 import java.io.FileReader;
19 import java.io.IOException;
20 import java.util.regex.Matcher;
21 import java.util.regex.Pattern;
22
23 public class ResilienceUtil {
24
25 static public int countLines(String logfile, String regexp)
26 throws NumberFormatException, IOException {
27 FileReader fr = new FileReader(logfile);
28 BufferedReader br = new BufferedReader(fr);
29 Pattern p = Pattern.compile(regexp);
30 String line;
31
32 int totalLines = 0;
33 int oldNum = -1;
34 int gaps = 0;
35 while ((line = br.readLine()) != null) {
36 Matcher m = p.matcher(line);
37 if (m.matches()) {
38 totalLines++;
39 String g = m.group(1);
40 int num = Integer.parseInt(g);
41 if (oldNum != -1 && num != oldNum + 1) {
42 gaps++;
43 }
44 oldNum = num;
45 }
46 }
47 fr.close();
48 br.close();
49
50 return totalLines;
51
52
53
54
55
56
57
58 }
59 }