List of usage examples for java.util List add
boolean add(E e);
From source file:EnumSpy.java
public static void main(String... args) { try {//from w ww . j a v a2 s. co m Class<?> c = Class.forName(args[0]); if (!c.isEnum()) { out.format("%s is not an enum type%n", c); return; } out.format("Class: %s%n", c); Field[] flds = c.getDeclaredFields(); List<Field> cst = new ArrayList<Field>(); // enum constants List<Field> mbr = new ArrayList<Field>(); // member fields for (Field f : flds) { if (f.isEnumConstant()) cst.add(f); else mbr.add(f); } if (!cst.isEmpty()) print(cst, "Constant"); if (!mbr.isEmpty()) print(mbr, "Field"); Constructor[] ctors = c.getDeclaredConstructors(); for (Constructor ctor : ctors) { out.format(fmt, "Constructor", ctor.toGenericString(), synthetic(ctor)); } Method[] mths = c.getDeclaredMethods(); for (Method m : mths) { out.format(fmt, "Method", m.toGenericString(), synthetic(m)); } // production code should handle this exception more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { List<Task> tasks = new LinkedList<Task>(); String[] tasksLabels = new String[] { "A", "B", "C" }; Clock clock = new Clock(tasksLabels.length, new Counter()); for (String s : tasksLabels) { Task task = new Task(s, clock); tasks.add(task); task.start();//from w w w .j av a 2s . c o m } }
From source file:org.excalibur.benchmark.test.EC2InstancesBenchmark.java
public static void main(String[] args) throws IOException { final String benchmark = "sp"; final String outputDir = "/home/alessandro/excalibur/source/services/benchmarks/ec2/"; final String[] scripts = { readLines(getDefaultClassLoader() .getResourceAsStream("org/excalibur/service/deployment/resource/script/iperf3.sh")), readLines(getDefaultClassLoader() .getResourceAsStream("org/excalibur/service/deployment/resource/script/linkpack.sh")), readLines(getDefaultClassLoader().getResourceAsStream( "org/excalibur/service/deployment/resource/script/benchmarks/run_linpack_xeon64.sh")), }; final String[] instanceTypes = { "c3.8xlarge", "r3.large", "r3.xlarge", "r3.2xlarge", "i2.xlarge" }; final String privateKeyMaterial = IOUtils2 .readLines(new File(SystemUtils2.getUserDirectory(), "/.ec2/leite.pem")); final File sshKey = new File(SystemUtils2.getUserDirectory(), "/.ec2/leite.pem"); Properties properties = Properties2 .load(getDefaultClassLoader().getResourceAsStream("aws-config.properties")); final LoginCredentials loginCredentials = new LoginCredentials.Builder() .identity(properties.getProperty("aws.access.key")) .credential(properties.getProperty("aws.secret.key")).credentialName("leite").build(); final UserProviderCredentials userProviderCredentials = new UserProviderCredentials() .setLoginCredentials(loginCredentials) .setRegion(new Region("us-east-1").setEndpoint("https://ec2.us-east-1.amazonaws.com")); final EC2 ec2 = new EC2(userProviderCredentials); List<Callable<Void>> tasks = Lists.newArrayList(); for (final String instanceType : instanceTypes) { tasks.add(new Callable<Void>() { @Override//from ww w .jav a 2 s . co m public Void call() throws Exception { InstanceTemplate template = new InstanceTemplate().setImageId("ami-864d84ee") .setInstanceType(InstanceType.valueOf(instanceType)).setKeyName("leite") .setLoginCredentials( loginCredentials.toBuilder().privateKey(privateKeyMaterial).build()) .setGroup(new org.excalibur.core.cloud.api.Placement().setZone("us-east-1a")) //.setGroupName("iperf-bench") .setMinCount(1).setMaxCount(1) .setInstanceName(String.format("%s-%s", instanceType, benchmark)) .setRegion(userProviderCredentials.getRegion()).setTags(Tags .newTags(new org.excalibur.core.cloud.api.domain.Tag("benchmark", benchmark))); final Instances instances = ec2.createInstances(template); for (VirtualMachine instance : instances) { Preconditions.checkState( !Strings.isNullOrEmpty(instance.getConfiguration().getPlatformUserName())); Preconditions.checkState( !Strings.isNullOrEmpty(instance.getConfiguration().getPublicIpAddress())); HostAndPort hostAndPort = fromParts(instance.getConfiguration().getPublicIpAddress(), 22); LoginCredentials sshCredentials = new LoginCredentials.Builder().authenticateAsSudo(true) .privateKey(sshKey).user(instance.getConfiguration().getPlatformUserName()).build(); SshClient client = SshClientFactory.defaultSshClientFactory().create(hostAndPort, sshCredentials); client.connect(); try { for (int i = 0; i < scripts.length; i++) { ExecutableResponse response = client.execute(scripts[i]); Files.write(response.getOutput().getBytes(), new File(outputDir, String.format("%s-%s.output.txt", template.getInstanceName(), i))); LOG.info( "Executed the script [{}] with exit code [{}], error [{}], and output [{}] ", new Object[] { scripts[i], String.valueOf(response.getExitStatus()), response.getError(), response.getOutput() }); } } finally { client.disconnect(); } ec2.terminateInstance(instance); } return null; } }); } ListeningExecutorService executor = DynamicExecutors .newListeningDynamicScalingThreadPool("benchmark-instances-thread-%d"); Futures2.invokeAllAndShutdownWhenFinish(tasks, executor); ec2.close(); }
From source file:Main.java
public static void main(String[] args) { Integer[] intArray = { 1, 2, 3, 4, 5, 6, 7, 8 }; List<Integer> listOfIntegers = new ArrayList<>(Arrays.asList(intArray)); List<Integer> serialStorage = new ArrayList<>(); System.out.println("Serial stream:"); listOfIntegers.stream()//from ww w .j a va2 s .c o m // Don't do this! It uses a stateful lambda expression. .map(e -> { serialStorage.add(e); return e; }) .forEachOrdered(e -> System.out.print(e + " ")); System.out.println(""); serialStorage.stream().forEachOrdered(e -> System.out.print(e + " ")); System.out.println(""); System.out.println("Parallel stream:"); List<Integer> parallelStorage = Collections.synchronizedList(new ArrayList<>()); listOfIntegers.parallelStream() // Don't do this! It uses a stateful lambda expression. .map(e -> { parallelStorage.add(e); return e; }) .forEachOrdered(e -> System.out.print(e + " ")); System.out.println(""); parallelStorage.stream().forEachOrdered(e -> System.out.print(e + " ")); System.out.println(""); }
From source file:jmbench.plots.SummaryWhiskerPlot.java
public static void main(String args[]) { Random rand = new Random(2344); SummaryWhiskerPlot plot = new SummaryWhiskerPlot("Test Summary", "Weighted by Operation Time"); for (int i = 0; i < 3; i++) { List<Double> overall = new ArrayList<Double>(); List<Double> large = new ArrayList<Double>(); List<Double> small = new ArrayList<Double>(); for (int j = 0; j < 50; j++) { overall.add(rand.nextDouble()); large.add(rand.nextDouble()); small.add(rand.nextDouble()); }/* w w w . j a v a 2s. c o m*/ plot.addLibrary("Lib " + i, overall, large, small); } plot.displayWindow(600, 350); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step5bAgreementMeasures.java
@SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { String inputDir = args[0];// ww w . j av a 2 s.c o m // all annotations List<AnnotatedArgumentPair> allArgumentPairs = new ArrayList<>(); Collection<File> files = IOHelper.listXmlFiles(new File(inputDir)); for (File file : files) { allArgumentPairs.addAll((List<AnnotatedArgumentPair>) XStreamTools.getXStream().fromXML(file)); } // for collecting the rank of n-th best worker per HIT SortedMap<Integer, DescriptiveStatistics> nThWorkerOnHITRank = new TreeMap<>(); // confusion matrix wrt. gold data for each n-th best worker on HIT SortedMap<Integer, ConfusionMatrix> nThWorkerOnHITConfusionMatrix = new TreeMap<>(); // initialize maps for (int i = 0; i < TOP_K_VOTES; i++) { nThWorkerOnHITRank.put(i, new DescriptiveStatistics()); nThWorkerOnHITConfusionMatrix.put(i, new ConfusionMatrix()); } for (AnnotatedArgumentPair argumentPair : allArgumentPairs) { // sort turker rank and their vote SortedMap<Integer, String> rankAndVote = new TreeMap<>(); System.out.println(argumentPair.mTurkAssignments.size()); for (AnnotatedArgumentPair.MTurkAssignment assignment : argumentPair.mTurkAssignments) { rankAndVote.put(assignment.getTurkRank(), assignment.getValue()); } String goldLabel = argumentPair.getGoldLabel(); System.out.println(rankAndVote); // top K workers for the HIT List<String> topKVotes = new ArrayList<>(rankAndVote.values()).subList(0, TOP_K_VOTES); // rank of top K workers List<Integer> topKRanks = new ArrayList<>(rankAndVote.keySet()).subList(0, TOP_K_VOTES); System.out.println("Top K votes: " + topKVotes); System.out.println("Top K ranks: " + topKRanks); // extract only category (a1, a2, or equal) List<String> topKVotesOnlyCategory = new ArrayList<>(); for (String vote : topKVotes) { String category = vote.split("_")[2]; topKVotesOnlyCategory.add(category); } System.out.println("Top " + TOP_K_VOTES + " workers' decisions: " + topKVotesOnlyCategory); if (goldLabel == null) { System.out.println("No gold label estimate for " + argumentPair.getId()); } else { // update statistics for (int i = 0; i < TOP_K_VOTES; i++) { nThWorkerOnHITConfusionMatrix.get(i).increaseValue(goldLabel, topKVotesOnlyCategory.get(i)); // rank is +1 (we don't start ranking from zero) nThWorkerOnHITRank.get(i).addValue(topKRanks.get(i) + 1); } } } for (int i = 0; i < TOP_K_VOTES; i++) { System.out.println("n-th worker : " + (i + 1) + " -----------"); System.out.println(nThWorkerOnHITConfusionMatrix.get(i).printNiceResults()); System.out.println(nThWorkerOnHITConfusionMatrix.get(i)); System.out.println("Average rank: " + nThWorkerOnHITRank.get(i).getMean() + ", stddev " + nThWorkerOnHITRank.get(i).getStandardDeviation()); } }
From source file:net.cloudkit.relaxation.HttpClientTest.java
public static void main(String[] args) throws Exception { InetAddress[] addresss = InetAddress.getAllByName("google.com"); for (InetAddress address : addresss) { System.out.println(address); }//ww w .j a va 2 s . c o m CloseableHttpClient httpclient = HttpClients.createDefault(); String __VIEWSTATE = ""; String __EVENTVALIDATION = ""; HttpGet httpGet = new HttpGet("http://query.customs.gov.cn/MNFTQ/MRoadQuery.aspx?" + Math.random() * 1000); httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); httpGet.setHeader("Accept-Encoding", "gzip, deflate, sdch"); httpGet.setHeader("Accept-Language", "zh-CN,zh;q=0.8,en;q=0.6"); httpGet.setHeader("Cache-Control", "no-cache"); // httpGet.setHeader("Connection", "keep-alive"); httpGet.setHeader("Host", "query.customs.gov.cn"); httpGet.setHeader("Pragma", "no-cache"); httpGet.setHeader("Upgrade-Insecure-Requests", "1"); httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"); HttpClientContext context = HttpClientContext.create(); // CloseableHttpResponse response1 = httpclient.execute(httpGet, context); CloseableHttpResponse response1 = httpclient.execute(httpGet); // Header[] headers = response1.getHeaders(HttpHeaders.CONTENT_TYPE); // System.out.println("context cookies:" + context.getCookieStore().getCookies()); // String setCookie = response1.getFirstHeader("Set-Cookie").getValue(); // System.out.println("context cookies:" + setCookie); try { System.out.println(response1.getStatusLine()); HttpEntity entity1 = response1.getEntity(); // do something useful with the response body and ensure it is fully consumed String result = IOUtils.toString(entity1.getContent(), "GBK"); // System.out.println(result); Matcher m1 = Pattern.compile( "<input type=\\\"hidden\\\" name=\\\"__VIEWSTATE\\\" id=\\\"__VIEWSTATE\\\" value=\\\"(.*)\\\" />") .matcher(result); __VIEWSTATE = m1.find() ? m1.group(1) : ""; Matcher m2 = Pattern.compile( "<input type=\\\"hidden\\\" name=\\\"__EVENTVALIDATION\\\" id=\\\"__EVENTVALIDATION\\\" value=\\\"(.*)\\\" />") .matcher(result); __EVENTVALIDATION = m2.find() ? m2.group(1) : ""; System.out.println(__VIEWSTATE); System.out.println(__EVENTVALIDATION); /* File storeFile = new File("D:\\customs\\customs"+ i +".jpg"); FileOutputStream output = new FileOutputStream(storeFile); IOUtils.copy(input, output); output.close(); */ EntityUtils.consume(entity1); } finally { response1.close(); } HttpPost httpPost = new HttpPost( "http://query.customs.gov.cn/MNFTQ/MRoadQuery.aspx?" + Math.random() * 1000); httpPost.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); httpPost.setHeader("Accept-Encoding", "gzip, deflate"); httpPost.setHeader("Accept-Language", "zh-CN,zh;q=0.8,en;q=0.6"); httpPost.setHeader("Cache-Control", "no-cache"); // httpPost.setHeader("Connection", "keep-alive"); httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); httpPost.setHeader("Cookie", "ASP.NET_SessionId=t1td453hcuy4oqiplekkqe55"); httpPost.setHeader("Host", "query.customs.gov.cn"); httpPost.setHeader("Origin", "http://query.customs.gov.cn"); httpPost.setHeader("Pragma", "no-cache"); httpPost.setHeader("Referer", "http://query.customs.gov.cn/MNFTQ/MRoadQuery.aspx"); httpPost.setHeader("Upgrade-Insecure-Requests", "1"); httpPost.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("__VIEWSTATE", __VIEWSTATE)); nvps.add(new BasicNameValuePair("__EVENTVALIDATION", __EVENTVALIDATION)); nvps.add(new BasicNameValuePair("ScrollTop", "")); nvps.add(new BasicNameValuePair("__essVariable", "")); nvps.add(new BasicNameValuePair("MRoadQueryCtrl1$txtManifestID", "5100312462240")); nvps.add(new BasicNameValuePair("MRoadQueryCtrl1$txtBillNo", "7PH650021105")); nvps.add(new BasicNameValuePair("MRoadQueryCtrl1$txtCode", "a778")); nvps.add(new BasicNameValuePair("MRoadQueryCtrl1$btQuery", " ")); nvps.add(new BasicNameValuePair("select", "")); nvps.add(new BasicNameValuePair("select1", "")); nvps.add(new BasicNameValuePair("select2", "")); nvps.add(new BasicNameValuePair("select3", "")); nvps.add(new BasicNameValuePair("select4", "")); nvps.add(new BasicNameValuePair("select5", "??")); nvps.add(new BasicNameValuePair("select6", "")); nvps.add(new BasicNameValuePair("select7", "")); nvps.add(new BasicNameValuePair("select8", "")); httpPost.setEntity(new UrlEncodedFormEntity(nvps, "GBK")); CloseableHttpResponse response2 = httpclient.execute(httpPost); try { System.out.println(response2.getStatusLine()); HttpEntity entity2 = response2.getEntity(); // do something useful with the response body // and ensure it is fully consumed // System.out.println(entity2.getContent()); System.out.println(IOUtils.toString(response2.getEntity().getContent(), "GBK")); EntityUtils.consume(entity2); } finally { response2.close(); } }
From source file:com.lsq.httpclient.netpay.BasicInfo.java
public static void main(String[] args) throws Exception { // final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("F://test/pkcs8_rsa_private_key_2048.pem", "pem", null, "RSA"); // final PublicKey yhPubKey = CryptoUtil.getRSAPublicKeyByFileSuffix("F://??/rsa_public_key_2048.pem", "pem", "RSA"); ////from w w w .jav a 2 s. c om // final String url = "http://localhost:8080/interfaceWeb/basicInfo"; // final String url = "https://testapp.sicpay.com:11008/interfaceWeb/basicInfo"; //? // final String url = "http://120.31.132.120:8082/interfaceWeb/basicInfo"; // final PublicKey yhPubKey = CryptoUtil.getRSAPublicKeyByFileSuffix("C:\\document\\key\\000158120120\\GHT_ROOT.pem", "pem", "RSA"); // final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("C:\\document\\key\\000000153990021\\000000153990021.pem", "pem", null, "RSA"); // final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("C:/document/key/000000158120121/000000158120121.pem", "pem", null, "RSA"); // final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("D:/key/000000152110003.pem", "pem", null, "RSA"); // final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("D:/key/test_pkcs8_rsa_private_key_2048.pem", "pem", null, "RSA"); // PublicKey yhPubKey = TestUtil.getPublicKey(); // PrivateKey hzfPriKey = TestUtil.getPrivateKey(); // final String url = "http://epay.gaohuitong.com:8083/interfaceWeb/basicInfo"; // final String url = "http://gpay.gaohuitong.com:8086/interfaceWeb2/basicInfo"; // final PublicKey yhPubKey = CryptoUtil.getRSAPublicKeyByFileSuffix("C:/document/key/549440155510001/GHT_ROOT.pem", "pem", "RSA"); // final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("C:/document/key/549440155510001/549440155510001.pem", "pem", null, "RSA"); // final String url = "https://portal.sicpay.com:8087/interfaceWeb/basicInfo"; final String url = TestUtil.interface_url + "basicInfo"; final PublicKey yhPubKey = TestUtil.getPublicKey(); final PrivateKey hzfPriKey = TestUtil.getPrivateKey(); int i = 0; // int j = 0; while (i < 1) { i++; try { HttpClient4Util httpClient4Util = new HttpClient4Util(); StringBuilder sBuilder = new StringBuilder(); sBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); sBuilder.append("<merchant>"); sBuilder.append("<head>"); sBuilder.append("<version>2.0.0</version>"); // sBuilder.append("<agencyId>549440155510001</agencyId>"); sBuilder.append("<agencyId>" + TestUtil.merchantId + "</agencyId>"); sBuilder.append("<msgType>01</msgType>"); sBuilder.append("<tranCode>100001</tranCode>"); sBuilder.append("<reqMsgId>" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + i + i + "</reqMsgId>"); sBuilder.append("<reqDate>" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + "</reqDate>"); sBuilder.append("</head>"); sBuilder.append("<body>"); sBuilder.append("<handleType>0</handleType>"); sBuilder.append("<merchantName>LIBTEST1</merchantName>"); sBuilder.append("<shortName>UNCLE HENRY(A)</shortName>"); sBuilder.append("<city>344344</city>"); sBuilder.append( "<merchantAddress>UNIT C 15/FHUA CHIAO COMM CTR 678 NATHAN RD MONGKOK KL</merchantAddress>"); sBuilder.append("<servicePhone>13250538964</servicePhone>"); sBuilder.append("<orgCode></orgCode>"); sBuilder.append("<merchantType>01</merchantType>"); sBuilder.append("<category>5399</category>"); sBuilder.append("<corpmanName>?</corpmanName>"); sBuilder.append("<corpmanId>440103198112214218</corpmanId>"); sBuilder.append("<corpmanPhone>13926015921</corpmanPhone>"); sBuilder.append("<corpmanMobile>13926015921</corpmanMobile>"); sBuilder.append("<corpmanEmail>>zhanglibo@sicpay.com</corpmanEmail>"); sBuilder.append("<bankCode>105</bankCode>"); sBuilder.append("<bankName></bankName>"); sBuilder.append("<bankaccountNo>6250502002603958</bankaccountNo>"); sBuilder.append("<bankaccountName>?</bankaccountName>"); sBuilder.append("<autoCus>0</autoCus>"); sBuilder.append("<remark></remark>"); sBuilder.append("<licenseNo>91440184355798892G</licenseNo>"); // sBuilder.append("<taxRegisterNo></taxRegisterNo>"); // sBuilder.append("<subMerchantNo></subMerchantNo>"); // sBuilder.append("<inviteMerNo></inviteMerNo>"); // sBuilder.append("<county></county>"); // sBuilder.append("<appid>wx04df48e919ef7b28</appid>"); // sBuilder.append("<pid>2015062600009243</pid>"); // sBuilder.append("<childEnter>1</childEnter>"); // sBuilder.append("<ghtEnter>0</ghtEnter>"); // sBuilder.append("<addrType>BUSINESS_ADDRESS</addrType>"); // sBuilder.append("<contactType>LEGAL_PERSON</contactType>"); // sBuilder.append("<mcc>200101110640354</mcc>"); // sBuilder.append("<licenseType>NATIONAL_LEGAL_MERGE</licenseType>"); // sBuilder.append("<authPayDir>http://epay.gaohuitong.com/channel/|http://test.pengjv.com/channel/</authPayDir>"); // sBuilder.append("<scribeAppid>wx04df48e919ef7b28</scribeAppid>"); // sBuilder.append("<contactMan></contactMan>"); // sBuilder.append("<telNo>18675857506</telNo>"); // sBuilder.append("<mobilePhone>18675857506</mobilePhone>"); // sBuilder.append("<email>CSC@sicpay.com</email>"); // sBuilder.append("<licenseBeginDate>20150826</licenseBeginDate>"); // sBuilder.append("<licenseEndDate>20991231</licenseEndDate>"); // sBuilder.append("<licenseRange>?????????????</licenseRange>"); sBuilder.append("</body>"); sBuilder.append("</merchant>"); String plainXML = sBuilder.toString(); byte[] plainBytes = plainXML.getBytes("UTF-8"); String keyStr = "4D22R4846VFJ8HH4"; byte[] keyBytes = keyStr.getBytes("UTF-8"); byte[] base64EncryptDataBytes = Base64.encodeBase64( CryptoUtil.AESEncrypt(plainBytes, keyBytes, "AES", "AES/ECB/PKCS5Padding", null)); String encryptData = new String(base64EncryptDataBytes, "UTF-8"); byte[] base64SingDataBytes = Base64 .encodeBase64(CryptoUtil.digitalSign(plainBytes, hzfPriKey, "SHA1WithRSA")); String signData = new String(base64SingDataBytes, "UTF-8"); byte[] base64EncyrptKeyBytes = Base64 .encodeBase64(CryptoUtil.RSAEncrypt(keyBytes, yhPubKey, 2048, 11, "RSA/ECB/PKCS1Padding")); String encrtptKey = new String(base64EncyrptKeyBytes, "UTF-8"); List<NameValuePair> nvps = new LinkedList<NameValuePair>(); nvps.add(new BasicNameValuePair("encryptData", encryptData)); nvps.add(new BasicNameValuePair("encryptKey", encrtptKey)); // nvps.add(new BasicNameValuePair("agencyId", "549440155510001")); nvps.add(new BasicNameValuePair("agencyId", TestUtil.merchantId)); nvps.add(new BasicNameValuePair("signData", signData)); nvps.add(new BasicNameValuePair("tranCode", "100001")); // nvps.add(new BasicNameValuePair("callBack","http://localhost:801/callback/ghtBindCard.do")); // byte[] retBytes = httpClient4Util.doPost("http://localhost:8080/quickInter/channel/commonSyncInter.do", null, nvps, null); byte[] retBytes = httpClient4Util.doPost(url, null, nvps, null); // byte[] retBytes =httpClient4Util.doPost("http://epay.gaohuitong.com:8082/quickInter/channel/commonSyncInter.do", null, nvps, null); // byte[] retBytes = httpClient4Util.doPost("http://192.168.80.113:8080/quickInter/channel/commonSyncInter.do", null, nvps, null); String response = new String(retBytes, "UTF-8"); System.out.println(" ||" + new String(retBytes, "UTF-8") + "||"); TestEncype t = new TestEncype(); System.out.println(": ||" + t.respDecryption(response) + "||"); System.out.println("i" + i); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.jgoetsch.eventtrader.EventTraderSpringLauncher.java
public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: " + EventTraderSpringLauncher.class.getSimpleName() + " <files>..."); System.out.println(" files - List of paths to spring bean definition xml files."); System.out.println(" Each object defined that implements Runnable will be executed"); System.out.println(" in its own thread."); } else {//from ww w .j a v a2s . co m AbstractApplicationContext context = new ClassPathXmlApplicationContext(args); // auto register growl notifications after all GrowlNotification objects have been instantiated // if it is found on the classpath try { Class.forName("com.jgoetsch.eventtrader.processor.GrowlNotification").getMethod("autoRegister") .invoke(null); } catch (Exception e) { log.warn("Growl not found, cannot autoRegister notifications: {}", e.getMessage()); } Map<String, Runnable> runnables = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, Runnable.class); List<Thread> threads = new ArrayList<Thread>(runnables.size()); for (final Map.Entry<String, Runnable> runner : runnables.entrySet()) { final Thread th = new Thread(runner.getValue(), runner.getKey()); threads.add(th); th.start(); } // close spring context on JVM shutdown // this causes all @PreDestroy methods in the runnables to be called to allow for // them to shutdown gracefully context.registerShutdownHook(); // wait for launched threads to finish before cleaning up beans for (Thread th : threads) { try { th.join(); } catch (InterruptedException e) { } } } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.KyanosGraphCreator.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input file"); inputOpt.setArgs(1);//from w w w.ja v a2s . c o m inputOpt.setRequired(true); Option outputOpt = OptionBuilder.create(OUT); outputOpt.setArgName("OUTPUT"); outputOpt.setDescription("Output directory"); outputOpt.setArgs(1); outputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); Option optFileOpt = OptionBuilder.create(OPTIONS_FILE); optFileOpt.setArgName("FILE"); optFileOpt.setDescription("Properties file holding the options to be used in the Kyanos Resource"); optFileOpt.setArgs(1); options.addOption(inputOpt); options.addOption(outputOpt); options.addOption(inClassOpt); options.addOption(optFileOpt); CommandLineParser parser = new PosixParser(); try { PersistenceBackendFactoryRegistry.getFactories().put(NeoBlueprintsURI.NEO_GRAPH_SCHEME, new BlueprintsPersistenceBackendFactory()); CommandLine commandLine = parser.parse(options, args); URI sourceUri = URI.createFileURI(commandLine.getOptionValue(IN)); URI targetUri = NeoBlueprintsURI.createNeoGraphURI(new File(commandLine.getOptionValue(OUT))); Class<?> inClazz = KyanosGraphCreator.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("zxmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap() .put(NeoBlueprintsURI.NEO_GRAPH_SCHEME, PersistentResourceFactory.eINSTANCE); Resource sourceResource = resourceSet.createResource(sourceUri); Map<String, Object> loadOpts = new HashMap<String, Object>(); if ("zxmi".equals(sourceUri.fileExtension())) { loadOpts.put(XMIResource.OPTION_ZIP, Boolean.TRUE); } Runtime.getRuntime().gc(); long initialUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory before loading: {0}", MessageUtil.byteCountToDisplaySize(initialUsedMemory))); LOG.log(Level.INFO, "Loading source resource"); sourceResource.load(loadOpts); LOG.log(Level.INFO, "Source resource loaded"); Runtime.getRuntime().gc(); long finalUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory after loading: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory))); LOG.log(Level.INFO, MessageFormat.format("Memory use increase: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory))); Resource targetResource = resourceSet.createResource(targetUri); Map<String, Object> saveOpts = new HashMap<String, Object>(); if (commandLine.hasOption(OPTIONS_FILE)) { Properties properties = new Properties(); properties.load(new FileInputStream(new File(commandLine.getOptionValue(OPTIONS_FILE)))); for (final Entry<Object, Object> entry : properties.entrySet()) { saveOpts.put((String) entry.getKey(), (String) entry.getValue()); } } List<StoreOption> storeOptions = new ArrayList<StoreOption>(); storeOptions.add(BlueprintsResourceOptions.EStoreGraphOption.AUTOCOMMIT); saveOpts.put(BlueprintsResourceOptions.STORE_OPTIONS, storeOptions); targetResource.save(saveOpts); LOG.log(Level.INFO, "Start moving elements"); targetResource.getContents().clear(); targetResource.getContents().addAll(sourceResource.getContents()); LOG.log(Level.INFO, "End moving elements"); LOG.log(Level.INFO, "Start saving"); targetResource.save(saveOpts); LOG.log(Level.INFO, "Saved"); if (targetResource instanceof PersistentResourceImpl) { PersistentResourceImpl.shutdownWithoutUnload((PersistentResourceImpl) targetResource); } else { targetResource.unload(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }