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