forked from SteamWar/SteamWar
Added flushing of trace write to prevent eof on read
This commit is contained in:
+1
-3
@@ -64,9 +64,7 @@ public class TraceManager implements Listener {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (TraceRepository.getVersion(traceFile) == TraceRepository.SERIALISATION_VERSION) {
|
if (TraceRepository.getVersion(traceFile) == TraceRepository.SERIALISATION_VERSION) {
|
||||||
Trace t = TraceRepository.readTrace(traceFile);
|
add(TraceRepository.readTrace(traceFile));
|
||||||
add(t);
|
|
||||||
System.out.println(t);
|
|
||||||
} else {
|
} else {
|
||||||
String uuid = traceFile.getName().replace(".meta", "");
|
String uuid = traceFile.getName().replace(".meta", "");
|
||||||
|
|
||||||
|
|||||||
+6
-2
@@ -41,7 +41,7 @@ public class TraceRepository {
|
|||||||
Region region = Region.getREGION_MAP().get(reader.readUTF());
|
Region region = Region.getREGION_MAP().get(reader.readUTF());
|
||||||
Date date = (Date) reader.readObject();
|
Date date = (Date) reader.readObject();
|
||||||
File recordsFile = new File(tracesFolder,uuid + ".records");
|
File recordsFile = new File(tracesFolder,uuid + ".records");
|
||||||
reader.readInt();
|
int serialisationVersion = reader.readInt();
|
||||||
int recordsCount = reader.readInt();
|
int recordsCount = reader.readInt();
|
||||||
|
|
||||||
return new Trace(uuid, region, date, metadataFile, recordsFile, recordsCount);
|
return new Trace(uuid, region, date, metadataFile, recordsFile, recordsCount);
|
||||||
@@ -49,13 +49,14 @@ public class TraceRepository {
|
|||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
protected static void writeTrace(Trace trace, List<TNTPoint> records) {
|
protected static void writeTrace(Trace trace, List<TNTPoint> records) {
|
||||||
@Cleanup
|
|
||||||
ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(trace.getMetadataSaveFile()));
|
ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(trace.getMetadataSaveFile()));
|
||||||
outputStream.writeUTF(trace.getUuid().toString());
|
outputStream.writeUTF(trace.getUuid().toString());
|
||||||
outputStream.writeUTF(trace.getRegion().getName());
|
outputStream.writeUTF(trace.getRegion().getName());
|
||||||
outputStream.writeObject(trace.getDate());
|
outputStream.writeObject(trace.getDate());
|
||||||
outputStream.writeInt(SERIALISATION_VERSION);
|
outputStream.writeInt(SERIALISATION_VERSION);
|
||||||
outputStream.writeInt(records.size());
|
outputStream.writeInt(records.size());
|
||||||
|
outputStream.flush();
|
||||||
|
outputStream.close();
|
||||||
|
|
||||||
|
|
||||||
writeTraceRecords(trace.getRecordsSaveFile(), records);
|
writeTraceRecords(trace.getRecordsSaveFile(), records);
|
||||||
@@ -82,6 +83,8 @@ public class TraceRepository {
|
|||||||
outputStream.writeDouble(velocity.getY());
|
outputStream.writeDouble(velocity.getY());
|
||||||
outputStream.writeDouble(velocity.getZ());
|
outputStream.writeDouble(velocity.getZ());
|
||||||
}
|
}
|
||||||
|
outputStream.flush();
|
||||||
|
outputStream.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@@ -118,6 +121,7 @@ public class TraceRepository {
|
|||||||
List<TNTPoint> records = new ArrayList<>();
|
List<TNTPoint> records = new ArrayList<>();
|
||||||
for (int i = 0; i < trace.getRecordsCount(); i++) {
|
for (int i = 0; i < trace.getRecordsCount(); i++) {
|
||||||
records.add(readTraceRecord(inputStream));
|
records.add(readTraceRecord(inputStream));
|
||||||
|
System.out.println("Read record " + i + " of " + trace.getRecordsCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Integer, List<TNTPoint>> histories = new HashMap<>();
|
Map<Integer, List<TNTPoint>> histories = new HashMap<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user