Mercurial Hosting > luan
annotate src/goodjava/lucene/logging/LogFile.java @ 1492:aaac1d29edea
better io
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 02 May 2020 22:25:56 -0600 |
parents | 9a2a2181a58f |
children | 86c5e7000ecf |
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; |
1461 | 15 |
16 | |
1486 | 17 public class LogFile { |
1465 | 18 private static final Logger logger = LoggerFactory.getLogger(LogFile.class); |
19 public final File file; | |
1486 | 20 long end; |
1461 | 21 |
1486 | 22 public LogFile(File file) throws IOException { |
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 | 26 end = 8; |
1476
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
27 raf.writeLong(end); |
1461 | 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 | 32 } |
1486 | 33 raf.close(); |
1461 | 34 } |
35 | |
1465 | 36 public String toString() { |
37 return "LogFile<" + file.getName() + ">"; | |
38 } | |
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 | 42 } |
43 | |
1486 | 44 public LogOutputStream output() throws IOException { |
45 RandomAccessFile raf = new RandomAccessFile(file,"rwd"); | |
46 OutputStream out = new FileOutputStream(raf.getFD()); | |
47 out = new BufferedOutputStream(out); | |
48 return newLogOutputStream(raf,out); | |
49 } | |
50 | |
51 protected LogOutputStream newLogOutputStream(RandomAccessFile raf,OutputStream out) throws IOException { | |
52 return new LogOutputStream(this,raf,out); | |
53 } | |
54 | |
1476
7d145095cc0b
lucene.logging check
Franklin Schmidt <fschmidt@gmail.com>
parents:
1465
diff
changeset
|
55 public LogInputStream input() throws IOException { |
1480 | 56 InputStream in = new FileInputStream(file); |
1490
9a2a2181a58f
FixedLengthInputStream
Franklin Schmidt <fschmidt@gmail.com>
parents:
1486
diff
changeset
|
57 in = new FixedLengthInputStream(in,end); |
1480 | 58 in = new BufferedInputStream(in); |
59 LogInputStream lis = newLogInputStream(in); | |
60 lis.readLong(); // skip end | |
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 | 66 } |
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 | 84 } |