annotate src/goodjava/lucene/logging/LogFile.java @ 1823:36dfc31fd607

install fix
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 07 Aug 2024 18:29:58 -0600
parents 117ce8645b7f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 package goodjava.lucene.logging;
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
3cff066f3bbc output buffering
Franklin Schmidt <fschmidt@gmail.com>
parents: 1480
diff changeset
5 import java.io.OutputStream;
3cff066f3bbc output buffering
Franklin Schmidt <fschmidt@gmail.com>
parents: 1480
diff changeset
6 import java.io.BufferedOutputStream;
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 import java.io.RandomAccessFile;
1480
1f41e5921090 input buffering
Franklin Schmidt <fschmidt@gmail.com>
parents: 1476
diff changeset
8 import java.io.FileInputStream;
1481
3cff066f3bbc output buffering
Franklin Schmidt <fschmidt@gmail.com>
parents: 1480
diff changeset
9 import java.io.FileOutputStream;
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 import java.io.IOException;
1465
5e3870618377 lucene.logging dir
Franklin Schmidt <fschmidt@gmail.com>
parents: 1462
diff changeset
11 import goodjava.logging.Logger;
5e3870618377 lucene.logging dir
Franklin Schmidt <fschmidt@gmail.com>
parents: 1462
diff changeset
12 import goodjava.logging.LoggerFactory;
1490
9a2a2181a58f FixedLengthInputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1486
diff changeset
13 import goodjava.io.FixedLengthInputStream;
1480
1f41e5921090 input buffering
Franklin Schmidt <fschmidt@gmail.com>
parents: 1476
diff changeset
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
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
18 public class LogFile {
1465
5e3870618377 lucene.logging dir
Franklin Schmidt <fschmidt@gmail.com>
parents: 1462
diff changeset
19 private static final Logger logger = LoggerFactory.getLogger(LogFile.class);
5e3870618377 lucene.logging dir
Franklin Schmidt <fschmidt@gmail.com>
parents: 1462
diff changeset
20 public final File file;
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
21 long end;
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
23 public LogFile(File file) throws IOException {
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
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
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 end = 8;
1476
7d145095cc0b lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents: 1465
diff changeset
28 raf.writeLong(end);
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 }
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
34 raf.close();
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36
1465
5e3870618377 lucene.logging dir
Franklin Schmidt <fschmidt@gmail.com>
parents: 1462
diff changeset
37 public String toString() {
5e3870618377 lucene.logging dir
Franklin Schmidt <fschmidt@gmail.com>
parents: 1462
diff changeset
38 return "LogFile<" + file.getName() + ">";
5e3870618377 lucene.logging dir
Franklin Schmidt <fschmidt@gmail.com>
parents: 1462
diff changeset
39 }
5e3870618377 lucene.logging dir
Franklin Schmidt <fschmidt@gmail.com>
parents: 1462
diff changeset
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
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44
1486
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
45 public LogOutputStream output() throws IOException {
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
46 RandomAccessFile raf = new RandomAccessFile(file,"rwd");
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
47 OutputStream out = new FileOutputStream(raf.getFD());
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
48 out = new BufferedOutputStream(out);
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
49 return newLogOutputStream(raf,out);
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
50 }
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
51
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
52 protected LogOutputStream newLogOutputStream(RandomAccessFile raf,OutputStream out) throws IOException {
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
53 return new LogOutputStream(this,raf,out);
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
54 }
2469aa31f31b LogOutputStream
Franklin Schmidt <fschmidt@gmail.com>
parents: 1484
diff changeset
55
1476
7d145095cc0b lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents: 1465
diff changeset
56 public LogInputStream input() throws IOException {
1480
1f41e5921090 input buffering
Franklin Schmidt <fschmidt@gmail.com>
parents: 1476
diff changeset
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
1f41e5921090 input buffering
Franklin Schmidt <fschmidt@gmail.com>
parents: 1476
diff changeset
59 in = new BufferedInputStream(in);
1f41e5921090 input buffering
Franklin Schmidt <fschmidt@gmail.com>
parents: 1476
diff changeset
60 LogInputStream lis = newLogInputStream(in);
1f41e5921090 input buffering
Franklin Schmidt <fschmidt@gmail.com>
parents: 1476
diff changeset
61 lis.readLong(); // skip end
1f41e5921090 input buffering
Franklin Schmidt <fschmidt@gmail.com>
parents: 1476
diff changeset
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
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 }
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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;
1557
117ce8645b7f lucene logging - add long string
Franklin Schmidt <fschmidt@gmail.com>
parents: 1508
diff changeset
89 static final int TYPE_LONG_STRING = 16;
1461
e5d48b85351c start lucene.logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90 }