Mercurial Hosting > luan
annotate src/goodjava/lucene/logging/LogFile.java @ 1523:2052c8a548dd
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 06 Jul 2020 11:30:02 -0600 |
parents | 86c5e7000ecf |
children | 117ce8645b7f |
rev | line source |
---|---|
1461 | 1 package goodjava.lucene.logging; |
2 | |
3 import java.io.File; | |
1476
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
4 import java.io.InputStream; |
1481 | 5 import java.io.OutputStream; |
6 import java.io.BufferedOutputStream; | |
1461 | 7 import java.io.RandomAccessFile; |
1480 | 8 import java.io.FileInputStream; |
1481 | 9 import java.io.FileOutputStream; |
1461 | 10 import java.io.IOException; |
1465 | 11 import goodjava.logging.Logger; |
12 import goodjava.logging.LoggerFactory; | |
1490
9a2a2181a58f
FixedLengthInputStream
Franklin Schmidt <fschmidt@gmail.com>
parents:
1486
diff
changeset
|
13 import goodjava.io.FixedLengthInputStream; |
1480 | 14 import goodjava.io.BufferedInputStream; |
1508
86c5e7000ecf
lucene.backup checksum
Franklin Schmidt <fschmidt@gmail.com>
parents:
1490
diff
changeset
|
15 import goodjava.io.IoUtils; |
1461 | 16 |
17 | |
1486 | 18 public class LogFile { |
1465 | 19 private static final Logger logger = LoggerFactory.getLogger(LogFile.class); |
20 public final File file; | |
1486 | 21 long end; |
1461 | 22 |
1486 | 23 public LogFile(File file) throws IOException { |
24 this.file = file; | |
1484
1fa6e8ec2d53
lucene.logging cleanup
Franklin Schmidt <fschmidt@gmail.com>
parents:
1481
diff
changeset
|
25 RandomAccessFile raf = new RandomAccessFile(file,"rwd"); |
1476
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
26 if( raf.length() == 0 ) { |
1461 | 27 end = 8; |
1476
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
28 raf.writeLong(end); |
1461 | 29 } else { |
1476
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
30 raf.seek(0L); |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
31 end = raf.readLong(); |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
32 raf.seek(end); |
1461 | 33 } |
1486 | 34 raf.close(); |
1461 | 35 } |
36 | |
1465 | 37 public String toString() { |
38 return "LogFile<" + file.getName() + ">"; | |
39 } | |
40 | |
1476
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
41 public long end() { |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
42 return end; |
1461 | 43 } |
44 | |
1486 | 45 public LogOutputStream output() throws IOException { |
46 RandomAccessFile raf = new RandomAccessFile(file,"rwd"); | |
47 OutputStream out = new FileOutputStream(raf.getFD()); | |
48 out = new BufferedOutputStream(out); | |
49 return newLogOutputStream(raf,out); | |
50 } | |
51 | |
52 protected LogOutputStream newLogOutputStream(RandomAccessFile raf,OutputStream out) throws IOException { | |
53 return new LogOutputStream(this,raf,out); | |
54 } | |
55 | |
1476
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
56 public LogInputStream input() throws IOException { |
1480 | 57 InputStream in = new FileInputStream(file); |
1490
9a2a2181a58f
FixedLengthInputStream
Franklin Schmidt <fschmidt@gmail.com>
parents:
1486
diff
changeset
|
58 in = new FixedLengthInputStream(in,end); |
1480 | 59 in = new BufferedInputStream(in); |
60 LogInputStream lis = newLogInputStream(in); | |
61 lis.readLong(); // skip end | |
62 return lis; | |
1476
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
63 } |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
64 |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
65 protected LogInputStream newLogInputStream(InputStream in) { |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
66 return new LogInputStream(in); |
1461 | 67 } |
68 | |
1508
86c5e7000ecf
lucene.backup checksum
Franklin Schmidt <fschmidt@gmail.com>
parents:
1490
diff
changeset
|
69 public long checksum() throws IOException { |
86c5e7000ecf
lucene.backup checksum
Franklin Schmidt <fschmidt@gmail.com>
parents:
1490
diff
changeset
|
70 return IoUtils.checksum(input()); |
86c5e7000ecf
lucene.backup checksum
Franklin Schmidt <fschmidt@gmail.com>
parents:
1490
diff
changeset
|
71 } |
86c5e7000ecf
lucene.backup checksum
Franklin Schmidt <fschmidt@gmail.com>
parents:
1490
diff
changeset
|
72 |
1476
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
73 static final int TYPE_NULL = 0; |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
74 static final int TYPE_STRING = 1; |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
75 static final int TYPE_INT = 2; |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
76 static final int TYPE_LONG = 3; |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
77 static final int TYPE_FLOAT = 4; |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
78 static final int TYPE_DOUBLE = 5; |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
79 static final int TYPE_BYTES = 6; |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
80 static final int TYPE_LIST = 7; |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
81 static final int TYPE_QUERY_MATCH_ALL_DOCS = 8; |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
82 static final int TYPE_QUERY_TERM = 9; |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
83 static final int TYPE_QUERY_PREFIX = 10; |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
84 static final int TYPE_QUERY_WILDCARD = 11; |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
85 static final int TYPE_QUERY_TERM_RANGE = 12; |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
86 static final int TYPE_QUERY_PHRASE = 13; |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
87 static final int TYPE_QUERY_NUMERIC_RANGE = 14; |
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
88 static final int TYPE_QUERY_BOOLEAN = 15; |
1461 | 89 } |