List of usage examples for java.lang String String
public String(StringBuilder builder)
From source file:com.vimukti.accounter.developer.api.PublicKeyGenerator.java
/** * @param args/*from w ww . j a v a 2 s .c o m*/ * @throws NoSuchProviderException * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException * @throws IOException * @throws CertificateException * @throws KeyStoreException * @throws UnrecoverableEntryException * @throws URISyntaxException */ public static void main(String[] args) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableEntryException { FileInputStream is = new FileInputStream( ServerConfiguration.getConfig() + File.separator + "license.keystore"); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); String password = "liceseStorePassword"; keystore.load(is, password.toCharArray()); PrivateKeyEntry entry = (PrivateKeyEntry) keystore.getEntry("licenseAlias", new PasswordProtection(ServerConfiguration.getLicenseKeystorePWD().toCharArray())); Key key = entry.getPrivateKey(); System.out.println((PrivateKey) key); PublicKey publicKey = entry.getCertificate().getPublicKey(); System.out.println(publicKey); byte[] encoded = publicKey.getEncoded(); byte[] encodeBase64 = Base64.encodeBase64(encoded); System.out.println("Public Key:" + new String(encodeBase64)); }
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); // Create a new document Document xmlDoc = builder.newDocument(); // Create root node for the document... Element root = xmlDoc.createElement("Players"); xmlDoc.appendChild(root);// w w w. ja va 2 s . co m // Create a "player" node Element player = xmlDoc.createElement("player"); // Set the players ID attribute player.setAttribute("ID", "1"); // Create currentRank node... Element currentRank = xmlDoc.createElement("currentRank"); currentRank.setTextContent("1"); player.appendChild(currentRank); // Create previousRank node... Element previousRank = xmlDoc.createElement("previousRank"); previousRank.setTextContent("1"); player.appendChild(previousRank); // Create playerName node... Element playerName = xmlDoc.createElement("PlayerName"); playerName.setTextContent("Max"); player.appendChild(playerName); // Create Money node... Element money = xmlDoc.createElement("Money"); money.setTextContent("15"); player.appendChild(money); // Add the player to the root node... root.appendChild(player); ByteArrayOutputStream baos = null; baos = new ByteArrayOutputStream(); Transformer tf = TransformerFactory.newInstance().newTransformer(); tf.setOutputProperty(OutputKeys.INDENT, "yes"); tf.setOutputProperty(OutputKeys.METHOD, "xml"); tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); DOMSource domSource = new DOMSource(xmlDoc); StreamResult sr = new StreamResult(baos); tf.transform(domSource, sr); baos.flush(); System.out.println(new String(baos.toByteArray())); baos.close(); }
From source file:ZipDemo.java
public static void main(String[] args) throws Exception { for (int i = 0; i < args.length; ++i) { String uncompressed = ""; File f = new File(args[i]); if (f.exists()) { BufferedReader br = new BufferedReader(new FileReader(f)); String line = ""; StringBuffer buffer = new StringBuffer(); while ((line = br.readLine()) != null) buffer.append(line);//from www. j av a 2 s. co m br.close(); uncompressed = buffer.toString(); } else { uncompressed = args[i]; } byte[] compressed = ZipDemo.compress(uncompressed); String compressedAsString = new String(compressed); byte[] bytesFromCompressedAsString = compressedAsString.getBytes(); bytesFromCompressedAsString.equals(compressed); System.out.println(ZipDemo.uncompress(compressed)); System.out.println(ZipDemo.uncompress(compressedAsString)); } }
From source file:com.mq.rocketmq.ordermessage.Consumer.java
public static void main(String[] args) throws MQClientException { DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name_3"); consumer.setNamesrvAddr("10.115.101.84:9876"); /**/*from w ww. j av a 2 s. co m*/ * Consumer?<br> * ??? */ consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET); consumer.subscribe("TopicTest", "TagA || TagC || TagD"); consumer.registerMessageListener(new MessageListenerOrderly() { AtomicLong consumeTimes = new AtomicLong(0); public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) { context.setAutoCommit(false); this.consumeTimes.incrementAndGet(); String msg = String.format("%s,%s,%s,%s,%s", this.consumeTimes.get(), Thread.currentThread().getName(), "Receive New Messages:", new String(msgs.get(0).getBody()), msgs.get(0).getTags()); // if ((this.consumeTimes.get() % 2) == 0) { // System.out.println(String.format("%s,%s","Commit",msg)); // return ConsumeOrderlyStatus.COMMIT; // } // else if ((this.consumeTimes.get() % 3) == 0) { // return ConsumeOrderlyStatus.ROLLBACK; // } // else if ((this.consumeTimes.get() % 3) == 0) { // System.out.println(String.format("%s,%s","Commit",msg)); // return ConsumeOrderlyStatus.COMMIT; // } // else if ((this.consumeTimes.get() % 5) == 0) { // context.setSuspendCurrentQueueTimeMillis(3000); // return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT; // } System.out.println(String.format("%s,%s", "SUCCESS", msg)); return ConsumeOrderlyStatus.SUCCESS; } }); consumer.start(); System.out.println("Consumer Started."); }
From source file:loanbroker.normalizer.NormalizerTeachersJsonBank.java
public static void main(String[] args) { try {/* w w w. j a v a 2 s. c om*/ ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); factory.setPort(5672); factory.setUsername("student"); factory.setPassword("cph"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME, "fanout"); //String queueName = channel.queueDeclare().getQueue(); //channel.queueBind(queueName, EXCHANGE_NAME, ""); channel.queueDeclare(RPC_QUEUE_NAME, false, false, false, null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(RPC_QUEUE_NAME, true, consumer); //producer Channel channelOutput = connection.createChannel(); channelOutput.exchangeDeclare(ExchangeName.GLOBAL, "direct"); String queueName = channelOutput.queueDeclare().getQueue(); channelOutput.queueBind(queueName, ExchangeName.GLOBAL, "normalizerToAggregator"); LoanResponse loanResponse; while (true) { System.out.println("Reading"); QueueingConsumer.Delivery delivery = consumer.nextDelivery(); System.out.println("CorrelationId: " + delivery.getProperties().getCorrelationId()); String message = new String(delivery.getBody()); JSONObject jsonObj = new JSONObject(message); loanResponse = new LoanResponse(jsonObj.getInt("ssn"), jsonObj.getDouble("interestRate"), "Teachers Json Bank", delivery.getProperties().getCorrelationId()); System.out.println("renter: " + loanResponse.getInterestRate()); System.out.println("ssn: " + loanResponse.getSsn()); System.out.println("bank : " + loanResponse.getBank()); // System.out.println(" [x] Received '" + message + "'"); System.out.println("JSON:" + loanResponse); System.out.println("TOstring:" + jsonObj.toString()); Gson g = new Gson(); String fm = g.toJson(loanResponse); channelOutput.basicPublish("TeamFirebug", "normalizerToAggregator", null, fm.getBytes()); } } catch (IOException | TimeoutException | InterruptedException e) { e.printStackTrace(); } }
From source file:com.floragunn.searchguard.tools.Hasher.java
public static void main(final String[] args) { final Options options = new Options(); final HelpFormatter formatter = new HelpFormatter(); options.addOption(/* w ww. ja v a 2 s . com*/ Option.builder("p").argName("password").hasArg().desc("Cleartext password to hash").build()); options.addOption(Option.builder("env").argName("name environment variable").hasArg() .desc("name environment variable to read password from").build()); final CommandLineParser parser = new DefaultParser(); try { final CommandLine line = parser.parse(options, args); if (line.hasOption("p")) { System.out.println(hash(line.getOptionValue("p").getBytes("UTF-8"))); } else if (line.hasOption("env")) { final String pwd = System.getenv(line.getOptionValue("env")); if (pwd == null || pwd.isEmpty()) { throw new Exception("No environment variable '" + line.getOptionValue("env") + "' set"); } System.out.println(hash(pwd.getBytes("UTF-8"))); } else { final Console console = System.console(); if (console == null) { throw new Exception("Cannot allocate a console"); } final char[] passwd = console.readPassword("[%s]", "Password:"); System.out.println(hash(new String(passwd).getBytes("UTF-8"))); } } catch (final Exception exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); formatter.printHelp("hasher.sh", options, true); System.exit(-1); } }
From source file:loanbroker.normalizer.NormalizerOurJsonBank.java
public static void main(String[] args) { try {//from w w w.j a va 2 s. c o m ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); factory.setPort(5672); factory.setUsername("student"); factory.setPassword("cph"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME, "fanout"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, EXCHANGE_NAME, ""); //channel.queueDeclare(RPC_QUEUE_NAME,false, false, false, null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, true, consumer); //producer Channel channelOutput = connection.createChannel(); channelOutput.exchangeDeclare(ExchangeName.GLOBAL, "direct"); String queueNameProducer = channelOutput.queueDeclare().getQueue(); channelOutput.queueBind(queueNameProducer, ExchangeName.GLOBAL, RoutingKeys.NormalizerToAggregator); LoanResponse loanResponse; while (true) { System.out.println("Reading"); QueueingConsumer.Delivery delivery = consumer.nextDelivery(); System.out.println("CorrelationId: " + delivery.getProperties().getCorrelationId()); String message = new String(delivery.getBody()); JSONObject jsonObj = new JSONObject(message); loanResponse = new LoanResponse(jsonObj.getInt("ssn"), Math.ceil(jsonObj.getDouble("interestRate")), "Our Json Bank", delivery.getProperties().getCorrelationId()); System.out.println("renter: " + loanResponse.getInterestRate()); System.out.println("ssn: " + loanResponse.getSsn()); System.out.println("bank : " + loanResponse.getBank()); System.out.println("JSON:" + loanResponse); System.out.println("TOstring:" + jsonObj.toString()); Gson g = new Gson(); String fm = g.toJson(loanResponse); channelOutput.basicPublish(ExchangeName.GLOBAL, RoutingKeys.NormalizerToAggregator, null, fm.getBytes()); } } catch (IOException | TimeoutException | InterruptedException e) { e.printStackTrace(); } }
From source file:com.sm.store.T1.java
public static void main(String[] args) { int i = -1, j = -(0xFF), k = 0xff; byte[] bs = new byte[4]; putInt(bs, 0, i);//from w w w . j a v a2 s . c o m putInt(bs, 0, j); putInt(bs, 0, k); T1.T2 t2 = new T1.T2("test-10", 20); T1 t1 = new T1("test-1", 1, new Integer(4), t2); HessianSerializer<T1> hs = new HessianSerializer<T1>(); String str = new String(hs.toBytes(t1)); System.out.println(str); t1 = new T1("test-1", 1, new Integer(4), null); str = new String(hs.toBytes(t1)); System.out.println(str); // Constructor[] cs = t1.getClass().getConstructors(); // for (Constructor each : cs) { // Type[] ts= each.getParameterTypes(); // logger.info(ts.getClass().getName()); // for ( Type type : ts) // logger.info(type.getClass().toString()); // } }
From source file:com.rslakra.java.TestUrlConnection.java
public static void main(String[] args) { String urlString = "https://devamatre.com/"; HttpResponse httpResponse = HTTPHelper.executeGetRequest(urlString, null, true); System.out.println(httpResponse.getRequestHeaders()); String formActionValue = extractFormActionValue(httpResponse.getDataBytes()); System.out.println("\nformActionValue:\n" + formActionValue); String dataString = new String(httpResponse.getDataBytes()); Pattern pattern = Pattern.compile("\""); Matcher matcher = pattern.matcher(dataString); if (matcher.matches()) { System.out.println("Matched\n"); System.out.println(matcher.group(1)); }//from ww w . j a v a 2 s . c o m System.out.println(StringEscapeUtils.unescapeHtml(urlString)); }
From source file:RulesDemo.java
static public void main(String[] args) { String englishRules = ("< a,A < b,B < c,C < d,D < e,E < f,F " + "< g,G < h,H < i,I < j,J < k,K < l,L " + "< m,M < n,N < o,O < p,P < q,Q < r,R " + "< s,S < t,T < u,U < v,V < w,W < x,X " + "< y,Y < z,Z"); String smallnTilde = new String("\u00F1"); String capitalNTilde = new String("\u00D1"); String traditionalSpanishRules = ("< a,A < b,B < c,C " + "< ch, cH, Ch, CH " + "< d,D < e,E < f,F " + "< g,G < h,H < i,I < j,J < k,K < l,L " + "< ll, lL, Ll, LL " + "< m,M < n,N " + "< " + smallnTilde + "," + capitalNTilde + " " + "< o,O < p,P < q,Q < r,R " + "< s,S < t,T < u,U < v,V < w,W < x,X " + "< y,Y < z,Z"); String[] words = { "luz", "curioso", "llama", "chalina" }; try {/*from w w w .j a va 2 s. com*/ RuleBasedCollator enCollator = new RuleBasedCollator(englishRules); RuleBasedCollator spCollator = new RuleBasedCollator(traditionalSpanishRules); sortStrings(enCollator, words); printStrings(words); System.out.println(); sortStrings(spCollator, words); printStrings(words); } catch (ParseException pe) { System.out.println("Parse exception for rules"); } }