List of usage examples for java.lang Long parseLong
public static long parseLong(String s) throws NumberFormatException
From source file:TestReadCustData.java
public static void main(String[] args) { AgentLoader.loadAgentFromClasspath("avaje-ebeanorm-agent", "debug=1"); List<Customer> lCust = new ArrayList<>(); try {/*from w w w. ja v a 2s . c om*/ List<String> s = Files.readAllLines(Paths.get("customer.txt"), Charsets.ISO_8859_1); for (String s1 : s) { if (!s1.startsWith("GRUP")) { Customer c = new Customer(); try { c.setId(Long.parseLong(s1.split("~")[3])); } catch (ArrayIndexOutOfBoundsException arrex) { c.setId(Long.parseLong(s1.split("~")[3])); } try { c.setNama(s1.split("~")[4]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNama(""); } try { c.setShipto(s1.split("~")[9]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setShipto(""); } try { c.setKota(s1.split("~")[12]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setKota(""); } try { c.setProvinsi(s1.split("~")[13]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setProvinsi(""); } try { c.setKodePos(s1.split("~")[14]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setKodePos(""); } try { c.setNamaArea(s1.split("~")[2]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNamaArea(""); } try { c.setDKLK(s1.split("~")[15]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setDKLK(""); } try { c.setCreditLimit(Long.parseLong(s1.split("~")[16])); } catch (ArrayIndexOutOfBoundsException arrex) { c.setCreditLimit(new Long(0)); } try { c.setNpwp(s1.split("~")[11]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNpwp(""); } try { c.setNamaWajibPajak(s1.split("~")[10]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNamaWajibPajak(""); } try { c.setCreationDate(s1.split("~")[6]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setCreationDate(""); } try { c.setLastUpdateBy(s1.split("~")[17]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setLastUpdateBy(""); } try { c.setLastUpdateDate(s1.split("~")[18]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setLastUpdateDate(""); } lCust.add(c); } } for (Customer c : lCust) { Customer cc = Ebean.find(Customer.class, c.getId()); if (cc != null) { cc = c; Ebean.update(cc); } System.out.print(c.getId()); System.out.print(" | "); System.out.print(c.getNama()); System.out.print(" | "); System.out.print(c.getShipto()); System.out.print(" | "); System.out.print(c.getNpwp()); System.out.print(" | "); System.out.print(c.getNamaWajibPajak()); System.out.println(); } } catch (IOException ex) { Logger.getLogger(TestReadCustData.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:cn.lynx.emi.license.GenerateLicense.java
public static void main(String[] args) throws ClassNotFoundException, ParseException { if (args == null || args.length != 4) { System.err.println("Please provide [machine code] [cpu] [memory in gb] [yyyy-MM-dd] as parameter"); return;//w w w . j a v a 2s . c o m } InputStream is = GenerateLicense.class.getResourceAsStream("/privatekey"); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String key = null; try { key = br.readLine(); } catch (IOException e) { System.err.println( "Can't read the private key file, make sure there's a file named \"privatekey\" in the root classpath"); e.printStackTrace(); return; } if (key == null) { System.err.println( "Can't read the private key file, make sure there's a file named \"privatekey\" in the root classpath"); return; } String machineCode = args[0]; int cpu = Integer.parseInt(args[1]); long mem = Long.parseLong(args[2]) * 1024 * 1024 * 1024; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); long expDate = sdf.parse(args[3]).getTime(); LicenseBean lb = new LicenseBean(); lb.setCpuCount(cpu); lb.setMemCount(mem); lb.setMachineCode(machineCode); lb.setExpireDate(expDate); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(baos); os.writeObject(lb); os.close(); String serializedLicense = Base64.encodeBase64String(baos.toByteArray()); System.out.println("License:" + encrypt(key, serializedLicense)); } catch (IOException e) { e.printStackTrace(); } }
From source file:koper.demo.performance.SendDataEventMsgPerf.java
/** * DataEventMsg ?//from w ww .j a v a2s .com * @param args ?:??? * ?:?????? sleep */ public static void main(String[] args) throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("kafka/context-data-message.xml", "kafka/context-data-producer.xml"); Order order = new Order(); order.setId(100); order.setOrderNo("order_no"); order.setCreatedTime("oroder_created_time"); OrderService orderService = (OrderService) context.getBean("orderServiceImpl"); int threadNum = 1; long sleepMs = 1000L; if (args.length >= 1) { threadNum = Integer.parseInt(args[0]); sleepMs = Long.parseLong(args[1]); } final long finalSleepMs = sleepMs; ExecutorService executorService = Executors.newFixedThreadPool(threadNum); for (int i = 0; i < threadNum; ++i) { executorService.execute(() -> { while (true) { orderService.insertOrder(order); try { Thread.sleep(finalSleepMs); } catch (Exception e) { e.printStackTrace(); } } }); } }
From source file:Pong.java
public static void main(String... args) throws Exception { System.setProperty("os.max.pid.bits", "16"); Options options = new Options(); options.addOption("i", true, "Input chronicle path"); options.addOption("n", true, "Number of entries to write"); options.addOption("w", true, "Number of writer threads"); options.addOption("r", true, "Number of reader threads"); options.addOption("x", false, "Delete the output chronicle at startup"); CommandLine cmd = new DefaultParser().parse(options, args); final Path output = Paths.get(cmd.getOptionValue("o", "/tmp/__test/chr")); final long maxCount = Long.parseLong(cmd.getOptionValue("n", "10000000")); final int writerThreadCount = Integer.parseInt(cmd.getOptionValue("w", "4")); final int readerThreadCount = Integer.parseInt(cmd.getOptionValue("r", "4")); final boolean deleteOnStartup = cmd.hasOption("x"); if (deleteOnStartup) { FileUtil.removeRecursive(output); }/*from ww w . j ava 2 s.c o m*/ final Chronicle chr = ChronicleQueueBuilder.vanilla(output.toFile()).build(); final ExecutorService executor = Executors.newFixedThreadPool(4); final List<Future<?>> futures = new ArrayList<>(); final long totalCount = writerThreadCount * maxCount; final long t0 = System.nanoTime(); for (int i = 0; i != readerThreadCount; ++i) { final int tid = i; futures.add(executor.submit((Runnable) () -> { try { IntLongMap counts = HashIntLongMaps.newMutableMap(); ExcerptTailer tailer = chr.createTailer(); final StringBuilder sb1 = new StringBuilder(); final StringBuilder sb2 = new StringBuilder(); long count = 0; while (count != totalCount) { if (!tailer.nextIndex()) continue; final int id = tailer.readInt(); final long val = tailer.readStopBit(); final long longValue = tailer.readLong(); sb1.setLength(0); sb2.setLength(0); tailer.read8bitText(sb1); tailer.read8bitText(sb2); if (counts.addValue(id, 1) - 1 != val || longValue != 0x0badcafedeadbeefL || !StringInterner.isEqual("FooBar", sb1) || !StringInterner.isEqual("AnotherFooBar", sb2)) { System.out.println("Unexpected value " + id + ", " + val + ", " + Long.toHexString(longValue) + ", " + sb1.toString() + ", " + sb2.toString()); return; } ++count; if (count % 1_000_000 == 0) { long t1 = System.nanoTime(); System.out.println(tid + " " + (t1 - t0) / 1e6 + " ms"); } } } catch (IOException e) { e.printStackTrace(); } })); } for (Future f : futures) { f.get(); } executor.shutdownNow(); final long t1 = System.nanoTime(); System.out.println("Done. Rough time=" + (t1 - t0) / 1e6 + " ms"); }
From source file:com.vaushell.superpipes.App.java
/** * Main method./*from ww w .j a v a 2 s . co m*/ * * @param args Command line arguments * @throws Exception */ public static void main(final String... args) throws Exception { // My config final XMLConfiguration config = new XMLConfiguration(); config.setDelimiterParsingDisabled(true); final long delay; final Path datas; switch (args.length) { case 1: { config.load(args[0]); datas = Paths.get("datas"); delay = 10000L; break; } case 2: { config.load(args[0]); datas = Paths.get(args[1]); delay = 10000L; break; } case 3: { config.load(args[0]); datas = Paths.get(args[1]); delay = Long.parseLong(args[2]); break; } default: { config.load("conf/configuration.xml"); datas = Paths.get("datas"); delay = 10000L; break; } } final Dispatcher dispatcher = new Dispatcher(); dispatcher.init(config, datas, new VC_SystemInputFactory()); // Run dispatcher.start(); // Wait try { Thread.sleep(delay); } catch (final InterruptedException ex) { // Ignore } // Stop dispatcher.stopAndWait(); }
From source file:com.alibaba.simpleimage.PressureTester.java
public static void main(String[] args) throws Exception { int threads = 1; long tasks = Long.MAX_VALUE; String rootDir = ""; if (args.length >= 1) { rootDir = args[0];//from w ww. jav a 2s. c o m } if (args.length >= 2) { threads = Integer.parseInt(args[1]); } if (args.length >= 3) { tasks = Long.parseLong(args[2]); } if ("null".equalsIgnoreCase(rootDir)) { rootDir = null; } System.out.println("task begin"); new PressureTester(threads, tasks, rootDir).run(); System.out.println("task end"); }
From source file:com.hellblazer.autoconfigure.ZookeeperLauncher.java
public static void main(String[] argv) throws Exception { if (argv.length != 2) { System.err.println("ZookeeperLauncher <config file> <timeout>"); System.exit(1);/*ww w .jav a 2 s.c o m*/ return; } ZookeeperLauncher launcher = new ZookeeperLauncher(argv[0]); long timeout = Long.parseLong(argv[1]); launcher.start(timeout, TimeUnit.SECONDS); }
From source file:cn.lhfei.spark.streaming.NginxlogSorterApp.java
public static void main(String[] args) { JavaSparkContext sc = null;/*from w w w . j a v a2 s .c o m*/ try { SparkConf conf = new SparkConf().setMaster("local").setAppName("NginxlogSorterApp"); sc = new JavaSparkContext(conf); JavaRDD<String> lines = sc.textFile(ORIGIN_PATH); JavaRDD<NginxLog> items = lines.map(new Function<String, NginxLog>() { private static final long serialVersionUID = -1530783780334450383L; @Override public NginxLog call(String v1) throws Exception { NginxLog item = new NginxLog(); String[] arrays = v1.split("[\\t]"); if (arrays.length == 3) { item.setIp(arrays[0]); item.setLiveTime(Long.parseLong(arrays[1])); item.setAgent(arrays[2]); } return item; } }); log.info("=================================Length: [{}]", items.count()); JavaPairRDD<String, Iterable<NginxLog>> keyMaps = items.groupBy(new Function<NginxLog, String>() { @Override public String call(NginxLog v1) throws Exception { return v1.getIp(); } }); log.info("=================================Group by Key Length: [{}]", keyMaps.count()); keyMaps.foreach(new VoidFunction<Tuple2<String, Iterable<NginxLog>>>() { @Override public void call(Tuple2<String, Iterable<NginxLog>> t) throws Exception { log.info("++++++++++++++++++++++++++++++++ key: {}", t._1); Iterator<NginxLog> ts = t._2().iterator(); while (ts.hasNext()) { log.info("=====================================[{}]", ts.next().toString()); } } }); FileUtils.deleteDirectory(new File(DESTI_PATH)); keyMaps.saveAsTextFile(DESTI_PATH); } catch (Exception e) { e.printStackTrace(); } finally { sc.close(); } }
From source file:ca.mcgill.networkdynamics.geoinference.evaluation.CrossValidationScorer.java
public static void main(String[] args) throws Exception { if (args.length != 4) { System.out.println("java CVS predictions-dir/ " + "cv-gold-dir/ results.txt error-sample.tsv"); return;// ww w.j a v a2 s . c o m } File predDir = new File(args[0]); File cvDir = new File(args[1]); TDoubleList errors = new TDoubleArrayList(10_000_000); TLongSet locatedUsers = new TLongHashSet(10_000_000); TLongSet allUsers = new TLongHashSet(10_000_000); TLongObjectMap<TDoubleList> userToErrors = new TLongObjectHashMap<TDoubleList>(); TLongDoubleMap tweetIdToError = new TLongDoubleHashMap(10_000_000); TLongObjectMap<double[]> idToPredLoc = new TLongObjectHashMap<double[]>(); int tweetsSeen = 0; int tweetsLocated = 0; BufferedReader cvBr = new BufferedReader(new FileReader(new File(cvDir, "folds.info.tsv"))); for (String foldLine = null; (foldLine = cvBr.readLine()) != null;) { String[] cols = foldLine.split("\t"); String foldName = cols[0]; System.out.printf("Scoring results for fold %s%n", foldName); File foldPredictionsFile = new File(predDir, foldName + ".results.tsv.gz"); File goldLocFile = new File(cvDir, foldName + ".gold-locations.tsv"); if (foldPredictionsFile.exists()) { BufferedReader br = Files.openGz(foldPredictionsFile); for (String line = null; (line = br.readLine()) != null;) { String[] arr = line.split("\t"); long id = Long.parseLong(arr[0]); idToPredLoc.put(id, new double[] { Double.parseDouble(arr[1]), Double.parseDouble(arr[2]) }); } br.close(); } System.out.printf("loaded predictions for %d tweets; " + "scoring predictions%n", idToPredLoc.size()); BufferedReader br = new BufferedReader(new FileReader(goldLocFile)); for (String line = null; (line = br.readLine()) != null;) { String[] arr = line.split("\t"); long id = Long.parseLong(arr[0]); long userId = Long.parseLong(arr[1]); allUsers.add(userId); tweetsSeen++; double[] predLoc = idToPredLoc.get(id); if (predLoc == null) continue; tweetsLocated++; locatedUsers.add(userId); double[] goldLoc = new double[] { Double.parseDouble(arr[2]), Double.parseDouble(arr[3]) }; double dist = Geometry.getDistance(predLoc, goldLoc); errors.add(dist); tweetIdToError.put(id, dist); TDoubleList userErrors = userToErrors.get(userId); if (userErrors == null) { userErrors = new TDoubleArrayList(); userToErrors.put(userId, userErrors); } userErrors.add(dist); } br.close(); } errors.sort(); System.out.println("Num errors to score: " + errors.size()); double auc = 0; double userCoverage = 0; double tweetCoverage = tweetsLocated / (double) tweetsSeen; double medianMaxUserError = Double.NaN; double medianMedianUserError = Double.NaN; if (errors.size() > 0) { auc = computeAuc(errors); userCoverage = locatedUsers.size() / ((double) allUsers.size()); TDoubleList maxUserErrors = new TDoubleArrayList(locatedUsers.size()); TDoubleList medianUserErrors = new TDoubleArrayList(locatedUsers.size()); for (TDoubleList userErrors : userToErrors.valueCollection()) { userErrors.sort(); maxUserErrors.add(userErrors.get(userErrors.size() - 1)); medianUserErrors.add(userErrors.get(userErrors.size() / 2)); } maxUserErrors.sort(); medianMaxUserError = maxUserErrors.get(maxUserErrors.size() / 2); medianUserErrors.sort(); medianMedianUserError = medianUserErrors.get(medianUserErrors.size() / 2); // Compute CDF int[] errorsPerKm = new int[MAX_KM]; for (int i = 0; i < errors.size(); ++i) { int error = (int) (Math.round(errors.get(i))); errorsPerKm[error]++; } // The accumulated sum of errors per km int[] errorsBelowEachKm = new int[errorsPerKm.length]; for (int i = 0; i < errorsBelowEachKm.length; ++i) { errorsBelowEachKm[i] = errorsPerKm[i]; if (i > 0) errorsBelowEachKm[i] += errorsBelowEachKm[i - 1]; } final double[] cdf = new double[errorsBelowEachKm.length]; double dSize = errors.size(); // to avoid casting all the time for (int i = 0; i < cdf.length; ++i) cdf[i] = errorsBelowEachKm[i] / dSize; } PrintWriter pw = new PrintWriter(new File(args[2])); pw.println("AUC\t" + auc); pw.println("user coverage\t" + userCoverage); pw.println("tweet coverage\t" + tweetCoverage); pw.println("median-max error\t" + medianMaxUserError); pw.close(); // Choose a random sampling of 10K tweets to pass on to the authors // here. PrintWriter errorsPw = new PrintWriter(args[3]); TLongList idsWithErrors = new TLongArrayList(tweetIdToError.keySet()); idsWithErrors.shuffle(new Random()); // Choose the first 10K for (int i = 0, chosen = 0; i < idsWithErrors.size() && chosen < 10_000; ++i) { long id = idsWithErrors.get(i); double[] prediction = idToPredLoc.get(id); double error = tweetIdToError.get(id); errorsPw.println(id + "\t" + error + "\t" + prediction[0] + "\t" + prediction[1]); ++chosen; } errorsPw.close(); }
From source file:com.kantenkugel.discordbot.Main.java
public static void main(String[] args) { boolean isDbBot = false; if (args.length == 2 && Boolean.parseBoolean(args[1])) { isDbBot = true;/*from w ww. ja va 2 s . co m*/ } else if (args.length < 4) { System.out.println("Missing arguments!"); return; } if (!BotConfig.load()) { System.out.println("Bot config created/updated. Please populate/check it before restarting the Bot"); System.exit(Statics.NORMAL_EXIT_CODE); } if (BotConfig.get("logToFiles", true)) { try { SimpleLog.addFileLogs(new File("logs/main.txt"), new File("logs/err.txt")); } catch (IOException e) { e.printStackTrace(); } } if (!isDbBot) { Statics.START_TIME = Long.parseLong(args[1]); Statics.VERSION = Integer.parseInt(args[3]); } if (!isDbBot && args.length > 4) { Statics.CHANGES = StringUtils.join(args, '\n', 4, args.length); } else { Statics.CHANGES = null; } if (isDbBot) { if ("".equals(BotConfig.get("historyBase"))) { Statics.LOG.fatal("Please specify a history-base in the config"); System.exit(Statics.NORMAL_EXIT_CODE); } if (!DbEngine.init()) { Statics.LOG.fatal("Could not connect to db! shutting down"); System.exit(Statics.NORMAL_EXIT_CODE); } } else { DocParser.init(); Module.init(); } try { JDABuilder jdaBuilder = new JDABuilder().setBotToken(args[0]).setAudioEnabled(false); if (isDbBot) jdaBuilder.addListener(new DbListener()); else jdaBuilder.addListener(new StatusListener()).addListener(new InviteListener()) .addListener(new MessageListener()); if (!isDbBot && !args[2].equals("-")) { boolean success = Boolean.parseBoolean(args[2]); if (success) { checker = UpdateValidator.getInstance(); checker.start(); } jdaBuilder.addListener(new UpdatePrintListener(success)); } Statics.jdaInstance = jdaBuilder.buildAsync(); if (!isDbBot) CommandRegistry.loadCommands(Statics.jdaInstance); new UpdateWatcher(Statics.jdaInstance); } catch (LoginException e) { Statics.LOG.fatal("Login informations were incorrect!"); System.err.flush(); } }