List of usage examples for java.lang StringBuilder StringBuilder
@HotSpotIntrinsicCandidate
public StringBuilder()
From source file:clientpaxos.ClientPaxos.java
/** * @param args the command line arguments *///w w w. j a v a2 s . com public static void main(String[] args) throws IOException, InterruptedException, Exception { // TODO code application logic here String host = ""; int port = 0; try (BufferedReader br = new BufferedReader(new FileReader("ipserver.txt"))) { StringBuilder sb = new StringBuilder(); String line = br.readLine(); if (line != null) { host = line; line = br.readLine(); if (line != null) { port = Integer.parseInt(line); } } } scanner = new Scanner(System.in); //System.out.print("Input server IP hostname : "); //host = scan.nextLine(); //System.out.print("Input server Port : "); //port = scan.nextInt(); //scan.nextLine(); tcpSocket = new Socket(host, port); System.out.println("Connected"); Thread t = new Thread(new StringGetter()); t.start(); while (true) { sleep(100); if (!voteInput) { System.out.print("COMMAND : "); } //send msg to server String msg = scanner.next(); //if ((day && isAlive == 1) || (!day && role.equals("werewolf") && isAlive == 1)) { ParseCommand(msg); //} } }
From source file:ObfuscatingStream.java
/** * Obfuscates or unobfuscates the second command-line argument, depending on * whether the first argument starts with "o" or "u" * /*from w w w . java 2 s . c o m*/ * @param args * Command-line arguments * @throws IOException * If an error occurs obfuscating or unobfuscating */ public static void main(String[] args) throws IOException { InputStream input = new ByteArrayInputStream(args[1].getBytes()); StringBuilder toPrint = new StringBuilder(); if (args[0].startsWith("o")) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); OutputStream out = obfuscate(bytes); int read = input.read(); while (read >= 0) { out.write(read); read = input.read(); } byte[] receiptBytes = bytes.toByteArray(); for (int b = 0; b < receiptBytes.length; b++) { int chr = (receiptBytes[b] + 256) % 256; toPrint.append(HEX_CHARS[chr >>> 4]); toPrint.append(HEX_CHARS[chr & 0xf]); } } else if (args[0].startsWith("u")) { input = unobfuscate(input); InputStreamReader reader = new InputStreamReader(input); int read = reader.read(); while (read >= 0) { toPrint.append((char) read); read = reader.read(); } } else throw new IllegalArgumentException("First argument must start with o or u"); System.out.println(toPrint.toString()); }
From source file:com.ctriposs.rest4j.tools.snapshot.check.Rest4JSnapshotCompatibilityChecker.java
public static void main(String[] args) { final Options options = new Options(); options.addOption("h", "help", false, "Print help"); options.addOption(OptionBuilder.withArgName("compatibility_level").withLongOpt("compat").hasArg() .withDescription("Compatibility level " + listCompatLevelOptions()).create('c')); final String cmdLineSyntax = Rest4JSnapshotCompatibilityChecker.class.getCanonicalName() + " [pairs of <prevRestspecPath currRestspecPath>]"; final CommandLineParser parser = new PosixParser(); final CommandLine cmd; try {// ww w.j ava 2 s . co m cmd = parser.parse(options, args); } catch (ParseException e) { new HelpFormatter().printHelp(cmdLineSyntax, options, true); System.exit(1); return; // to suppress IDE warning } final String[] targets = cmd.getArgs(); if (cmd.hasOption('h') || targets.length < 2 || targets.length % 2 != 0) { new HelpFormatter().printHelp(cmdLineSyntax, options, true); System.exit(1); } final String compatValue; if (cmd.hasOption('c')) { compatValue = cmd.getOptionValue('c'); } else { compatValue = CompatibilityLevel.DEFAULT.name(); } final CompatibilityLevel compat; try { compat = CompatibilityLevel.valueOf(compatValue.toUpperCase()); } catch (IllegalArgumentException e) { new HelpFormatter().printHelp(cmdLineSyntax, options, true); System.exit(1); return; } final StringBuilder allSummaries = new StringBuilder(); boolean result = true; final String resolverPath = System.getProperty(AbstractGenerator.GENERATOR_RESOLVER_PATH); final Rest4JSnapshotCompatibilityChecker checker = new Rest4JSnapshotCompatibilityChecker(); checker.setResolverPath(resolverPath); for (int i = 1; i < targets.length; i += 2) { String prevTarget = targets[i - 1]; String currTarget = targets[i]; CompatibilityInfoMap infoMap = checker.check(prevTarget, currTarget, compat); result &= infoMap.isCompatible(compat); allSummaries.append(infoMap.createSummary(prevTarget, currTarget)); } if (compat != CompatibilityLevel.OFF && allSummaries.length() > 0) { System.out.println(allSummaries); } System.exit(result ? 0 : 1); }
From source file:com.ctriposs.rest4j.tools.idlcheck.Rest4JResourceModelCompatibilityChecker.java
@SuppressWarnings({ "static" }) public static void main(String[] args) { final Options options = new Options(); options.addOption("h", "help", false, "Print help"); options.addOption(OptionBuilder.withArgName("compatibility_level").withLongOpt("compat").hasArg() .withDescription("Compatibility level " + listCompatLevelOptions()).create('c')); final String cmdLineSyntax = Rest4JResourceModelCompatibilityChecker.class.getCanonicalName() + " [pairs of <prevRestspecPath currRestspecPath>]"; final CommandLineParser parser = new PosixParser(); final CommandLine cmd; try {/*from w ww . j av a2s. c o m*/ cmd = parser.parse(options, args); } catch (ParseException e) { new HelpFormatter().printHelp(cmdLineSyntax, options, true); System.exit(1); return; // to suppress IDE warning } final String[] targets = cmd.getArgs(); if (cmd.hasOption('h') || targets.length < 2 || targets.length % 2 != 0) { new HelpFormatter().printHelp(cmdLineSyntax, options, true); System.exit(1); } final String compatValue; if (cmd.hasOption('c')) { compatValue = cmd.getOptionValue('c'); } else { compatValue = CompatibilityLevel.DEFAULT.name(); } final CompatibilityLevel compat; try { compat = CompatibilityLevel.valueOf(compatValue.toUpperCase()); } catch (IllegalArgumentException e) { new HelpFormatter().printHelp(cmdLineSyntax, options, true); System.exit(1); return; } final StringBuilder allSummaries = new StringBuilder(); boolean result = true; for (int i = 1; i < targets.length; i += 2) { final Rest4JResourceModelCompatibilityChecker checker = new Rest4JResourceModelCompatibilityChecker(); checker.setResolverPath(System.getProperty(AbstractGenerator.GENERATOR_RESOLVER_PATH)); String prevTarget = targets[i - 1]; String currTarget = targets[i]; result &= checker.check(prevTarget, currTarget, compat); allSummaries.append(checker.getInfoMap().createSummary(prevTarget, currTarget)); } if (compat != CompatibilityLevel.OFF && allSummaries.length() > 0) { System.out.println(allSummaries); } System.exit(result ? 0 : 1); }
From source file:JALPTest.java
/** * The main method that gets called to test JALoP. * * @param args the command line arguments */// w w w.j a va 2s . c o m public static void main(String[] args) { Producer producer = null; try { Options options = createOptions(); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); String pathToXML = null; String type = null; String input = null; String privateKeyPath = null; String publicKeyPath = null; String certPath = null; String socketPath = null; Boolean hasDigest = false; File file = null; ApplicationMetadataXML xml = null; if (cmd.hasOption("h")) { System.out.println(usage); return; } if (cmd.hasOption("a")) { pathToXML = cmd.getOptionValue("a"); } if (cmd.hasOption("t")) { type = cmd.getOptionValue("t"); } if (cmd.hasOption("p")) { file = new File(cmd.getOptionValue("p")); } if (cmd.hasOption("s")) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); String s; while ((s = in.readLine()) != null && s.length() != 0) { sb.append(s); sb.append("\n"); } input = sb.toString(); } if (cmd.hasOption("j")) { socketPath = cmd.getOptionValue("j"); } if (cmd.hasOption("k")) { privateKeyPath = cmd.getOptionValue("k"); } if (cmd.hasOption("b")) { publicKeyPath = cmd.getOptionValue("b"); } if (cmd.hasOption("c")) { certPath = cmd.getOptionValue("c"); } if (cmd.hasOption("d")) { hasDigest = true; } if (pathToXML != null) { xml = createXML(readXML(pathToXML)); } producer = createProducer(xml, socketPath, privateKeyPath, publicKeyPath, certPath, hasDigest); callSend(producer, type, input, file); } catch (IOException e) { if (producer != null) { System.out.println("Failed to open socket: " + producer.getSocketFile()); } else { System.out.println("Failed to create Producer"); } } catch (Exception e) { error(e.toString()); return; } }
From source file:Server_socket.java
public static void main(String argv[]) throws Exception { int puerto = Integer.parseInt(argv[0]); //String username = argv[1]; //String password = argv[2]; String clientformat;/*ww w .ja v a2 s . c o m*/ String clientdata; String clientresult; String clientresource; String url_login = "http://localhost:3000/users/sign_in"; ServerSocket welcomeSocket = new ServerSocket(puerto); /*HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url_login); // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); // nameValuePairs.add(new BasicNameValuePair("utf8", Character.toString('\u2713'))); nameValuePairs.add(new BasicNameValuePair("username", username)); nameValuePairs.add(new BasicNameValuePair("password", password)); // nameValuePairs.add(new BasicNameValuePair("commit", "Sign in")); httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpClient.execute(httpPost); String ret = EntityUtils.tostring(response.getEntity()); System.out.println(ret); */ while (true) { Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader( new InputStreamReader(connectionSocket.getInputStream())); clientformat = inFromClient.readLine(); System.out.println("FORMAT: " + clientformat); BufferedReader inFromClient1 = new BufferedReader( new InputStreamReader(connectionSocket.getInputStream())); clientdata = inFromClient1.readLine(); System.out.println("DATA: " + clientdata); BufferedReader inFromClient2 = new BufferedReader( new InputStreamReader(connectionSocket.getInputStream())); clientresult = inFromClient2.readLine(); System.out.println("RESULT: " + clientresult); BufferedReader inFromClient3 = new BufferedReader( new InputStreamReader(connectionSocket.getInputStream())); clientresource = inFromClient3.readLine(); System.out.println("RESOURCE: " + clientresource); System.out.println("no pasas de aqui"); String url = "http://localhost:3000/" + clientresource + "/" + clientdata + "." + clientformat; System.out.println(url); try (InputStream is = new URL(url).openStream()) { BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); StringBuilder sb = new StringBuilder(); int cp; while ((cp = rd.read()) != -1) { sb.append((char) cp); } String stb = sb.toString(); System.out.println("estas aqui"); String output = null; String jsonText = stb; output = jsonText.replace("[", "").replace("]", ""); JSONObject json = new JSONObject(output); System.out.println(json.toString()); System.out.println("llegaste al final"); DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); outToClient.writeBytes(json.toString()); } connectionSocket.close(); } }
From source file:fr.eo.util.dumper.Dumper.java
/** * @param args/*from w ww.j a v a 2 s.c o m*/ */ public static void main(String[] args) { String appName = args[0]; System.out.println("Starting dumper ..."); Statement stmt = null; try { System.out.println("Getting database connection ..."); Connection conn = getJtdsConnection(); List<RequestDefinitionBean> requests = RequestDefinitionParser.getRequests(appName); assetFolder = RequestDefinitionParser.getAppBaseDir(appName) + "assets/"; for (RequestDefinitionBean request : requests) { int currentFileSize = 0, cpt = 1; stmt = conn.createStatement(); System.out.println("Dumping " + request.name + "..."); ResultSet rs = stmt.executeQuery(request.sql); BufferedWriter bw = getWriter(request.name, cpt); bw.append(COPYRIGHTS); currentFileSize += COPYRIGHTS.length(); bw.append("--" + request.name + "\n"); while (rs.next()) { StringBuilder sb = new StringBuilder(); sb.append("INSERT INTO "); sb.append(request.table).append(" VALUES ("); int pos = 0; for (String fieldName : request.fields) { String str = getFieldValue(request, pos, rs, fieldName); sb.append(str); pos++; if (pos < request.fields.size()) { sb.append(","); } } sb.append(");\n"); currentFileSize += sb.length(); bw.append(sb.toString()); bw.flush(); if (currentFileSize > MAX_FILE_SIZE) { bw.close(); bw = getWriter(request.name, ++cpt); bw.append(COPYRIGHTS); bw.append("--" + request.name + "\n"); currentFileSize = COPYRIGHTS.length(); } } bw.flush(); bw.close(); } System.out.println("done."); } catch (SQLException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } } DumpFilesDescriptor descriptor = new DumpFilesDescriptor(); descriptor.lineNumbers = getDumpLinesNumber(); descriptor.dumpFileNames = dumpFileNames; writeDescriptorFile(descriptor); System.out.println("nb :" + descriptor.lineNumbers); }
From source file:com.linkedin.restli.tools.idlcheck.RestLiResourceModelCompatibilityChecker.java
public static void main(String[] args) { final Options options = new Options(); options.addOption("h", "help", false, "Print help"); options.addOption(OptionBuilder.withArgName("compatibility_level").withLongOpt("compat").hasArg() .withDescription("Compatibility level " + listCompatLevelOptions()).create('c')); options.addOption(OptionBuilder.withLongOpt("report").withDescription( "Prints a report at the end of the execution that can be parsed for reporting to other tools") .create("report")); final String cmdLineSyntax = RestLiResourceModelCompatibilityChecker.class.getCanonicalName() + " [pairs of <prevRestspecPath currRestspecPath>]"; final CommandLineParser parser = new PosixParser(); final CommandLine cmd; try {//from w w w .j a va2s . co m cmd = parser.parse(options, args); } catch (ParseException e) { new HelpFormatter().printHelp(cmdLineSyntax, options, true); System.exit(255); return; // to suppress IDE warning } final String[] targets = cmd.getArgs(); if (cmd.hasOption('h') || targets.length < 2 || targets.length % 2 != 0) { new HelpFormatter().printHelp(cmdLineSyntax, options, true); System.exit(255); } final String compatValue; if (cmd.hasOption('c')) { compatValue = cmd.getOptionValue('c'); } else { compatValue = CompatibilityLevel.DEFAULT.name(); } final CompatibilityLevel compat; try { compat = CompatibilityLevel.valueOf(compatValue.toUpperCase()); } catch (IllegalArgumentException e) { new HelpFormatter().printHelp(cmdLineSyntax, options, true); System.exit(255); return; } final StringBuilder allSummaries = new StringBuilder(); final RestLiResourceModelCompatibilityChecker checker = new RestLiResourceModelCompatibilityChecker(); for (int i = 1; i < targets.length; i += 2) { checker.setResolverPath(System.getProperty(AbstractGenerator.GENERATOR_RESOLVER_PATH)); String prevTarget = targets[i - 1]; String currTarget = targets[i]; checker.check(prevTarget, currTarget, compat); } allSummaries.append(checker.getInfoMap().createSummary()); if (compat != CompatibilityLevel.OFF && allSummaries.length() > 0) { System.out.println(allSummaries); } if (cmd.hasOption("report")) { System.out.println(new CompatibilityReport(checker.getInfoMap(), compat).createReport()); System.exit(0); } System.exit(checker.getInfoMap().isCompatible(compat) ? 0 : 1); }
From source file:mxnet.ObjectDetection.java
public static void main(String[] args) { List<Context> context = new ArrayList<Context>(); context.add(Context.cpu());//from ww w . ja va 2 s. c o m downloadModelImage(); List<List<ObjectDetectorOutput>> output = runObjectDetectionSingle(modelPath, imagePath, context); Shape inputShape = new Shape(new int[] { 1, 3, 512, 512 }); Shape outputShape = new Shape(new int[] { 1, 6132, 6 }); int width = inputShape.get(2); int height = inputShape.get(3); String outputStr = "\n"; for (List<ObjectDetectorOutput> ele : output) { for (ObjectDetectorOutput i : ele) { outputStr += "Class: " + i.getClassName() + "\n"; outputStr += "Probabilties: " + i.getProbability() + "\n"; List<Float> coord = Arrays.asList(i.getXMin() * width, i.getXMax() * height, i.getYMin() * width, i.getYMax() * height); StringBuilder sb = new StringBuilder(); for (float c : coord) { sb.append(", ").append(c); } outputStr += "Coord:" + sb.substring(2) + "\n"; } } System.out.println(outputStr); }
From source file:com.heliosapm.opentsdb.client.boot.JavaAgentInstaller.java
public static void main(final String[] args) { if (args.length == 0) { loge("Usage: java com.heliosapm.opentsdb.client.boot.JavaAgentInstaller \n\t<PID | Name to match> \n\t[-list | -listjson] \n\t[-p k=v] \n\t[-config URL|File]"); }/*from www . j av a 2 s . co m*/ final long pid; if (isPid(args[0])) { pid = Long.parseLong(args[0].trim()); } else if ("-list".equalsIgnoreCase(args[0])) { printJVMs(myId); return; } else if ("-listjson".equalsIgnoreCase(args[0])) { printJVMsInJSON(myId); return; } else { pid = findPid(args[0]); } if (pid < 1) { System.exit(-1); } log("Installing JavaAgent to PID: %s from JAR: %s", pid, JavaAgentInstaller.class.getProtectionDomain().getCodeSource().getLocation()); VirtualMachine vm = null; try { final String loc = new File( JavaAgentInstaller.class.getProtectionDomain().getCodeSource().getLocation().getFile()) .getAbsolutePath(); vm = VirtualMachine.attach("" + pid); log("Connected to process %s, loading Agent from %s", vm.id(), loc); if (args.length > 1) { StringBuilder b = new StringBuilder(); for (int i = 1; i < args.length; i++) { b.append(args[i]).append("|~"); if ("-config".equalsIgnoreCase(args[i])) { i++; final URL url = URLHelper.toURL(args[i]); b.append(url).append("|~"); } } b.deleteCharAt(b.length() - 1); b.deleteCharAt(b.length() - 1); log("Loading with options [%s]", b); vm.loadAgent(loc, b.toString()); } else { log("Loading with no options"); vm.loadAgent(loc); } log("Agent loaded to process %s", vm.id()); System.exit((int) pid); } catch (Exception ex) { loge("Failed to attach to process %s. Stack trace follows...", pid); ex.printStackTrace(System.err); } finally { if (vm != null) { try { vm.detach(); log("Detached from process %s", pid); } catch (Exception ex) { } } } }