aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-08-27 01:07:53 +0200
committer zaaarf <zaaarf@proton.me>2023-08-27 01:07:53 +0200
commit4cb9bb46e04c93f1469861bddec2d5b5e577c710 (patch)
tree836bfd26f75c06ddc57448319692c89df531d426
parent5bd9f685b1df4e819dcab5ebe4bff0146bb90aa3 (diff)
fix: don't bother with error catching
-rw-r--r--src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java87
1 files changed, 42 insertions, 45 deletions
diff --git a/src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java b/src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java
index f5f7b10..2cc8007 100644
--- a/src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java
+++ b/src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java
@@ -21,60 +21,57 @@ public class MappingWriter {
/**
* The main function, must be passed exactly two arguments
* @param args the command line arguments
- * @throws IOException if something goes wrong
+ * @throws IOException if something goes wrong while writing the file
+ * @throws ParseException if something goes wrong while parsin arguments
*/
public static void main(String[] args) throws IOException, ParseException {
- try {
- Options options = new Options()
- .addOption("r", "reverse", false, "Writes down inverted mappings");
- DefaultParser parser = new DefaultParser();
- CommandLine cmdLine = parser.parse(options, args);
- args = cmdLine.getArgs();
+ Options options = new Options()
+ .addOption("r", "reverse", false, "Writes down inverted mappings");
+ DefaultParser parser = new DefaultParser();
+ CommandLine cmdLine = parser.parse(options, args);
+ args = cmdLine.getArgs();
- if(args.length != 3) {
- System.err.println("Bad argument count!");
- System.err.println("java -jar mapping-writer.jar [-r] <location> <format> <output>");
- return;
- }
-
- //load the mapper
- List<String> lines = MapperProvider.fetchFromLocalOrRemote(args[0]);
- IMapper mapper = MapperProvider.getMapper(lines);
- mapper.populate(lines, false);
- if(cmdLine.hasOption("reverse"))
- mapper = mapper.getInverted();
+ if(args.length != 3) {
+ System.err.println("Bad argument count!");
+ System.err.println("java -jar mapping-writer.jar [-r] <location> <format> <output>");
+ return;
+ }
- //load the writers
- Map<String, IWriter> writerMap = new HashMap<>();
- for(IWriter w : ServiceLoader.load(IWriter.class))
- writerMap.put(w.uniqueId(), w);
+ //load the mapper
+ List<String> lines = MapperProvider.fetchFromLocalOrRemote(args[0]);
+ IMapper mapper = MapperProvider.getMapper(lines);
+ mapper.populate(lines, false);
+ if(cmdLine.hasOption("reverse"))
+ mapper = mapper.getInverted();
- //get the one we need
- IWriter writer = writerMap.get(args[1]);
- if(writer == null) {
- System.err.printf("%s was not recognised as a valid format!", args[1]);
- return;
- }
+ //load the writers
+ Map<String, IWriter> writerMap = new HashMap<>();
+ for(IWriter w : ServiceLoader.load(IWriter.class))
+ writerMap.put(w.uniqueId(), w);
- //now for the file
- File targetFile = new File(args[2]);
+ //get the one we need
+ IWriter writer = writerMap.get(args[1]);
+ if(writer == null) {
+ System.err.printf("%s was not recognised as a valid format!", args[1]);
+ return;
+ }
- if(!targetFile.createNewFile()) {
- System.out.println("File already exists!");
- return;
- }
+ //now for the file
+ File targetFile = new File(args[2]);
- if(!targetFile.canWrite()) {
- System.out.println("Failed to write to file: access denied.");
- return;
- }
+ if(!targetFile.createNewFile()) {
+ System.out.println("File already exists!");
+ return;
+ }
- //call the writer
- PrintWriter printWriter = new PrintWriter(new FileWriter(targetFile));
- writer.write(mapper, printWriter);
- printWriter.close();
- } catch(ParseException ex) {
- ex.printStackTrace();
+ if(!targetFile.canWrite()) {
+ System.out.println("Failed to write to file: access denied.");
+ return;
}
+
+ //call the writer
+ PrintWriter printWriter = new PrintWriter(new FileWriter(targetFile));
+ writer.write(mapper, printWriter);
+ printWriter.close();
}
}