diff src/goodjava/lucene/logging/LogFile.java @ 1484:1fa6e8ec2d53

lucene.logging cleanup
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 25 Apr 2020 11:14:25 -0600
parents 3cff066f3bbc
children 2469aa31f31b
line wrap: on
line diff
--- a/src/goodjava/lucene/logging/LogFile.java	Sat Apr 25 10:31:49 2020 -0600
+++ b/src/goodjava/lucene/logging/LogFile.java	Sat Apr 25 11:14:25 2020 -0600
@@ -29,23 +29,24 @@
 import goodjava.io.BufferedInputStream;
 
 
-public class LogFile {
+public class LogFile extends DataOutputStream {
 	private static final Logger logger = LoggerFactory.getLogger(LogFile.class);
 	public final File file;
 	private final RandomAccessFile raf;
-	private final DataOutputStream out;
 	private long end;
 
-	public LogFile(File file,String mode) throws IOException {
-		this.file = file;
-		this.raf = new RandomAccessFile(file,mode);
+	public static LogFile newLogFile(File file) throws IOException {
+		RandomAccessFile raf = new RandomAccessFile(file,"rwd");
 		OutputStream out = new FileOutputStream(raf.getFD());
 		out = new BufferedOutputStream(out);
-		this.out = new DataOutputStream(out);
-		init();
+		return new LogFile(file,raf,out);
 	}
 
-	private void init() throws IOException {
+	protected LogFile(File file,RandomAccessFile raf,OutputStream out) throws IOException {
+		super(out);
+		this.file = file;
+		this.raf = raf;
+
 		if( raf.length() == 0 ) {
 			end = 8;
 			raf.writeLong(end);
@@ -56,21 +57,6 @@
 		}
 	}
 
-	private LogFile(LogFile lf) throws IOException {
-		this.file = lf.file;
-		this.raf = new RandomAccessFile(file,"r");
-		this.out = null;
-		this.end = lf.end;
-	}
-
-	public void close() throws IOException {
-		raf.close();
-	}
-
-	public LogFile snapshot() throws IOException {
-		return new LogFile(this);
-	}
-
 	public String toString() {
 		return "LogFile<" + file.getName() + ">";
 	}
@@ -93,7 +79,7 @@
 	}
 
 	public void commit() throws IOException {
-		out.flush();
+		flush();
 		end = raf.getFilePointer();
 		raf.seek(0L);
 		raf.writeLong(end);
@@ -101,7 +87,7 @@
 	}
 
 	public void rollback() throws IOException {
-		out.flush();
+		flush();
 		raf.seek(end);
 	}
 
@@ -267,41 +253,4 @@
 		writeBytesRef( term.bytes() );
 	}
 
-
-	public void writeByte(int v) throws IOException {
-		out.writeByte(v);
-	}
-
-	public void writeInt(int v) throws IOException {
-		out.writeInt(v);
-	}
-
-	public void writeLong(long v) throws IOException {
-		out.writeLong(v);
-	}
-
-	public void writeFloat(float v) throws IOException {
-		out.writeFloat(v);
-	}
-
-	public void writeDouble(double v) throws IOException {
-		out.writeDouble(v);
-	}
-
-	public void writeBoolean(boolean v) throws IOException {
-		out.writeBoolean(v);
-	}
-
-	public void writeUTF(String s) throws IOException {
-		out.writeUTF(s);
-	}
-
-	public void write(byte[] b) throws IOException {
-		out.write(b);
-	}
-
-	public void write(byte[] b, int off, int len) throws IOException {
-		out.write(b,off,len);
-	}
-
 }