summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java')
-rw-r--r--src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java
index 692bd81..33eae6c 100644
--- a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java
+++ b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java
@@ -23,7 +23,7 @@ public class MappingsEnigmaReader
23 else 23 else
24 { 24 {
25 mappings = new Mappings(); 25 mappings = new Mappings();
26 readFile(mappings, new BufferedReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8))); 26 readFile(mappings, file);
27 } 27 }
28 return mappings; 28 return mappings;
29 } 29 }
@@ -33,7 +33,7 @@ public class MappingsEnigmaReader
33 if (files != null) { 33 if (files != null) {
34 for (File file : files) { 34 for (File file : files) {
35 if (file.isFile() && !file.getName().startsWith(".") && file.getName().endsWith(".mapping")) 35 if (file.isFile() && !file.getName().startsWith(".") && file.getName().endsWith(".mapping"))
36 readFile(mappings, new BufferedReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8))); 36 readFile(mappings, file);
37 else if (file.isDirectory()) 37 else if (file.isDirectory())
38 readDirectory(mappings, file.getAbsoluteFile()); 38 readDirectory(mappings, file.getAbsoluteFile());
39 } 39 }
@@ -42,8 +42,9 @@ public class MappingsEnigmaReader
42 throw new IOException("Cannot access directory" + directory.getAbsolutePath()); 42 throw new IOException("Cannot access directory" + directory.getAbsolutePath());
43 } 43 }
44 44
45 public Mappings readFile(Mappings mappings, BufferedReader in) throws IOException, MappingParseException { 45 public Mappings readFile(Mappings mappings, File file) throws IOException, MappingParseException {
46 46
47 BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8));
47 Deque<Object> mappingStack = Queues.newArrayDeque(); 48 Deque<Object> mappingStack = Queues.newArrayDeque();
48 49
49 int lineNumber = 0; 50 int lineNumber = 0;
@@ -91,7 +92,7 @@ public class MappingsEnigmaReader
91 92
92 // inner class 93 // inner class
93 if (!(mappingStack.peek() instanceof ClassMapping)) { 94 if (!(mappingStack.peek() instanceof ClassMapping)) {
94 throw new MappingParseException(lineNumber, "Unexpected CLASS entry here!"); 95 throw new MappingParseException(file, lineNumber, "Unexpected CLASS entry here!");
95 } 96 }
96 97
97 classMapping = readClass(parts, true); 98 classMapping = readClass(parts, true);
@@ -100,24 +101,24 @@ public class MappingsEnigmaReader
100 mappingStack.push(classMapping); 101 mappingStack.push(classMapping);
101 } else if (token.equalsIgnoreCase("FIELD")) { 102 } else if (token.equalsIgnoreCase("FIELD")) {
102 if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) { 103 if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) {
103 throw new MappingParseException(lineNumber, "Unexpected FIELD entry here!"); 104 throw new MappingParseException(file, lineNumber, "Unexpected FIELD entry here!");
104 } 105 }
105 ((ClassMapping) mappingStack.peek()).addFieldMapping(readField(parts)); 106 ((ClassMapping) mappingStack.peek()).addFieldMapping(readField(parts));
106 } else if (token.equalsIgnoreCase("METHOD")) { 107 } else if (token.equalsIgnoreCase("METHOD")) {
107 if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) { 108 if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) {
108 throw new MappingParseException(lineNumber, "Unexpected METHOD entry here!"); 109 throw new MappingParseException(file, lineNumber, "Unexpected METHOD entry here!");
109 } 110 }
110 MethodMapping methodMapping = readMethod(parts); 111 MethodMapping methodMapping = readMethod(parts);
111 ((ClassMapping) mappingStack.peek()).addMethodMapping(methodMapping); 112 ((ClassMapping) mappingStack.peek()).addMethodMapping(methodMapping);
112 mappingStack.push(methodMapping); 113 mappingStack.push(methodMapping);
113 } else if (token.equalsIgnoreCase("ARG")) { 114 } else if (token.equalsIgnoreCase("ARG")) {
114 if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof MethodMapping)) { 115 if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof MethodMapping)) {
115 throw new MappingParseException(lineNumber, "Unexpected ARG entry here!"); 116 throw new MappingParseException(file, lineNumber, "Unexpected ARG entry here!");
116 } 117 }
117 ((MethodMapping) mappingStack.peek()).addArgumentMapping(readArgument(parts)); 118 ((MethodMapping) mappingStack.peek()).addArgumentMapping(readArgument(parts));
118 } 119 }
119 } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException ex) { 120 } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException ex) {
120 throw new MappingParseException(lineNumber, "Malformed line:\n" + line); 121 throw new MappingParseException(file, lineNumber, "Malformed line:\n" + line);
121 } catch (MappingConflict e) { 122 } catch (MappingConflict e) {
122 e.printStackTrace(); 123 e.printStackTrace();
123 } 124 }