refactoring
This commit is contained in:
parent
ed1254bfd1
commit
34daa4dd03
|
@ -14,6 +14,9 @@ import com.rusefi.core.Pair;
|
|||
import com.rusefi.core.Sensor;
|
||||
import com.rusefi.core.SensorCentral;
|
||||
import com.rusefi.io.*;
|
||||
import com.rusefi.stream.StreamFile;
|
||||
import com.rusefi.stream.TSHighSpeedLog;
|
||||
import com.rusefi.stream.VcdStreamFile;
|
||||
import com.rusefi.tune.xml.Msq;
|
||||
import com.rusefi.ui.livedocs.LiveDocsRegistry;
|
||||
import jssc.SerialPortException;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.rusefi.composite.test;
|
||||
|
||||
import com.rusefi.binaryprotocol.VcdStreamFile;
|
||||
import com.rusefi.stream.VcdStreamFile;
|
||||
import com.rusefi.composite.CompositeEvent;
|
||||
import com.rusefi.composite.CompositeParser;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package com.rusefi.binaryprotocol;
|
||||
package com.rusefi.stream;
|
||||
|
||||
import com.rusefi.composite.CompositeEvent;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class StreamFile {
|
||||
protected FileWriter writer;
|
||||
protected OutputStream stream;
|
||||
protected Writer writer;
|
||||
|
||||
public StreamFile() {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||
|
@ -18,7 +18,7 @@ public abstract class StreamFile {
|
|||
}));
|
||||
}
|
||||
|
||||
abstract void append(List<CompositeEvent> events);
|
||||
public abstract void append(List<CompositeEvent> events);
|
||||
|
||||
public synchronized void close() {
|
||||
if (writer != null) {
|
||||
|
@ -30,8 +30,20 @@ public abstract class StreamFile {
|
|||
}
|
||||
}
|
||||
writer = null;
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
// ignoring this one
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeFooter(FileWriter writer) throws IOException {
|
||||
protected void createFileWriter(String fileName) throws FileNotFoundException {
|
||||
stream = new FileOutputStream(fileName);
|
||||
writer = new OutputStreamWriter(stream);
|
||||
}
|
||||
|
||||
protected void writeFooter(Writer writer) throws IOException {
|
||||
}
|
||||
}
|
|
@ -1,11 +1,9 @@
|
|||
package com.rusefi.binaryprotocol;
|
||||
package com.rusefi.stream;
|
||||
|
||||
import com.rusefi.composite.CompositeEvent;
|
||||
import com.rusefi.rusEFIVersion;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
public class TSHighSpeedLog extends StreamFile {
|
||||
|
@ -23,10 +21,10 @@ public class TSHighSpeedLog extends StreamFile {
|
|||
}
|
||||
|
||||
@Override
|
||||
void append(List<CompositeEvent> events) {
|
||||
public void append(List<CompositeEvent> events) {
|
||||
try {
|
||||
if (writer == null) {
|
||||
writer = new FileWriter(fileName);
|
||||
createFileWriter(fileName);
|
||||
writeHeader(writer);
|
||||
}
|
||||
for (CompositeEvent event : events) {
|
||||
|
@ -43,7 +41,7 @@ public class TSHighSpeedLog extends StreamFile {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void writeFooter(FileWriter writer) throws IOException {
|
||||
protected void writeFooter(Writer writer) throws IOException {
|
||||
writer.write("MARK 028\n");
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.rusefi.binaryprotocol;
|
||||
package com.rusefi.stream;
|
||||
|
||||
import com.rusefi.composite.CompositeEvent;
|
||||
|
||||
|
@ -74,7 +74,7 @@ public class VcdStreamFile extends StreamFile {
|
|||
public void append(List<CompositeEvent> events) {
|
||||
try {
|
||||
if (writer == null) {
|
||||
writer = new FileWriter(fileName);
|
||||
createFileWriter(fileName);
|
||||
writeHeader(writer, new Date());
|
||||
}
|
||||
appendEvents(events, writer);
|
Loading…
Reference in New Issue