From 25216c0268ec2410dea2c9a26bc85e01ce09dfa1 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Mon, 13 May 2013 16:17:32 +0200 Subject: [PATCH] added argument handling to JobGenerator --- src/at/ac/tuwien/lsdc/JobGenerator.java | 39 ++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/at/ac/tuwien/lsdc/JobGenerator.java b/src/at/ac/tuwien/lsdc/JobGenerator.java index 82c6b9f..121362d 100644 --- a/src/at/ac/tuwien/lsdc/JobGenerator.java +++ b/src/at/ac/tuwien/lsdc/JobGenerator.java @@ -1,16 +1,53 @@ package at.ac.tuwien.lsdc; +import java.io.File; +import java.io.IOException; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class JobGenerator { private static final Logger log = LoggerFactory.getLogger(JobGenerator.class); private static final String USAGE = "JobGenerator needs exactly 3 parameters: Szenario, count, targetFile"; + + private enum ScenarioType { A, B, C }; + + private static ScenarioType scenario; + private static int count; + private static File targetFile; + public static void main(String[] args) throws Exception { + System.out.println("args: " + args + " len: " + args.length); if (args.length != 3) { - throw new IllegalArgumentException(USAGE); + log.info(USAGE); + System.exit(1); } log.info("Generate CSV with..."); + doArgumentHandling(args); + } + + private static void doArgumentHandling(String[] args) { + String scenarioStr = args[0]; + String countStr = args[1]; + String targetFileStr = args[2]; + scenario = ScenarioType.valueOf(scenarioStr); + try { + boolean fileWriteOK = false; + count = Integer.parseInt(countStr); + targetFile = new File(targetFileStr); + if (targetFile.exists()) { + fileWriteOK = targetFile.canWrite(); + } else { + targetFile.createNewFile(); + fileWriteOK = true; + } + if (!fileWriteOK) + throw new IOException("Can not write to File " + targetFileStr); + } catch (Exception e) { + e.printStackTrace(); + log.info(USAGE); + System.exit(1); + } } } -- 2.43.0