Waypoint magic
This commit is contained in:
parent
c3009b46a8
commit
6ce0f40451
@ -30,6 +30,12 @@ import java.util.*;
|
|||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public class Waypoints {
|
public class Waypoints {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Magic value to detect invalid waypoint files
|
||||||
|
*/
|
||||||
|
private static final long WAYPOINT_MAGIC_VALUE = 121977993584L; // good value
|
||||||
|
|
||||||
private final Path directory;
|
private final Path directory;
|
||||||
private final Map<Waypoint.Tag, Set<Waypoint>> waypoints;
|
private final Map<Waypoint.Tag, Set<Waypoint>> waypoints;
|
||||||
|
|
||||||
@ -63,7 +69,13 @@ public class Waypoints {
|
|||||||
BufferedInputStream bufIn = new BufferedInputStream(fileIn);
|
BufferedInputStream bufIn = new BufferedInputStream(fileIn);
|
||||||
DataInputStream in = new DataInputStream(bufIn)
|
DataInputStream in = new DataInputStream(bufIn)
|
||||||
) {
|
) {
|
||||||
while (true) {
|
long magic = in.readLong();
|
||||||
|
if (magic != WAYPOINT_MAGIC_VALUE) {
|
||||||
|
throw new IOException("Bad magic value " + magic);
|
||||||
|
}
|
||||||
|
|
||||||
|
long length = in.readLong(); // Yes I want 9,223,372,036,854,775,807 waypoints, do you not?
|
||||||
|
while (length-- > 0) {
|
||||||
String name = in.readUTF();
|
String name = in.readUTF();
|
||||||
long creationTimestamp = in.readLong();
|
long creationTimestamp = in.readLong();
|
||||||
int x = in.readInt();
|
int x = in.readInt();
|
||||||
@ -81,6 +93,8 @@ public class Waypoints {
|
|||||||
BufferedOutputStream bufOut = new BufferedOutputStream(fileOut);
|
BufferedOutputStream bufOut = new BufferedOutputStream(fileOut);
|
||||||
DataOutputStream out = new DataOutputStream(bufOut)
|
DataOutputStream out = new DataOutputStream(bufOut)
|
||||||
) {
|
) {
|
||||||
|
out.writeLong(WAYPOINT_MAGIC_VALUE);
|
||||||
|
out.writeLong(waypoints.get(tag).size());
|
||||||
for (Waypoint waypoint : waypoints.get(tag)) {
|
for (Waypoint waypoint : waypoints.get(tag)) {
|
||||||
out.writeUTF(waypoint.name);
|
out.writeUTF(waypoint.name);
|
||||||
out.writeLong(waypoint.creationTimestamp());
|
out.writeLong(waypoint.creationTimestamp());
|
||||||
|
Loading…
Reference in New Issue
Block a user