List of usage examples for java.util List size
int size();
From source file:com.sm.test.TestFile.java
public static void main(String[] args) throws Exception { String[] opts = new String[] { "-filename", "-mapSize", "-range", "-listSize", "-times", "-url", "-store", }; String[] defaults = new String[] { "/Users/mhsieh/test/data/userCrm", "5", "4", "2", "100", "las1-crmp001:6172", "userCrm" }; String[] paras = getOpts(args, opts, defaults); String filename = paras[0];/* w ww . java 2 s . c o m*/ short mapSize = Short.valueOf(paras[1]); int range = Integer.valueOf(paras[2]); int listSize = Integer.valueOf(paras[3]); int times = Integer.valueOf(paras[4]); String url = paras[5]; String store = paras[6]; TestFile testFile = new TestFile(mapSize, range, listSize); ClusterClientFactory ccf = ClusterClientFactory.connect(url, store); ClusterClient client = ccf.getDefaultStore(); StoreIterator storeIterator = new StoreIterator(filename); int i = 0; while (storeIterator.hasNext()) { // Pair<Key, byte[]> pair = storeIterator.next(); // short c1 = testFile.getPartitionIndex( pair.getFirst()).getFirst(); // short c2 = testFile.finePartition( pair.getFirst()); // if ( c1 != c2) { // logger.info( "mismatch i "+i + " c1 "+c1 + " c2 "+c2+ " "+ toStr( (byte[]) pair.getFirst().getKey() )+ " "+pair.getFirst().hashCode() ); // } List<Key> list = getKeyList(storeIterator, 1000); List<KeyValue> keyValues = client.multiGets(list); int ma = match(keyValues); if (ma != list.size()) { logger.info("expect " + list.size() + " get " + ma); } i++; if (i > times) break; } logger.info("close file " + filename); storeIterator.close(); }
From source file:net.jcreate.home.dict.DictService.java
public static void main(String[] args) { DictService service = DictService.getInstance(); DictItem dictItem1 = new DictItem(); dictItem1.setOid(KeyGenerator.getKey()); dictItem1.setDictOID("e34028818317d572f80117d573bf4b0003"); dictItem1.setDictItemCode("a"); dictItem1.setDictItemName("dddddddddddddd"); try {/* w ww.j av a 2s. c o m*/ service.test(dictItem1); } catch (BusinessException e) { // TODO Auto-generated catch block e.printStackTrace(); } List dictItems = null; try { dictItems = service.getDictItems("vv"); } catch (BusinessException e1) { e1.printStackTrace(); } for (int i = 0; i < dictItems.size(); i++) { DictItem dictItem = (DictItem) dictItems.get(i); System.out.println(dictItem); } }
From source file:jdbc.ClientFormLogin.java
public static void main(String[] args) throws Exception { BasicCookieStore cookieStore = new BasicCookieStore(); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build(); java.net.CookieManager cm = new java.net.CookieManager(); java.net.CookieHandler.setDefault(cm); try {/*from ww w. j a va 2s. c o m*/ HttpGet httpget = new HttpGet("http://www.cophieu68.vn/export/excel.php?id=AAA"); CloseableHttpResponse response1 = httpclient.execute(httpget); try { HttpEntity entity = response1.getEntity(); System.out.println("Login form get: " + response1.getStatusLine()); EntityUtils.consume(entity); System.out.println("Initial set of cookies:"); List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } finally { response1.close(); } HttpUriRequest login = RequestBuilder.post() .setUri(new URI("http://www.cophieu68.vn/export/excel.php?id=AAA")) .addParameter("username", "hello_nguyenson@live.com").addParameter("tpassword", "19931994") .build(); CloseableHttpResponse response2 = httpclient.execute(login); try { HttpEntity entity = response2.getEntity(); System.out.println("Login form get: " + response2.getStatusLine()); EntityUtils.consume(entity); System.out.println("Post logon cookies:"); List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } finally { response2.close(); } } finally { httpclient.close(); } }
From source file:com.github.fge.jsonschema.main.cli.Main.java
public static void main(final String... args) throws IOException, ProcessingException { final OptionParser parser = new OptionParser(); parser.accepts("help", "show this help").forHelp(); parser.acceptsAll(Arrays.asList("s", "brief"), "only show validation status (OK/NOT OK)"); parser.acceptsAll(Arrays.asList("q", "quiet"), "no output; exit with the relevant return code (see below)"); parser.accepts("syntax", "check the syntax of schema(s) given as argument(s)"); parser.accepts("fakeroot", "pretend that the current directory is absolute URI \"uri\"").withRequiredArg(); parser.formatHelpWith(HELP);// w w w. java 2 s . c om final OptionSet optionSet; final boolean isSyntax; final int requiredArgs; Reporter reporter = Reporters.DEFAULT; String fakeRoot = null; try { optionSet = parser.parse(args); } catch (OptionException e) { System.err.println("unrecognized option(s): " + CustomHelpFormatter.OPTIONS_JOINER.join(e.options())); parser.printHelpOn(System.err); System.exit(CMD_ERROR.get()); throw new IllegalStateException("WTF??"); } if (optionSet.has("help")) { parser.printHelpOn(System.out); System.exit(ALL_OK.get()); } if (optionSet.has("s") && optionSet.has("q")) { System.err.println("cannot specify both \"--brief\" and " + "\"--quiet\""); parser.printHelpOn(System.err); System.exit(CMD_ERROR.get()); } if (optionSet.has("fakeroot")) fakeRoot = (String) optionSet.valueOf("fakeroot"); isSyntax = optionSet.has("syntax"); requiredArgs = isSyntax ? 1 : 2; @SuppressWarnings("unchecked") final List<String> arguments = (List<String>) optionSet.nonOptionArguments(); if (arguments.size() < requiredArgs) { System.err.println("missing arguments"); parser.printHelpOn(System.err); System.exit(CMD_ERROR.get()); } final List<File> files = Lists.newArrayList(); for (final String target : arguments) files.add(new File(target).getCanonicalFile()); if (optionSet.has("brief")) reporter = Reporters.BRIEF; else if (optionSet.has("quiet")) { System.out.close(); System.err.close(); reporter = Reporters.QUIET; } new Main(fakeRoot).proceed(reporter, files, isSyntax); }
From source file:com.github.stagirs.lingvo.build.SyntaxStatisticsBuilder.java
public static void main(String[] args) throws Exception { TObjectIntHashMap<String> map = new TObjectIntHashMap<String>(); for (String line : FileUtils.readLines(new File("annot.opcorpora.no_ambig.plain"), "utf-8")) { List<String> types = types(Annotation.parse(line)); if (types.isEmpty()) { continue; }/* w w w. j a v a 2s .c o m*/ map.adjustOrPutValue(types.get(0), 1, 1); map.adjustOrPutValue(" " + types.get(0), 1, 1); for (int i = 1; i < types.size(); i++) { map.adjustOrPutValue(types.get(i), 1, 1); map.adjustOrPutValue(types.get(i - 1) + " " + types.get(i), 1, 1); } map.adjustOrPutValue(types.get(types.size() - 1) + " ", 1, 1); } final List<String> result = new ArrayList<String>(); map.forEachEntry(new TObjectIntProcedure<String>() { @Override public boolean execute(String key, int count) { result.add(key + "\t" + count); return true; } }); FileUtils.writeLines(new File("src/main/resources/SyntaxStatistics"), "utf-8", result); }
From source file:httpclient.client.ClientFormLogin.java
public static void main(String[] args) throws Exception { // prepare parameters HttpParams params = new BasicHttpParams(); HttpProtocolParams.setUserAgent(params, Constants.BROWSER_TYPE); HttpProtocolParams.setUseExpectContinue(params, true); DefaultHttpClient httpclient = new DefaultHttpClient(params); String loginURL = "http://10.1.1.251/login.asp"; HttpGet httpget = new HttpGet(loginURL); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent();/*from ww w . ja v a 2s . co m*/ } System.out.println("Initial set of cookies:"); List<Cookie> cookies = httpclient.getCookieStore().getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } HttpPost httpost = new HttpPost(loginURL); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("name", "fangdj")); nvps.add(new BasicNameValuePair("passwd", "1111")); httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); response = httpclient.execute(httpost); entity = response.getEntity(); for (Header h : response.getAllHeaders()) { System.out.println(h); } System.out.println("Login form get: " + response.getStatusLine()); if (entity != null) { entity.consumeContent(); } System.out.println("Post logon cookies:"); cookies = httpclient.getCookieStore().getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } String mainURL = "http://10.1.1.251/ONWork/Record_save.asp"; HttpPost mainHttPost = new HttpPost(mainURL); List<NameValuePair> mainNvps = new ArrayList<NameValuePair>(); mainNvps.add(new BasicNameValuePair("EMP_NO", "13028")); mainNvps.add(new BasicNameValuePair("pwd", "1111")); mainNvps.add(new BasicNameValuePair("cmd2", "Apply")); httpost.setEntity(new UrlEncodedFormEntity(mainNvps, HTTP.UTF_8)); response = httpclient.execute(mainHttPost); System.out.println(Tools.InputStreamToString(response.getEntity().getContent())); // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); }
From source file:com.genentech.struchk.sdfNormalizer.java
public static void main(String[] args) { long start = System.currentTimeMillis(); int nMessages = 0; int nErrors = 0; int nStruct = 0; // create command line Options object Options options = new Options(); Option opt = new Option("in", true, "input file [.ism,.sdf,...]"); opt.setRequired(true);//from w w w . ja v a 2 s . c o m options.addOption(opt); opt = new Option("out", true, "output file"); opt.setRequired(true); options.addOption(opt); opt = new Option("mol", true, "molFile used for output: ORIGINAL(def)|NORMALIZED|TAUTOMERIC"); opt.setRequired(false); options.addOption(opt); opt = new Option("shortMessage", false, "Limit message to first 80 characters to conform with sdf file specs."); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { exitWithHelp(options, e.getMessage()); throw new Error(e); // avoid compiler errors } args = cmd.getArgs(); if (args.length != 0) { System.err.print("Unknown options: " + args + "\n\n"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("sdfNormalizer", options); System.exit(1); } String molOpt = cmd.getOptionValue("mol"); OUTMolFormat outMol = OUTMolFormat.ORIGINAL; if (molOpt == null || "original".equalsIgnoreCase(molOpt)) outMol = OUTMolFormat.ORIGINAL; else if ("NORMALIZED".equalsIgnoreCase(molOpt)) outMol = OUTMolFormat.NORMALIZED; else if ("TAUTOMERIC".equalsIgnoreCase(molOpt)) outMol = OUTMolFormat.TAUTOMERIC; else { System.err.printf("Unkown option for -mol: %s\n", molOpt); System.exit(1); } String inFile = cmd.getOptionValue("in"); String outFile = cmd.getOptionValue("out"); boolean limitMessage = cmd.hasOption("shortMessage"); try { oemolistream ifs = new oemolistream(inFile); oemolostream ofs = new oemolostream(outFile); URL cFile = OEStruchk.getResourceURL(OEStruchk.class, "Struchk.xml"); // create OEStruchk from config file OEStruchk strchk = new OEStruchk(cFile, CHECKConfig.ASSIGNStructFlag, false); OEGraphMol mol = new OEGraphMol(); StringBuilder sb = new StringBuilder(2000); while (oechem.OEReadMolecule(ifs, mol)) { if (!strchk.applyRules(mol, null)) nErrors++; switch (outMol) { case NORMALIZED: mol.Clear(); oechem.OEAddMols(mol, strchk.getTransformedMol("parent")); break; case TAUTOMERIC: mol.Clear(); oechem.OEAddMols(mol, strchk.getTransformedMol(null)); break; case ORIGINAL: break; } oechem.OESetSDData(mol, "CTISMILES", strchk.getTransformedIsoSmiles(null)); oechem.OESetSDData(mol, "CTSMILES", strchk.getTransformedSmiles(null)); oechem.OESetSDData(mol, "CISMILES", strchk.getTransformedIsoSmiles("parent")); oechem.OESetSDData(mol, "Strutct_Flag", strchk.getStructureFlag().getName()); List<Message> msgs = strchk.getStructureMessages(null); nMessages += msgs.size(); for (Message msg : msgs) sb.append(String.format("\t%s:%s", msg.getLevel(), msg.getText())); if (limitMessage) sb.setLength(Math.min(sb.length(), 80)); oechem.OESetSDData(mol, "NORM_MESSAGE", sb.toString()); oechem.OEWriteMolecule(ofs, mol); sb.setLength(0); nStruct++; } strchk.delete(); mol.delete(); ifs.close(); ifs.delete(); ofs.close(); ofs.delete(); } catch (Exception e) { throw new Error(e); } finally { System.err.printf("sdfNormalizer: Checked %d structures %d errors, %d messages in %dsec\n", nStruct, nErrors, nMessages, (System.currentTimeMillis() - start) / 1000); } }
From source file:AmazonKinesisList.java
public static void main(String[] args) throws Exception { init();// www .ja va 2s . com final String myStreamName = "anotestBstream"; final Integer myStreamSize = 1; // Create a stream. The number of shards determines the provisioned throughput. // CreateStreamRequest createStreamRequest = new CreateStreamRequest(); // createStreamRequest.setStreamName(myStreamName); // createStreamRequest.setShardCount(myStreamSize); // pt // kinesisClient.createStream(createStreamRequest); // The stream is now being created. // LOG.info("Creating Stream : " + myStreamName); // waitForStreamToBecomeAvailable(myStreamName); // list all of my streams ListStreamsRequest listStreamsRequest = new ListStreamsRequest(); listStreamsRequest.setLimit(10); ListStreamsResult listStreamsResult = kinesisClient.listStreams(listStreamsRequest); List<String> streamNames = listStreamsResult.getStreamNames(); while (listStreamsResult.isHasMoreStreams()) { if (streamNames.size() > 0) { listStreamsRequest.setExclusiveStartStreamName(streamNames.get(streamNames.size() - 1)); } listStreamsResult = kinesisClient.listStreams(listStreamsRequest); streamNames.addAll(listStreamsResult.getStreamNames()); } LOG.info("Printing my list of streams : "); // print all of my streams. if (!streamNames.isEmpty()) { System.out.println("List of my streams: "); } for (int i = 0; i < streamNames.size(); i++) { System.out.println(streamNames.get(i)); } /* LOG.info("Putting records in stream : " + myStreamName); // Write 10 records to the stream for (int j = 0; j < 10; j++) { PutRecordRequest putRecordRequest = new PutRecordRequest(); putRecordRequest.setStreamName(myStreamName); putRecordRequest.setData(ByteBuffer.wrap(String.format("testData-%d", j).getBytes())); putRecordRequest.setPartitionKey(String.format("partitionKey-%d", j)); PutRecordResult putRecordResult = kinesisClient.putRecord(putRecordRequest); System.out.println("Successfully putrecord, partition key : " + putRecordRequest.getPartitionKey() + ", ShardID : " + putRecordResult.getShardId()); } */ // Delete the stream. /* LOG.info("Deleting stream : " + myStreamName); DeleteStreamRequest deleteStreamRequest = new DeleteStreamRequest(); deleteStreamRequest.setStreamName(myStreamName); kinesisClient.deleteStream(deleteStreamRequest); // The stream is now being deleted. LOG.info("Stream is now being deleted : " + myStreamName); LOG.info("Streaming completed" + myStreamName); */ }
From source file:org.mitre.mpf.rest.client.Main.java
public static void main(String[] args) throws RestClientException, IOException, InterruptedException { System.out.println("Starting rest-client!"); //not necessary for localhost, but left if a proxy configuration is needed //System.setProperty("http.proxyHost",""); //System.setProperty("http.proxyPort",""); String currentDirectory;/*from w ww .j a v a 2 s.co m*/ currentDirectory = System.getProperty("user.dir"); System.out.println("Current working directory : " + currentDirectory); String username = "mpf"; String password = "mpf123"; byte[] encodedBytes = Base64.encodeBase64((username + ":" + password).getBytes()); String base64 = new String(encodedBytes); System.out.println("encodedBytes " + base64); final String mpfAuth = "Basic " + base64; RequestInterceptor authorize = new RequestInterceptor() { @Override public void intercept(HttpRequestBase request) { request.addHeader("Authorization", mpfAuth /*credentials*/); } }; //RestClient client = RestClient.builder().requestInterceptor(authorize).build(); CustomRestClient client = (CustomRestClient) CustomRestClient.builder() .restClientClass(CustomRestClient.class).requestInterceptor(authorize).build(); //getAvailableWorkPipelineNames String url = "http://localhost:8080/workflow-manager/rest/pipelines"; Map<String, String> params = new HashMap<String, String>(); List<String> availableWorkPipelines = client.get(url, params, new TypeReference<List<String>>() { }); System.out.println("availableWorkPipelines size: " + availableWorkPipelines.size()); System.out.println(Arrays.toString(availableWorkPipelines.toArray())); //processMedia JobCreationRequest jobCreationRequest = new JobCreationRequest(); URI uri = Paths.get(currentDirectory, "/trunk/workflow-manager/src/test/resources/samples/meds/aa/S001-01-t10_01.jpg").toUri(); jobCreationRequest.getMedia().add(new JobCreationMediaData(uri.toString())); uri = Paths.get(currentDirectory, "/trunk/workflow-manager/src/test/resources/samples/meds/aa/S008-01-t10_01.jpg").toUri(); jobCreationRequest.getMedia().add(new JobCreationMediaData(uri.toString())); jobCreationRequest.setExternalId("external id"); //get first DLIB pipeline String firstDlibPipeline = availableWorkPipelines.stream() //.peek(pipepline -> System.out.println("will filter - " + pipepline)) .filter(pipepline -> pipepline.startsWith("DLIB")).findFirst().get(); System.out.println("found firstDlibPipeline: " + firstDlibPipeline); jobCreationRequest.setPipelineName(firstDlibPipeline); //grabbed from 'rest/pipelines' - see #1 //two optional params jobCreationRequest.setBuildOutput(true); //jobCreationRequest.setPriority(priority); //will be set to 4 (default) if not set JobCreationResponse jobCreationResponse = client.customPostObject( "http://localhost:8080/workflow-manager/rest/jobs", jobCreationRequest, JobCreationResponse.class); System.out.println("jobCreationResponse job id: " + jobCreationResponse.getJobId()); System.out.println("\n---Sleeping for 10 seconds to let the job process---\n"); Thread.sleep(10000); //getJobStatus url = "http://localhost:8080/workflow-manager/rest/jobs"; // /status"; params = new HashMap<String, String>(); //OPTIONAL //params.put("v", "") - no versioning currently implemented //id is now a path var - if not set, all job info will returned url = url + "/" + Long.toString(jobCreationResponse.getJobId()); SingleJobInfo jobInfo = client.get(url, params, SingleJobInfo.class); System.out.println("jobInfo id: " + jobInfo.getJobId()); //getSerializedOutput String jobIdToGetOutputStr = Long.toString(jobCreationResponse.getJobId()); url = "http://localhost:8080/workflow-manager/rest/jobs/" + jobIdToGetOutputStr + "/output/detection"; params = new HashMap<String, String>(); //REQUIRED - job id is now a path var and required for this endpoint String serializedOutput = client.getAsString(url, params); System.out.println("serializedOutput: " + serializedOutput); }
From source file:com.mirth.connect.cli.launcher.CommandLineLauncher.java
public static void main(String[] args) { System.setProperty("log4j.configuration", "log4j-cli.properties"); logger = Logger.getLogger(CommandLineLauncher.class); try {//w w w . ja v a2s . c o m ManifestFile mirthCliJar = new ManifestFile("cli-lib/mirth-cli.jar"); ManifestFile mirthClientCoreJar = new ManifestFile("cli-lib/mirth-client-core.jar"); ManifestDirectory cliLibDir = new ManifestDirectory("cli-lib"); cliLibDir.setExcludes(new String[] { "mirth-client-core.jar" }); ManifestEntry[] manifest = new ManifestEntry[] { mirthCliJar, mirthClientCoreJar, cliLibDir }; List<URL> classpathUrls = new ArrayList<URL>(); addManifestToClasspath(manifest, classpathUrls); addSharedLibsToClasspath(classpathUrls); URLClassLoader classLoader = new URLClassLoader(classpathUrls.toArray(new URL[classpathUrls.size()])); Class<?> cliClass = classLoader.loadClass("com.mirth.connect.cli.CommandLineInterface"); Constructor<?>[] constructors = cliClass.getDeclaredConstructors(); for (int i = 0; i < constructors.length; i++) { Class<?> parameters[] = constructors[i].getParameterTypes(); if (parameters.length == 1) { constructors[i].newInstance(new Object[] { args }); i = constructors.length; } } } catch (Exception e) { e.printStackTrace(); } }