List of usage examples for java.io IOException printStackTrace
public void 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); }//w w w . java 2s .c om 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:examples.rexec.java
public static final void main(String[] args) { String server, username, password, command; RExecClient client;//from w ww. j a va 2s. c o m if (args.length != 4) { System.err.println("Usage: rexec <hostname> <username> <password> <command>"); System.exit(1); return; // so compiler can do proper flow control analysis } client = new RExecClient(); server = args[0]; username = args[1]; password = args[2]; command = args[3]; try { client.connect(server); } catch (IOException e) { System.err.println("Could not connect to server."); e.printStackTrace(); System.exit(1); } try { client.rexec(username, password, command); } catch (IOException e) { try { client.disconnect(); } catch (IOException f) { } e.printStackTrace(); System.err.println("Could not execute command."); System.exit(1); } IOUtil.readWrite(client.getInputStream(), client.getOutputStream(), System.in, System.out); try { client.disconnect(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.exit(0); }
From source file:com.cisco.dbds.utils.git.FileUtilities.java
/** * local main.//from w ww .java 2 s . c o m * * @param args the arguments */ public static void main(String[] args) { FileUtilities fileChecker = new FileUtilities(); try { System.out.println(fileChecker.getGitRootDir() + "/src" + "/" + "it" + "/" + "resources"); System.out.println( fileChecker.getFiles(fileChecker.getGitRootDir() + "/src" + "/" + "it" + "/" + "resources")); } catch (IOException e) { e.printStackTrace(); } }
From source file:ke.co.tawi.babblesms.server.utils.randomgenerate.IncomingLogGenerator.java
/** * @param args// w w w.j a va 2s . c o m */ public static void main(String[] args) { System.out.println("Have started IncomingSMSGenerator."); File outFile = new File("/tmp/logs/incomingSMS.csv"); RandomDataGenerator randomDataImpl = new RandomDataGenerator(); String randomStrFile = "/tmp/random.txt"; List<String> randomStrings = new ArrayList<>(); int randStrLength = 0; long startDate = 1412380800; // Unix time in seconds for Oct 4 2014 long stopDate = 1420070340; // Unix time for in seconds Dec 31 2014 SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 2011-06-01 00:16:45" List<String> shortcodeUuids = new ArrayList<>(); shortcodeUuids.add("094def52-bc18-4a9e-9b84-c34cc6476c75"); shortcodeUuids.add("e9570c5d-0cc4-41e5-81df-b0674e9dda1e"); shortcodeUuids.add("a118c8ea-f831-4288-986d-35e22c91fc4d"); shortcodeUuids.add("a2688d72-291b-470c-8926-31a903f5ed0c"); shortcodeUuids.add("9bef62f6-e682-4efd-98e9-ca41fa4ef993"); int shortcodeCount = shortcodeUuids.size() - 1; try { randomStrings = FileUtils.readLines(new File(randomStrFile)); randStrLength = randomStrings.size(); for (int j = 0; j < 30000; j++) { FileUtils.write(outFile, // shortcodeUuids.get(randomDataImpl.nextInt(0, shortcodeCount)) + "|" // Destination UUID.randomUUID().toString() + "|" // Unique Code + randomDataImpl.nextLong(new Long("254700000000").longValue(), new Long("254734999999").longValue()) + "|" // Origin + shortcodeUuids.get(randomDataImpl.nextInt(0, shortcodeCount)) + "|" + randomStrings.get(randomDataImpl.nextInt(0, randStrLength - 1)) + "|" // Message + "N|" // deleted + dateFormatter.format( new Date(randomDataImpl.nextLong(startDate, stopDate) * 1000)) + "\n", // smsTime true); // Append to file } } catch (IOException e) { System.err.println("IOException in main."); e.printStackTrace(); } System.out.println("Have finished IncomingSMSGenerator."); }
From source file:niclients.main.regni.java
public static void main(String[] args) throws UnsupportedEncodingException { HttpClient client = new DefaultHttpClient(); if (commandparser(args)) { if (createpub()) { try { HttpResponse response = client.execute(post); int resp_code = response.getStatusLine().getStatusCode(); System.err.println("RESP_CODE: " + Integer.toString(resp_code)); BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); }//from w ww. ja v a 2 s . c om } catch (IOException e) { e.printStackTrace(); } } else { System.err.println("Publish creation failed!"); } } else { System.err.println("Command line parsing failed!"); } }
From source file:examples.unix.rexec.java
public static void main(String[] args) { String server, username, password, command; RExecClient client;// ww w . j a v a2s.c o m if (args.length != 4) { System.err.println("Usage: rexec <hostname> <username> <password> <command>"); System.exit(1); return; // so compiler can do proper flow control analysis } client = new RExecClient(); server = args[0]; username = args[1]; password = args[2]; command = args[3]; try { client.connect(server); } catch (IOException e) { System.err.println("Could not connect to server."); e.printStackTrace(); System.exit(1); } try { client.rexec(username, password, command); } catch (IOException e) { try { client.disconnect(); } catch (IOException f) { } e.printStackTrace(); System.err.println("Could not execute command."); System.exit(1); } IOUtil.readWrite(client.getInputStream(), client.getOutputStream(), System.in, System.out); try { client.disconnect(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.exit(0); }
From source file:examples.rshell.java
public static final void main(String[] args) { String server, localuser, remoteuser, command; RCommandClient client;/*w w w. ja va 2 s .co m*/ if (args.length != 4) { System.err.println("Usage: rshell <hostname> <localuser> <remoteuser> <command>"); System.exit(1); return; // so compiler can do proper flow control analysis } client = new RCommandClient(); server = args[0]; localuser = args[1]; remoteuser = args[2]; command = args[3]; try { client.connect(server); } catch (IOException e) { System.err.println("Could not connect to server."); e.printStackTrace(); System.exit(1); } try { client.rcommand(localuser, remoteuser, command); } catch (IOException e) { try { client.disconnect(); } catch (IOException f) { } e.printStackTrace(); System.err.println("Could not execute command."); System.exit(1); } IOUtil.readWrite(client.getInputStream(), client.getOutputStream(), System.in, System.out); try { client.disconnect(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.exit(0); }
From source file:org.bimserver.build.CreateGitHubRelease.java
public static void main(String[] args) { String username = args[0];/*from www .j av a 2s. co m*/ String password = args[1]; String repo = args[2]; String project = args[3]; String tagname = args[4]; String name = args[5]; String body = args[6]; String draft = args[7]; String prerelease = args[8]; String filesString = args[9]; String[] filenames = filesString.split(";"); GitHubClient gitHubClient = new GitHubClient("api.github.com"); gitHubClient.setCredentials(username, password); Map<String, String> map = new HashMap<String, String>(); map.put("tag_name", tagname); // map.put("target_commitish", "test"); map.put("name", name); map.put("body", body); // map.put("draft", draft); // map.put("prerelease", prerelease); try { String string = "/repos/" + repo + "/" + project + "/releases"; System.out.println(string); JsonObject gitHubResponse = gitHubClient.post(string, map, JsonObject.class); System.out.println(gitHubResponse); String id = gitHubResponse.get("id").getAsString(); HttpHost httpHost = new HttpHost("uploads.github.com", 443, "https"); BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider(); basicCredentialsProvider.setCredentials(new AuthScope(httpHost), new UsernamePasswordCredentials(username, password)); HostnameVerifier hostnameVerifier = new AllowAllHostnameVerifier(); SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build()); CloseableHttpClient client = HttpClients.custom() .setDefaultCredentialsProvider(basicCredentialsProvider) .setHostnameVerifier((X509HostnameVerifier) hostnameVerifier).setSSLSocketFactory(sslsf) .build(); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(httpHost, basicAuth); HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(basicCredentialsProvider); context.setAuthCache(authCache); for (String filename : filenames) { File file = new File(filename); String url = "https://uploads.github.com/repos/" + repo + "/" + project + "/releases/" + id + "/assets?name=" + file.getName(); HttpPost post = new HttpPost(url); post.setHeader("Accept", "application/vnd.github.manifold-preview"); post.setHeader("Content-Type", "application/zip"); post.setEntity(new InputStreamEntity(new FileInputStream(file), file.length())); HttpResponse execute = client.execute(httpHost, post, context); execute.getEntity().getContent().close(); } } catch (IOException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } }
From source file:net.semanticmetadata.lire.solr.AddImages.java
public static void main(String[] args) throws IOException, InterruptedException { BitSampling.readHashFunctions();/*from ww w . j av a2s .co m*/ LinkedList<Thread> threads = new LinkedList<Thread>(); for (int j = 10; j < 21; j++) { final int tz = j; Thread t = new Thread() { @Override public void run() { try { List<File> files = FileUtils .getAllImageFiles(new File("D:\\DataSets\\WIPO-US\\jpg_us_trim\\" + tz), true); int count = 0; BufferedWriter br = new BufferedWriter(new FileWriter("add-us-" + tz + ".xml", false)); br.write("<add>\n"); for (Iterator<File> iterator = files.iterator(); iterator.hasNext();) { File file = iterator.next(); br.write(createAddDoc(file).toString()); count++; // if (count % 1000 == 0) System.out.print('.'); } br.write("</add>\n"); br.close(); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } }; t.start(); threads.add(t); } for (Iterator<Thread> iterator = threads.iterator(); iterator.hasNext();) { Thread next = iterator.next(); next.join(); } }
From source file:examples.unix.rshell.java
public static void main(String[] args) { String server, localuser, remoteuser, command; RCommandClient client;/*from w w w . ja va 2 s . c om*/ if (args.length != 4) { System.err.println("Usage: rshell <hostname> <localuser> <remoteuser> <command>"); System.exit(1); return; // so compiler can do proper flow control analysis } client = new RCommandClient(); server = args[0]; localuser = args[1]; remoteuser = args[2]; command = args[3]; try { client.connect(server); } catch (IOException e) { System.err.println("Could not connect to server."); e.printStackTrace(); System.exit(1); } try { client.rcommand(localuser, remoteuser, command); } catch (IOException e) { try { client.disconnect(); } catch (IOException f) { } e.printStackTrace(); System.err.println("Could not execute command."); System.exit(1); } IOUtil.readWrite(client.getInputStream(), client.getOutputStream(), System.in, System.out); try { client.disconnect(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.exit(0); }