commit | author | age
|
15ed25
|
1 |
package de.uhilger.avdirektor; |
U |
2 |
|
|
3 |
import java.io.BufferedReader; |
|
4 |
import java.io.File; |
|
5 |
import java.io.FileInputStream; |
|
6 |
import java.io.FileNotFoundException; |
|
7 |
import java.io.IOException; |
|
8 |
import java.io.InputStream; |
|
9 |
import java.io.InputStreamReader; |
|
10 |
import java.util.logging.Logger; |
|
11 |
|
|
12 |
/** |
|
13 |
* |
|
14 |
* @author ulrich |
|
15 |
*/ |
|
16 |
public class OMXLogLeser { |
|
17 |
|
|
18 |
private static final Logger logger = Logger.getLogger(OMXLogLeser.class.getName()); |
|
19 |
|
|
20 |
public String lesen(File logfile) throws FileNotFoundException, IOException { |
|
21 |
InputStream is = new FileInputStream(logfile); |
|
22 |
BufferedReader r = new BufferedReader(new InputStreamReader(is)); |
|
23 |
String firstLine = r.readLine(); |
|
24 |
String lastLine = ""; |
|
25 |
if(firstLine != null) { |
|
26 |
long size = logfile.length(); |
|
27 |
long pos = size - (long) 1000; |
|
28 |
logger.info("Size: " + size + ", Pos: " + pos); // 2.341.930 Bytes |
|
29 |
long skipped = r.skip(pos); |
|
30 |
logger.info("skipped: " + skipped); |
|
31 |
String line = r.readLine(); |
|
32 |
while(line != null) { |
|
33 |
lastLine = line; |
|
34 |
logger.info(lastLine); |
|
35 |
line = r.readLine(); |
|
36 |
} |
|
37 |
} |
|
38 |
r.close(); |
|
39 |
is.close(); |
|
40 |
StringBuilder sb = new StringBuilder(); |
|
41 |
sb.append("\r\n---"); |
|
42 |
sb.append("\r\nfirst line:\r\n"); |
|
43 |
sb.append(firstLine); |
|
44 |
sb.append("\r\n\r\nlastLine\r\n"); |
|
45 |
sb.append(lastLine); |
|
46 |
String lines = sb.toString(); |
|
47 |
logger.info(lines); |
|
48 |
return lines; |
|
49 |
} |
|
50 |
|
|
51 |
} |