List of usage examples for java.lang String format
public static String format(Locale l, String format, Object... args)
From source file:net.sf.hajdbc.codec.base64.Base64CodecFactory.java
public static void main(String... args) { if (args.length != 2) { System.err.println(String.format("Usage:%s\tjava %s <cluster-id> <password-to-encrypt>", Strings.NEW_LINE, Base64CodecFactory.class.getName())); System.exit(1);/*from ww w . ja va2 s . c om*/ return; } String clusterId = args[0]; String value = args[1]; try { Codec codec = new Base64CodecFactory().createCodec(clusterId); System.out.println(codec.encode(value)); } catch (SQLException e) { e.printStackTrace(System.err); } }
From source file:example.stores.StarbucksClient.java
public static void main(String[] args) { Traverson traverson = new Traverson(URI.create("http://localhost:8080"), MediaTypes.HAL_JSON); Map<String, Object> parameters = new HashMap<>(); parameters.put("location", "40.740337,-73.995146"); parameters.put("distance", "0.5miles"); PagedResources<Resource<Store>> resources = traverson. // follow("stores", "search", "by-location").// withTemplateParameters(parameters).// toObject(TYPE_REFERENCE);/* w ww.j a v a 2s . c o m*/ PageMetadata metadata = resources.getMetadata(); System.out.println( String.format("Got %s of %s stores: ", resources.getContent().size(), metadata.getTotalElements())); for (Resource<Store> resource : resources) { Store store = resource.getContent(); System.out.println(String.format("- %s - %s", store.name, store.address)); } }
From source file:crawlers.Xinh.java
public static void main(String[] args) { System.out.println("Crawl Data Xinh!"); logger.fatal("Crawl Data Xinh!"); int pageSize = 120; String linkXinhCategory = "http://vietmkt.com/xinhxinh/?op=categories"; String linkHome = "http://vietmkt.com/xinhxinh/?op=home&page=%s&pagesize=%s&device=ipad"; String linkCategory = "http://vietmkt.com/xinhxinh/?op=getListCate&ID=%s&page=%s&pagesize=%s&device=ipad"; try {/*from w w w . ja v a 2 s . c o m*/ //Get Home boolean isLoad = true; int i = 0; while (isLoad) { i = (i + 1); System.out.println("[Home] Get Image {" + pageSize + "} -> " + i); logger.fatal("[Home] Get Image {" + pageSize + "} -> " + i); String urlHome = String.format(linkHome, i, pageSize); isLoad = saveImageByUrl(urlHome, "Xinh,XHome"); } //Get All Category JsonObject jsonObjCategory = readJsonObjectFromUrl(linkXinhCategory); if (jsonObjCategory != null) { JsonElement jsonElementErrorCode = jsonObjCategory.get("ErrorCode"); if (jsonElementErrorCode != null && jsonElementErrorCode.getAsInt() == 0) { JsonElement jsonElementLoadMore = jsonObjCategory.get("LoadMore"); JsonArray jsonElementData = jsonObjCategory.get("DATA").getAsJsonArray(); if (jsonElementData != null && jsonElementData.size() > 0) { for (JsonElement tmpJson : jsonElementData) { String catName = tmpJson.getAsJsonObject().get("NAME_CAT").getAsString(); String catKey = tmpJson.getAsJsonObject().get("link").getAsString(); isLoad = true; i = 0; while (isLoad) { i = (i + 1); System.out.println("[" + catKey + "] Get Image {" + pageSize + "} -> " + i); logger.fatal("[" + catKey + "] Get Image {" + pageSize + "} -> " + i); String urlCategory = String.format(linkCategory, catKey, i, pageSize); isLoad = saveImageByUrl(urlCategory, "Xinh," + catName + "," + catKey); } } } } } System.exit(0); // System.out.println(YoutubeChannel.getChannelId("https://www.youtube.com/channel/UC_iuTdGAVYHMcUZm-srQcRw")); // System.out.println(YoutubeChannel.getChannelId("https://www.youtube.com/user/trucnhanchannel")); // System.out.println(YoutubeChannel.getChannelId("https://www.youtube.com/channel/UC_iuTdGAVYHMcUZm-srQcRw!fdsafasd").length()); } catch (Exception ex) { } }
From source file:net.sf.hajdbc.codec.hex.HexCodecFactory.java
public static void main(String... args) { if (args.length != 2) { System.err.println(String.format("Usage:%s\tjava %s <cluster-id> <password-to-encrypt>", Strings.NEW_LINE, HexCodecFactory.class.getName())); System.exit(1);//from ww w. j a v a2s .c om return; } String clusterId = args[0]; String value = args[1]; try { Codec codec = new HexCodecFactory().createCodec(clusterId); System.out.println(codec.encode(value)); } catch (SQLException e) { e.printStackTrace(System.err); } }
From source file:com.hp.mqm.atrf.Main.java
public static void main(String[] args) { long start = System.currentTimeMillis(); setUncaughtExceptionHandler();/*from w ww. j a va2s . c o m*/ CliParser cliParser = new CliParser(); cliParser.handleHelpAndVersionOptions(args); configureLog4J(); logger.info(System.lineSeparator() + System.lineSeparator()); logger.info("************************************************************************************"); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.getDefault()); DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.getDefault()); logger.info((String.format("Starting HPE ALM Test Result Collection Tool %s %s", dateFormatter.format(new Date()), timeFormatter.format(new Date())))); logger.info("************************************************************************************"); FetchConfiguration configuration = cliParser.parse(args); ConfigurationUtilities.setConfiguration(configuration); App app = new App(configuration); app.start(); long end = System.currentTimeMillis(); logger.info(String.format("Finished creating tests and test results on ALM Octane in %s seconds", (end - start) / 1000)); logger.info(System.lineSeparator()); }
From source file:org.eel.kitchen.jsonschema.MiniPerfTest2.java
public static void main(final String... args) throws IOException, JsonSchemaException { final JsonNode googleAPI = JsonLoader.fromResource("/other/google-json-api.json"); final Map<String, JsonNode> schemas = JacksonUtils.nodeToMap(googleAPI.get("schemas")); final JsonSchemaFactory factory = JsonSchemaFactory.defaultFactory(); final JsonSchema schema = factory.fromURI("resource:/schema-draftv3.json"); long begin, current; begin = System.currentTimeMillis(); doValidate(schemas, schema, -1);// www . j a va 2 s . c o m current = System.currentTimeMillis(); System.out.println("Initial validation :" + (current - begin) + " ms"); begin = System.currentTimeMillis(); for (int i = 0; i < 500; i++) { doValidate(schemas, schema, i); if (i % 20 == 0) { current = System.currentTimeMillis(); System.out.println(String.format("Iteration %d (in %d ms)", i, current - begin)); } } final long end = System.currentTimeMillis(); System.out.println("END -- time in ms: " + (end - begin)); System.exit(0); }
From source file:com.github.fge.jsonschema.NewAPIPerfTest.java
public static void main(final String... args) throws IOException, ProcessingException { final JsonNode googleAPI = JsonLoader.fromResource("/other/google-json-api.json"); final Map<String, JsonNode> googleSchemas = JacksonUtils.asMap(googleAPI.get("schemas")); long begin, current; begin = System.currentTimeMillis(); doValidate(googleSchemas, -1);/*from w w w. j av a2 s. c o m*/ current = System.currentTimeMillis(); System.out.println("Initial validation :" + (current - begin) + " ms"); begin = System.currentTimeMillis(); for (int i = 0; i < 500; i++) { doValidate(googleSchemas, i); if (i % 20 == 0) { current = System.currentTimeMillis(); System.out.println(String.format("Iteration %d (in %d ms)", i, current - begin)); } } final long end = System.currentTimeMillis(); System.out.println("END -- time in ms: " + (end - begin)); System.exit(0); }
From source file:com.knewton.mapreduce.cassandra.WriteSampleSSTable.java
/** * Writes a sample SSTable that can be used for running the example job {@link SSTableMRExample} * * @param args/*from www . j av a 2s.co m*/ * Args to be parsed * @throws Exception */ public static void main(String[] args) throws Exception { buildParametersFromArgs(args); IPartitioner partitioner = StorageService.getPartitioner(); String schema = String.format( "CREATE TABLE %s.%s (studentid 'LongType', " + "eventid 'LongType'," + "data 'BytesType', " + "PRIMARY KEY (studentid, eventid))" + " WITH COMPACT STORAGE", KEYSPACE_NAME, COLUMN_FAMILY_NAME); String insertStatement = String.format("INSERT INTO %s.%s (studentid, eventid, data) " + "VALUES (?, ?, ?)", KEYSPACE_NAME, COLUMN_FAMILY_NAME); CQLSSTableWriter tableWriter = CQLSSTableWriter.builder().inDirectory(tableDirectory) .withPartitioner(partitioner).forTable(schema).using(insertStatement).build(); for (int i = 0; i < numberOfStudents; i++) { for (int j = 0; j < eventsPerStudent; j++) { StudentEvent studentEvent = RandomStudentEventGenerator.getRandomStudentEvent(); ByteBuffer columnValue = ByteBuffer .wrap(RandomStudentEventGenerator.serializeStudentEventData(studentEvent.getData())); tableWriter.addRow(RandomStudentEventGenerator.getRandomId(), studentEvent.getId(), columnValue); } } tableWriter.close(); }
From source file:example.Listener.java
public static void main(String[] args) throws Exception { String user = env("ACTIVEMQ_USER", "admin"); String password = env("ACTIVEMQ_PASSWORD", "password"); String host = env("ACTIVEMQ_HOST", "localhost"); int port = Integer.parseInt(env("ACTIVEMQ_PORT", "1883")); final String destination = arg(args, 0, "/topic/event"); MQTT mqtt = new MQTT(); mqtt.setHost(host, port);/*from www . j a v a 2 s.c o m*/ mqtt.setUserName(user); mqtt.setPassword(password); final CallbackConnection connection = mqtt.callbackConnection(); connection.listener(new org.fusesource.mqtt.client.Listener() { long count = 0; long start = System.currentTimeMillis(); public void onConnected() { } public void onDisconnected() { } public void onFailure(Throwable value) { value.printStackTrace(); System.exit(-2); } public void onPublish(UTF8Buffer topic, Buffer msg, Runnable ack) { String body = msg.utf8().toString(); if ("SHUTDOWN".equals(body)) { long diff = System.currentTimeMillis() - start; System.out.println(String.format("Received %d in %.2f seconds", count, (1.0 * diff / 1000.0))); connection.disconnect(new Callback<Void>() { @Override public void onSuccess(Void value) { System.exit(0); } @Override public void onFailure(Throwable value) { value.printStackTrace(); System.exit(-2); } }); } else { if (count == 0) { start = System.currentTimeMillis(); } if (count % 1000 == 0) { System.out.println(String.format("Received %d messages.", count)); } count++; } ack.run(); } }); connection.connect(new Callback<Void>() { @Override public void onSuccess(Void value) { Topic[] topics = { new Topic(destination, QoS.AT_LEAST_ONCE) }; connection.subscribe(topics, new Callback<byte[]>() { public void onSuccess(byte[] qoses) { } public void onFailure(Throwable value) { value.printStackTrace(); System.exit(-2); } }); } @Override public void onFailure(Throwable value) { value.printStackTrace(); System.exit(-2); } }); // Wait forever.. synchronized (Listener.class) { while (true) Listener.class.wait(); } }
From source file:com.google.play.developerapi.samples.ListApks.java
public static void main(String[] args) { try {/*from w w w. j a v a 2s .co m*/ Preconditions.checkArgument(!Strings.isNullOrEmpty(ApplicationConfig.PACKAGE_NAME), "ApplicationConfig.PACKAGE_NAME cannot be null or empty!"); // Create the API service. final AndroidPublisher service = AndroidPublisherHelper.init(ApplicationConfig.APPLICATION_NAME, ApplicationConfig.SERVICE_ACCOUNT_EMAIL); final Edits edits = service.edits(); // Create a new edit to make changes. Insert editRequest = edits.insert(ApplicationConfig.PACKAGE_NAME, null /** no content */ ); AppEdit appEdit = editRequest.execute(); // Get a list of apks. ApksListResponse apksResponse = edits.apks().list(ApplicationConfig.PACKAGE_NAME, appEdit.getId()) .execute(); // Print the apk info. for (Apk apk : apksResponse.getApks()) { System.out.println(String.format("Version: %d - Binary sha1: %s", apk.getVersionCode(), apk.getBinary().getSha1())); } } catch (IOException | GeneralSecurityException ex) { log.error("Exception was thrown while updating listing", ex); } }