annotate src/goodjava/lucene/logging/LogFile.java @ 1487:044a360c2300

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