List of usage examples for java.lang String format
public static String format(String format, Object... args)
From source file:edu.indiana.d2i.sloan.internal.DeleteVMSimulator.java
public static void main(String[] args) { DeleteVMSimulator simulator = new DeleteVMSimulator(); CommandLineParser parser = new PosixParser(); try {/* w w w . jav a2s. c o m*/ CommandLine line = simulator.parseCommandLine(parser, args); String wdir = line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.WORKING_DIR)); if (!HypervisorCmdSimulator.resourceExist(wdir)) { logger.error(String.format("Cannot find VM working dir: %s", wdir)); System.exit(ERROR_CODE.get(ERROR_STATE.VM_NOT_EXIST)); } Properties prop = new Properties(); String filename = HypervisorCmdSimulator.cleanPath(wdir) + HypervisorCmdSimulator.VM_INFO_FILE_NAME; prop.load(new FileInputStream(new File(filename))); // cannot delete VM when it is not shutdown VMState currentState = VMState.valueOf(prop.getProperty(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VM_STATE))); if (!currentState.equals(VMState.SHUTDOWN)) { logger.error("Cannot perform delete when VM is not shutdown"); System.exit(ERROR_CODE.get(ERROR_STATE.VM_NOT_SHUTDOWN)); } // delete working directory FileUtils.deleteDirectory(new File(wdir)); // success System.exit(0); } catch (ParseException e) { logger.error(String.format("Cannot parse input arguments: %s%n, expected:%n%s", StringUtils.join(args, " "), simulator.getUsage(100, "", 5, 5, ""))); System.exit(ERROR_CODE.get(ERROR_STATE.INVALID_INPUT_ARGS)); } catch (IOException e) { logger.error(e.getMessage(), e); System.exit(ERROR_CODE.get(ERROR_STATE.IO_ERR)); } }
From source file:edu.indiana.d2i.sloan.internal.StopVMSimulator.java
public static void main(String[] args) { StopVMSimulator simulator = new StopVMSimulator(); CommandLineParser parser = new PosixParser(); try {/* w w w. j a v a 2 s. c o m*/ CommandLine line = simulator.parseCommandLine(parser, args); String wdir = line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.WORKING_DIR)); if (!HypervisorCmdSimulator.resourceExist(wdir)) { logger.error(String.format("Cannot find VM working dir: %s", wdir)); System.exit(ERROR_CODE.get(ERROR_STATE.VM_NOT_EXIST)); } Properties prop = new Properties(); String filename = HypervisorCmdSimulator.cleanPath(wdir) + HypervisorCmdSimulator.VM_INFO_FILE_NAME; prop.load(new FileInputStream(new File(filename))); // cannot stop VM when it is not running VMState currentState = VMState.valueOf(prop.getProperty(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VM_STATE))); if (!currentState.equals(VMState.RUNNING)) { logger.error("Cannot perform stop when VM is not running"); System.exit(ERROR_CODE.get(ERROR_STATE.VM_NOT_RUNNING)); } // stop VM try { Thread.sleep(1000); } catch (InterruptedException e) { logger.error(e.getMessage()); } // update VM status file, i.e. set state to shutdown prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VM_STATE), VMState.SHUTDOWN.toString()); // save VM state file back prop.store(new FileOutputStream(new File(filename)), ""); // success System.exit(0); } catch (ParseException e) { logger.error(String.format("Cannot parse input arguments: %s%n, expected:%n%s", StringUtils.join(args, " "), simulator.getUsage(100, "", 5, 5, ""))); System.exit(ERROR_CODE.get(ERROR_STATE.INVALID_INPUT_ARGS)); } catch (IOException e) { logger.error(e.getMessage(), e); System.exit(ERROR_CODE.get(ERROR_STATE.IO_ERR)); } }
From source file:com.smartling.api.sdk.file.commandline.RetrieveFile.java
/** * @param args The arguments to pass in. * <pre>/*from w w w .j a v a2 s. c o m*/ * 6 Arguments are expected: * 1) boolean if production should be used (true), or sandbox (false) * 2) apiKey * 3) projectId * 4) path to the property file to download (used to look up the fileUri). * 5) the locale to download the file for. Can be null if the original file is desired. * 6) path to store the file. * <pre> * @throws IOException if an exception occurs in the course of downloading the specified file. * @throws ApiException if an exception occurs while writing translated contents into file */ public static void main(String[] args) throws IOException, ApiException { File translatedFile = retrieve(args); logger.info(String.format(RESULT, translatedFile.getName())); }
From source file:com.mmone.gpdati.config.GpDatiProperties.java
public static void main(String[] args) { String s = "C:/svnprjects/mauro_netbprj/abs-ota-soapui-listener/test/FILE_DISPO__%s.txt"; String td = DateFormatUtils.format(new Date(), "yyyyMMdd"); System.out.println(String.format(s, td)); }
From source file:name.ikysil.beanpathdsl.codegen.CLI.java
/** * @param args the command line arguments *//*from w w w .j av a2s . co m*/ public static void main(String[] args) { final Options options = buildOptions(); try { CommandLineParser parser = new DefaultParser(); CommandLine cmdLine = parser.parse(options, args); if (cmdLine.hasOption("h")) { usage(options); System.exit(1); } Configuration configuration = new Configuration(); if (cmdLine.hasOption("s")) { configuration.setOutputDirectory(cmdLine.getOptionValue("s")); } if (cmdLine.hasOption("c")) { configuration.setOutputCharset(Charset.forName(cmdLine.getOptionValue("c"))); } if (cmdLine.hasOption("cnp")) { configuration.setClassNamePrefix(cmdLine.getOptionValue("cnp")); } if (cmdLine.hasOption("cns")) { configuration.setClassNameSuffix(cmdLine.getOptionValue("cns")); } if (cmdLine.hasOption("pnp")) { configuration.setPackageNamePrefix(cmdLine.getOptionValue("pnp")); } if (cmdLine.hasOption("pns")) { configuration.setPackageNameSuffix(cmdLine.getOptionValue("pns")); } new CodeGen(configuration).process(); } catch (ParseException ex) { System.err.println(String.format("Can not parse arguments: %s", ex.getMessage())); usage(options); } }
From source file:pt.souplesse.spark.Server.java
public static void main(String[] args) { EntityManagerFactory factory = Persistence.createEntityManagerFactory("guestbook"); EntityManager manager = factory.createEntityManager(); JinqJPAStreamProvider streams = new JinqJPAStreamProvider(factory); get("/messages", (req, rsp) -> { rsp.type("application/json"); return gson.toJson(streams.streamAll(manager, Message.class).collect(Collectors.toList())); });/*from www .ja v a2 s.co m*/ post("/messages", (req, rsp) -> { try { Message msg = gson.fromJson(req.body(), Message.class); if (StringUtils.isBlank(msg.getMessage()) || StringUtils.isBlank(msg.getName())) { halt(400); } manager.getTransaction().begin(); manager.persist(msg); manager.getTransaction().commit(); } catch (JsonSyntaxException e) { halt(400); } rsp.type("application/json"); return gson.toJson(streams.streamAll(manager, Message.class).collect(Collectors.toList())); }); get("/comments", (req, rsp) -> { rsp.type("application/json"); Map<String, List<Body>> body = new HashMap<>(); try (CloseableHttpClient client = create().build()) { String url = String.format("https://api.github.com/repos/%s/events", req.queryMap("repo").value()); log.info(url); body = client.execute(new HttpGet(url), r -> { List<Map<String, Object>> list = gson.fromJson(EntityUtils.toString(r.getEntity()), List.class); Map<String, List<Body>> result = new HashMap<>(); list.stream().filter(m -> m.getOrDefault("type", "").equals("IssueCommentEvent")) .map(m -> new Body(((Map<String, String>) m.get("actor")).get("login"), ((Map<String, Map<String, String>>) m.get("payload")).get("comment") .get("body"))) .forEach(b -> result.compute(b.getLogin(), (k, v) -> v == null ? new ArrayList<>() : Lists.asList(b, v.toArray(new Body[v.size()])))); return result; }); } catch (IOException e) { log.error(null, e); halt(400, e.getMessage()); } return gson.toJson(body); }); }
From source file:com.floreantpos.license.FiveStarPOSLicenseManager.java
public static void main(String[] args) throws FileNotFoundException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException, SignatureException, URISyntaxException { /* checks if we need generate the public/private keys */ boolean genKeysParam = FiveStarPOSLicenseManager.genKeys(args); InputStream privateKey = null; if (genKeysParam) { FiveStarPOSKeyGenerator.createKeys(PUBLIC_KEY_FILE, PRIVATE_KEY_FILE); privateKey = new FileInputStream(new File(PRIVATE_KEY_FILE)); } else {//from w w w . j av a2 s . c o m File privateKeyFile = FiveStarPOSLicenseManager.getPrivateKey(args); if (privateKeyFile.exists()) { privateKey = new FileInputStream(new File(PRIVATE_KEY_FILE)); } else { privateKey = FiveStarPOSLicenseManager.class .getResourceAsStream(String.format("/license/%s", PRIVATE_KEY_FILE)); } } /* checks if we need create the template file for a new license */ File templateFile = FiveStarPOSLicenseManager.getTemplateFile(args); if (!templateFile.exists()) { FiveStarPOSLicenseManager.getInstance().createTemplateFile(templateFile); } /* creates the new license */ File licenseFile = new File(LICENSE_FILE); FiveStarPOSLicenseManager.getInstance().generateNewLicense(templateFile, privateKey, licenseFile); }
From source file:edu.cmu.cs.lti.ark.fn.identification.training.ConvertAlphabetFile.java
public static void main(String[] args) throws Exception { final String alphabetFile = args[0]; final String modelFile = args[1]; final String outFile = args[2]; final String featureType = args[3]; final double threshold = args.length >= 5 ? Double.parseDouble(args[4].trim()) : DEFAULT_THRESHOLD; // read in map from feature id -> feature name final BiMap<Integer, String> featureNameById = readAlphabetFile(new File(alphabetFile)).inverse(); // read in parameter values final double[] parameters = TrainBatch.loadModel(modelFile); // write out list of (feature name, feature value) pairs final BufferedWriter output = Files.newWriter(new File(outFile), Charsets.UTF_8); try {/* w w w. j a v a2 s. co m*/ output.write(String.format("%s\n", featureType)); for (int i : xrange(parameters.length)) { final double val = parameters[i]; if (Math.abs(val) <= threshold) continue; output.write(String.format("%s\t%s\n", featureNameById.get(i), val)); } } finally { closeQuietly(output); } }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.loader.CommandLineLoader.java
public static void main(final String[] args) { try {//from www. j av a2s . c o m if (args.length != 1) { throw new Exception("Expected filename argument"); } configureDataSource(); configureDccCommonDataSource(); List<FileListRecord> fileList = readFileList(args[0]); CommandLineLoader cll = new CommandLineLoader(fileList); cll.go(); } catch (Exception e) { //catch everything including runtime exceptions logger.logToLogger(Level.ERROR, String.format("ERROR: %s", e.getMessage())); } }
From source file:edu.cuhk.hccl.cmd.AppQueryExpander.java
public static void main(String[] args) { try {//from w ww .j ava 2 s.c o m CommandLineParser parser = new BasicParser(); Options options = createOptions(); CommandLine line = parser.parse(options, args); // Get parameters String queryStr = line.getOptionValue('q'); int topK = Integer.parseInt(line.getOptionValue('k')); String modelPath = line.getOptionValue('m'); String queryType = line.getOptionValue('t'); QueryExpander expander = null; if (queryType.equalsIgnoreCase("WordVector")) { // Load word vectors System.out.println("[INFO] Loading word vectors..."); expander = new WordVectorExpander(modelPath); } else if (queryType.equalsIgnoreCase("WordNet")) { // Load WordNet System.out.println("[INFO] Loading WordNet..."); expander = new WordNetExpander(modelPath); } else { System.out.println("Please choose a correct expander: WordNet or WordVector!"); System.exit(-1); } // Expand query System.out.println("[INFO] Computing similar words..."); List<String> terms = expander.expandQuery(queryStr, topK); System.out.println(String.format("\n[INFO] The top %d similar words are: ", topK)); for (String term : terms) { System.out.println(term); } } catch (ParseException exp) { System.out.println("Error in parameters: \n" + exp.getMessage()); System.exit(-1); } }