View Javadoc
1   package gboat2.base.logging.service.impl;
2   
3   
4   
5   import gboat2.base.logging.Constants;
6   import gboat2.base.logging.service.ISystemLogService;
7   
8   import java.io.File;
9   import java.io.FileReader;
10  import java.io.LineNumberReader;
11  
12  import org.springframework.stereotype.Service;
13  import org.springframework.transaction.annotation.Transactional;
14  
15  /**
16   * 系统日志管理
17   * @author zhaop
18   * @since jdk1.6
19   * @date 2012-05-09
20   */
21  @Transactional
22  @Service
23  public class SystemLogServiceImpl implements ISystemLogService {
24  
25  	@Override
26  	public int getTotalLineNumber(File file) {
27  		int lines = 0;
28  		try {
29  			FileReader in = new FileReader(file);
30  			LineNumberReader reader = new LineNumberReader(in);
31  			String s = reader.readLine();
32  			while (s != null) {
33  				lines++;
34  				s = reader.readLine();
35  			}
36  			reader.close();
37  			in.close();
38  		} catch (Exception e) {
39  			e.printStackTrace();
40  		}
41  		return lines;
42  	}
43  
44  	@Override
45  	public int getTotalPage(int lines) {
46  		if (lines <= Constants.PAGESIZE) {
47  			return 1;
48  		} else {
49  			if (lines % Constants.PAGESIZE == 0) {
50  				return lines / Constants.PAGESIZE;
51  			} else {
52  				return lines / Constants.PAGESIZE + 1;
53  			}
54  		}
55  	}
56  
57  }