32
32
import java .util .Deque ;
33
33
import java .util .List ;
34
34
import java .util .Locale ;
35
+ import java .util .stream .Stream ;
35
36
36
37
public enum EnigmaMappingsReader implements MappingsReader {
37
38
FILE {
@@ -56,10 +57,13 @@ public EntryTree<EntryMapping> read(Path root, ProgressListener progress, Mappin
56
57
57
58
EntryTree <EntryMapping > mappings = new HashEntryTree <>();
58
59
59
- List <Path > files = Files .walk (root )
60
+ List <Path > files ;
61
+ try (Stream <Path > fileStream = Files .walk (root )) {
62
+ files = fileStream
60
63
.filter (f -> !Files .isDirectory (f ))
61
64
.filter (f -> f .toString ().endsWith (".mapping" ))
62
65
.toList ();
66
+ }
63
67
64
68
progress .init (files .size (), I18n .translate ("progress.mappings.enigma_directory.loading" ));
65
69
int step = 0 ;
@@ -85,34 +89,6 @@ public EntryTree<EntryMapping> read(Path zip, ProgressListener progress, Mapping
85
89
}
86
90
};
87
91
88
- /**
89
- * Reads multiple Enigma mapping files.
90
- *
91
- * @param progress the progress listener
92
- * @param paths the Enigma files to read; cannot be empty
93
- * @return the parsed mappings
94
- * @throws MappingParseException if a mapping file cannot be parsed
95
- * @throws IOException if an IO error occurs
96
- * @throws IllegalArgumentException if there are no paths to read
97
- */
98
- public static EntryTree <EntryMapping > readFiles (ProgressListener progress , Path ... paths ) throws MappingParseException , IOException {
99
- EntryTree <EntryMapping > mappings = new HashEntryTree <>();
100
-
101
- if (paths .length == 0 ) {
102
- throw new IllegalArgumentException ("No paths to read mappings from" );
103
- }
104
-
105
- progress .init (paths .length , I18n .translate ("progress.mappings.enigma_directory.loading" ));
106
- int step = 0 ;
107
-
108
- for (Path file : paths ) {
109
- progress .step (step ++, paths .toString ());
110
- readFile (file , mappings );
111
- }
112
-
113
- return mappings ;
114
- }
115
-
116
92
private static void readFile (Path path , EntryTree <EntryMapping > mappings ) throws IOException , MappingParseException {
117
93
List <String > lines = Files .readAllLines (path , StandardCharsets .UTF_8 );
118
94
Deque <MappingPair <?, RawEntryMapping >> mappingStack = new ArrayDeque <>();
@@ -245,7 +221,12 @@ private static MappingPair<ClassEntry, RawEntryMapping> parseClass(@Nullable Ent
245
221
obfuscatedEntry = new ClassEntry (obfuscatedName );
246
222
}
247
223
248
- String mapping = tokens [2 ];
224
+ String mapping = null ;
225
+ if (tokens .length == 3 ) {
226
+ mapping = tokens [2 ];
227
+ } else if (tokens .length != 2 ) {
228
+ throw new RuntimeException ("invalid class declaration: not enough tokens (" + tokens .length + " found, 2 needed)!" );
229
+ }
249
230
250
231
return new MappingPair <>(obfuscatedEntry , new RawEntryMapping (mapping ));
251
232
}
0 commit comments