comparison src/goodjava/lucene/logging/LogFile.java @ 1480:1f41e5921090

input buffering
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 24 Apr 2020 14:32:20 -0600
parents 7d145095cc0b
children 3cff066f3bbc
comparison
equal deleted inserted replaced
1479:bd13aaeaf6d4 1480:1f41e5921090
4 import java.io.InputStream; 4 import java.io.InputStream;
5 import java.io.DataOutput; 5 import java.io.DataOutput;
6 import java.io.DataOutputStream; 6 import java.io.DataOutputStream;
7 import java.io.RandomAccessFile; 7 import java.io.RandomAccessFile;
8 import java.io.ByteArrayOutputStream; 8 import java.io.ByteArrayOutputStream;
9 import java.io.ByteArrayInputStream; 9 import java.io.FileInputStream;
10 import java.io.IOException; 10 import java.io.IOException;
11 import java.util.List; 11 import java.util.List;
12 import java.util.Map; 12 import java.util.Map;
13 import org.apache.lucene.index.Term; 13 import org.apache.lucene.index.Term;
14 import org.apache.lucene.search.Query; 14 import org.apache.lucene.search.Query;
22 import org.apache.lucene.search.BooleanQuery; 22 import org.apache.lucene.search.BooleanQuery;
23 import org.apache.lucene.search.BooleanClause; 23 import org.apache.lucene.search.BooleanClause;
24 import org.apache.lucene.util.BytesRef; 24 import org.apache.lucene.util.BytesRef;
25 import goodjava.logging.Logger; 25 import goodjava.logging.Logger;
26 import goodjava.logging.LoggerFactory; 26 import goodjava.logging.LoggerFactory;
27 import goodjava.io.LimitedInputStream;
28 import goodjava.io.BufferedInputStream;
27 29
28 30
29 public class LogFile { 31 public class LogFile {
30 private static final Logger logger = LoggerFactory.getLogger(LogFile.class); 32 private static final Logger logger = LoggerFactory.getLogger(LogFile.class);
31 public final File file; 33 public final File file;
70 public long end() { 72 public long end() {
71 return end; 73 return end;
72 } 74 }
73 75
74 public LogInputStream input() throws IOException { 76 public LogInputStream input() throws IOException {
75 byte[] a = new byte[(int)end - 8]; 77 InputStream in = new FileInputStream(file);
76 raf.seek(8L); 78 in = new LimitedInputStream(in,end);
77 raf.readFully(a); 79 in = new BufferedInputStream(in);
78 return newLogInputStream(new ByteArrayInputStream(a)); 80 LogInputStream lis = newLogInputStream(in);
81 lis.readLong(); // skip end
82 return lis;
79 } 83 }
80 84
81 protected LogInputStream newLogInputStream(InputStream in) { 85 protected LogInputStream newLogInputStream(InputStream in) {
82 return new LogInputStream(in); 86 return new LogInputStream(in);
83 } 87 }