MCPcopy Index your code
hub / github.com/boazy/TWEditorEnhanced / load

Method load

src/main/java/SaveDatabase.java:40–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38 }
39
40 public void load()
41 throws DBException, IOException
42 {
43 RandomAccessFile in = new RandomAccessFile(this.file, "r");
44 try
45 {
46 byte[] buffer = new byte[40];
47 int count = in.read(buffer, 0, 12);
48 if (count != 12) {
49 throw new DBException("Save header truncated");
50 }
51 String signature = new String(buffer, 0, 4);
52 if (!signature.equals("RGMH")) {
53 throw new DBException("Save signature is not valid");
54 }
55 int version = getInteger(buffer, 4);
56 if (version != 1) {
57 throw new DBException("Save version " + version + " is not supported");
58 }
59 this.dataOffset = getInteger(buffer, 8);
60
61 in.seek(in.length() - 8L);
62 count = in.read(buffer, 0, 8);
63 if (count != 8) {
64 throw new DBException("Save trailer truncated");
65 }
66 int resourceOffset = getInteger(buffer, 0);
67 int resourceCount = getInteger(buffer, 4);
68 in.seek(resourceOffset);
69
70 for (int i = 0; i < resourceCount; i++) {
71 count = in.read(buffer, 0, 4);
72 if (count != 4) {
73 throw new DBException("Resource table truncated");
74 }
75 int length = getInteger(buffer, 0);
76 if (buffer.length < length) {
77 buffer = new byte[length];
78 }
79 count = in.read(buffer, 0, length);
80 if (count != length) {
81 throw new DBException("Resource name truncated");
82 }
83 String name = new String(buffer, 0, length, "UTF-8");
84 count = in.read(buffer, 0, 8);
85 if (count != 8) {
86 throw new DBException("Resource table truncated");
87 }
88 length = getInteger(buffer, 0);
89 int offset = getInteger(buffer, 4);
90 SaveEntry saveEntry = new SaveEntry(name, this.file, offset, length);
91 this.entries.add(saveEntry);
92 this.entryMap.put(saveEntry.getResourceName(), saveEntry);
93 }
94 } finally {
95 if (in != null)
96 in.close();
97 }

Callers 2

runMethod · 0.95
runMethod · 0.95

Calls 5

getIntegerMethod · 0.95
getResourceNameMethod · 0.95
readMethod · 0.45
equalsMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected