Example usage for java.lang String String

List of usage examples for java.lang String String

Introduction

In this page you can find the example usage for java.lang String String.

Prototype

public String(StringBuilder builder) 

Source Link

Document

Allocates a new string that contains the sequence of characters currently contained in the string builder argument.

Usage

From source file:loanbroker.normalizer.NormalizerTeachersXmlBank.java

public static void main(String[] argv) throws IOException, InterruptedException, TimeoutException {
    //Connection/* w  ww . jav a  2s .c o m*/
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("datdb.cphbusiness.dk");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    //Consumer
    channel.exchangeDeclare(EXCHANGE_NAME, "fanout");
    //String queueName = channel.queueDeclare().getQueue();
    //s channel.queueBind(queueName, EXCHANGE_NAME, "OurSoapXmlBank");
    channel.queueDeclare(RPC_QUEUE_NAME, false, false, false, null);
    QueueingConsumer consumer = new QueueingConsumer(channel);
    channel.basicConsume(RPC_QUEUE_NAME, true, consumer);
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

    //Producer
    Channel channelOutput = connection.createChannel();
    channelOutput.exchangeDeclare("TeamFirebug", "direct");

    while (true) {
        System.out.println("Reading");
        QueueingConsumer.Delivery delivery = consumer.nextDelivery();
        String message = new String(delivery.getBody());
        String routingKey = delivery.getEnvelope().getRoutingKey();

        DtoTeachersXmlBank dtoOurSoapXmlBank = JAXB.unmarshal(new StringReader(message),
                DtoTeachersXmlBank.class);
        LoanResponse loanResponse = new LoanResponse(dtoOurSoapXmlBank.getSsn(),
                dtoOurSoapXmlBank.getInterestRate(), "Teachers Xml Bank",
                delivery.getProperties().getCorrelationId());
        // loanResponse.setBank(routingKey);
        System.out.println("CorrelationId: " + delivery.getProperties().getCorrelationId());

        System.out.println("renter: " + loanResponse.getInterestRate());
        System.out.println("ssn: " + loanResponse.getSsn());
        System.out.println("bank : " + loanResponse.getBank());
        JSONObject jsonObj = new JSONObject(loanResponse);
        System.out.println("JSON:" + jsonObj);
        // channelOutput.basicPublish("", RoutingKeys.Aggregator, null, jsonObj.toString().getBytes());
        channelOutput.basicPublish("TeamFirebug", "normalizerToAggregator", null,
                jsonObj.toString().getBytes());
        delivery = null;
    }
}

From source file:cz.muni.fi.pa165.rentalofconstructionmachinery.restclient.App.java

public static int main(String[] args) {

    infoLogger.info("\n\nREST Sample Client\n\n");

    HttpHeaders httpHeaders = new HttpHeaders();
    String auth = REST_USERNAME + ":" + REST_PASSWORD;
    byte[] encodedAuthorisation = Base64.encode(auth.getBytes());
    httpHeaders.add("Authorization", "Basic " + new String(encodedAuthorisation));

    CustomerRestController.setHttpHeaders(httpHeaders);
    MachineRestController.setHttpHeaders(httpHeaders);

    try {// www . jav a  2 s . com
        switch (System.getProperty(ACTION, "")) {
        case "list":
            listEntities();
            break;
        case "details":
            getDetails();
            break;
        case "create":
            createEntity();
            break;
        case "edit":
            editEntity();
            break;
        case "delete":
            deleteEntity();
            break;
        default:
            infoLogger.info("Please, see the usage guide for this client in the README file.");
        }
    } catch (Exception e) {
        errorLogger.error("Houston, we have a problem.", e);
        infoLogger.info("\n\n");
        infoLogger.info("Ooops.");
        return 1;
    }

    infoLogger.info("\n\n");
    infoLogger.info("The operation was successful.");
    return 0;
}

From source file:EncodeUtils.java

public static final void main(String[] args) throws Exception {
    byte[] bytes = { (byte) 0, (byte) 128, (byte) 0 };
    System.out.println(new String(toBase64(bytes)));
    System.out.println(new String(toBase64("Hello, World".getBytes())));
    System.out.println(new String(toBase64("Monday".getBytes())));
    System.out.println(new String(toBase64("M\u00F6nchengladbach\r\n".getBytes("ISO-8859-1"))));
}

From source file:org.opencredo.cloud.storage.samples.quote.S3QuoteDemo.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("quoteDemo-context.xml");

    TickerUploader tickerUploader = (TickerUploader) context.getBean("tickerUploader");
    // sending requests for tickers to be uploaded to S3, so that they can
    // later be read by another application.
    // can be commented out if already uploaded enough information
    for (int i = 0; i < 4; i++) {
        char[] chars = new char[3];
        for (int j = 0; j < 3; j++) {
            chars[j] = (char) (new Random().nextInt(25) + 65);
        }/* ww  w  .  j  a  va  2s . com*/
        String ticker = new String(chars);
        LOG.info("ticker to upload: {}", ticker);
        MessageBuilder<String> builder = MessageBuilder.withPayload(ticker);
        tickerUploader.sendTicker(builder.build());
    }
}

From source file:StringConverter.java

public static void main(String[] args) {

    System.out.println(System.getProperty("file.encoding"));
    String original = new String("A" + "\u00ea" + "\u00f1" + "\u00fc" + "C");

    System.out.println("original = " + original);
    System.out.println();//  w ww.ja  v  a  2 s. c  om

    try {
        byte[] utf8Bytes = original.getBytes("UTF8");
        byte[] defaultBytes = original.getBytes();

        String roundTrip = new String(utf8Bytes, "UTF8");
        System.out.println("roundTrip = " + roundTrip);

        System.out.println();
        printBytes(utf8Bytes, "utf8Bytes");
        System.out.println();
        printBytes(defaultBytes, "defaultBytes");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

}

From source file:com.pinterest.terrapin.client.ClientTool.java

public static void main(String[] args) throws Exception {
    PropertiesConfiguration config = new PropertiesConfiguration(System.getProperty("terrapin.config"));
    TerrapinClient client = new TerrapinClient(config, 9090, 1000, 5000);
    String key = args[1];/* ww w.  ja va  2s  .  c om*/
    TerrapinSingleResponse response = client.getOne(args[0], // fileset
            ByteBuffer.wrap(key.getBytes())).get();
    if (response.isSetErrorCode()) {
        System.out.println("Got error " + response.getErrorCode().toString());
    } else if (response.isSetValue()) {
        System.out.println("Got value.");
        System.out.println(new String(response.getValue()));
    } else {
        System.out.println("Key " + key + " not found.");
    }
    System.exit(0);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    String s = "F488FD584E49DBCD20B49DE49107366B336C380D451D0F7C88"
            + "11111111111111111111111111111111111111111111111111"
            + "11111111111111111111111111111111111111111111111111"
            + "11111111111111111111111111111111111111111111111111"
            + "11111111111111111111111111111111111111111111111111" + "2F78C7";
    BigInteger base = BigInteger.valueOf(2);
    BigInteger modulous = new BigInteger(s, 16);
    DHParameterSpec skipParameterSpec = new DHParameterSpec(modulous, base);

    KeyPairGenerator kpg1 = KeyPairGenerator.getInstance("DH");
    kpg1.initialize(skipParameterSpec);//from w  ww.  jav  a 2s.co  m
    KeyPair kp1 = kpg1.generateKeyPair();

    KeyAgreement ka1 = KeyAgreement.getInstance("DH");
    DHPrivateKey privateKey1 = (DHPrivateKey) kp1.getPrivate();
    DHPublicKey publicKey1 = (DHPublicKey) kp1.getPublic();
    ka1.init(privateKey1);
    System.out.println("1 is using " + publicKey1.getY() + " for its public key");

    KeyPairGenerator kpg2 = KeyPairGenerator.getInstance("DH");
    kpg2.initialize(skipParameterSpec);
    KeyPair kp2 = kpg2.generateKeyPair();

    KeyAgreement ka2 = KeyAgreement.getInstance("DH");
    DHPrivateKey privateKey2 = (DHPrivateKey) kp2.getPrivate();
    DHPublicKey publicKey2 = (DHPublicKey) kp2.getPublic();
    ka2.init(privateKey2);
    System.out.println("2 is using " + publicKey2.getY() + "for its public key");
    // Use the KeyAgreement object of 1 to generate its shared key
    ka1.doPhase(publicKey2, true);
    SecretKey sharedKey1 = ka1.generateSecret("DES");
    System.out.println("1 is using " + new String(sharedKey1.getEncoded()) + " as its DES session key");
    // Use the KeyAgreement object of 2 to generate its shared key
    ka2.doPhase(publicKey1, true);
    SecretKey sharedKey2 = ka2.generateSecret("DES");
    System.out.println("2 is using " + new String(sharedKey2.getEncoded()) + "as its DES session key");
}

From source file:GetMultipleLeads.java

public static void main(String[] args) {
    System.out.println("Executing GetMultipleLeads");
    try {//from   ww w . ja va 2  s  . c o  m
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsGetMultipleLeads request = new ParamsGetMultipleLeads();

        // Request Using LeadKey Selector
        ////////////////////////////////////////////////////////
        LeadKeySelector keySelector = new LeadKeySelector();
        keySelector.setKeyType(LeadKeyRef.EMAIL);

        ArrayOfString aos = new ArrayOfString();
        aos.getStringItems().add("formtest1@marketo.com");
        aos.getStringItems().add("joe@marketo.com");
        keySelector.setKeyValues(aos);
        request.setLeadSelector(keySelector);

        /*
        // Request Using LastUpdateAtSelector
        ////////////////////////////////////////////////////////
        LastUpdateAtSelector leadSelector = new LastUpdateAtSelector();
                 
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTimeInMillis(new Date().getTime());
        gc.add( GregorianCalendar.DAY_OF_YEAR, -2);
                 
        DatatypeFactory factory = DatatypeFactory.newInstance();
                
        ObjectFactory objectFactory = new ObjectFactory();
        JAXBElement<XMLGregorianCalendar> until =objectFactory.createLastUpdateAtSelectorLatestUpdatedAt(factory.newXMLGregorianCalendar(gc));            
                 
        GregorianCalendar since = new GregorianCalendar();
        since.setTimeInMillis(new Date().getTime());
        since.add( GregorianCalendar.DAY_OF_YEAR, -5);
                 
        leadSelector.setOldestUpdatedAt(factory.newXMLGregorianCalendar(since));
        leadSelector.setLatestUpdatedAt(until);     
                 
        request.setLeadSelector(leadSelector);
        */

        /*
        // Request Using StaticList Selector
        ////////////////////////////////////////////////////////
        StaticListSelector staticListSelector = new StaticListSelector();
                
        //staticListSelector.setStaticListId(value)
        ObjectFactory objectFactory = new ObjectFactory();
        JAXBElement<String> listName = objectFactory.createStaticListSelectorStaticListName("SMSProgram.listForTesting");
        staticListSelector.setStaticListName(listName);
                 
        // JAXBElement<Integer> listId = objectFactory.createStaticListSelectorStaticListId(6926);
        // staticListSelector.setStaticListId(listId);
                 
        request.setLeadSelector(staticListSelector);
        */

        ArrayOfString attributes = new ArrayOfString();
        attributes.getStringItems().add("FirstName");
        attributes.getStringItems().add("AnonymousIP");
        attributes.getStringItems().add("Company");

        request.setIncludeAttributes(attributes);

        JAXBElement<Integer> batchSize = new ObjectFactory().createParamsGetMultipleLeadsBatchSize(10);
        request.setBatchSize(batchSize);

        SuccessGetMultipleLeads result = port.getMultipleLeads(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessGetLead.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:DataStudioCrak.java

public static void main(String[] args) {
    String company = "labthink";
    byte[] companyByteArray = company.getBytes();
    byte[] companyByteIntArray = intToByteArray(compute(companyByteArray, companyByteArray.length));
    // byte[] ff = "zhulixia".getBytes();
    byte[] snByte = new byte[32];
    byte[] byte1 = new byte[] { 7, 1 };
    byte[] byte2 = "zhaodapengpojiehahahahahaha".getBytes();
    byte[] byte3 = new byte[] { 127 };
    byte[] snMain = new byte[24];
    System.arraycopy(byte1, 0, snMain, 0, 2);
    System.arraycopy(byte2, 0, snMain, 2, 17);
    System.arraycopy(companyByteIntArray, 0, snMain, 19, 4);
    System.arraycopy(byte3, 0, snMain, 23, 1);
    //  1 - single license,2 - site license ,3 educational license
    snMain[2] = (byte) 1;
    int intSn = compute(snMain, snMain.length);
    System.out.println("intSn=" + intSn);
    byte[] key1 = "dddd".getBytes();
    byte[] key2 = intToByteArray(intSn);
    byte[] key = new byte[8];
    System.arraycopy(key1, 0, key, 0, 4);
    System.arraycopy(key2, 0, key, 4, 4);

    byte encodedSnMain[] = new byte[snMain.length];
    try {/*from  w w w.  jav  a  2s.  c  o  m*/
        DESKeySpec deskeyspec = new DESKeySpec(key);
        javax.crypto.SecretKey secretkey = SecretKeyFactory.getInstance("DES").generateSecret(deskeyspec);
        Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding");
        cipher.init(Cipher.ENCRYPT_MODE, secretkey);
        cipher.update(snMain, 0, snMain.length, encodedSnMain);
        cipher.doFinal();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    System.arraycopy(key1, 0, snByte, 0, 4);
    System.arraycopy(key2, 0, snByte, 28, 4);
    System.arraycopy(encodedSnMain, 0, snByte, 4, 24);
    char[] snCharArray = Hex.encodeHex(snByte);
    String sn = new String(snCharArray);
    System.out.println("sn=" + sn);
}

From source file:net.labthink.run.DataStudioCrak.java

public static void main(String[] args) {
    String company = "Labthink";
    byte[] companyByteArray = company.getBytes();
    byte[] companyByteIntArray = intToByteArray(compute(companyByteArray, companyByteArray.length));
    // byte[] ff = "zhulixia".getBytes();
    byte[] snByte = new byte[32];
    byte[] byte1 = new byte[] { 7, 1 };
    byte[] byte2 = "zhaodapengpojiehahahahahaha".getBytes();
    byte[] byte3 = new byte[] { 127 };
    byte[] snMain = new byte[24];
    System.arraycopy(byte1, 0, snMain, 0, 2);
    System.arraycopy(byte2, 0, snMain, 2, 17);
    System.arraycopy(companyByteIntArray, 0, snMain, 19, 4);
    System.arraycopy(byte3, 0, snMain, 23, 1);
    //  1 - single license,2 - site license ,3 educational license
    snMain[2] = (byte) 1;
    int intSn = compute(snMain, snMain.length);
    System.out.println("intSn=" + intSn);
    byte[] key1 = "dddd".getBytes();
    byte[] key2 = intToByteArray(intSn);
    byte[] key = new byte[8];
    System.arraycopy(key1, 0, key, 0, 4);
    System.arraycopy(key2, 0, key, 4, 4);

    byte encodedSnMain[] = new byte[snMain.length];
    try {/*from ww  w .  java2  s .  c o  m*/
        DESKeySpec deskeyspec = new DESKeySpec(key);
        javax.crypto.SecretKey secretkey = SecretKeyFactory.getInstance("DES").generateSecret(deskeyspec);
        Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding");
        cipher.init(Cipher.ENCRYPT_MODE, secretkey);
        cipher.update(snMain, 0, snMain.length, encodedSnMain);
        cipher.doFinal();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    System.arraycopy(key1, 0, snByte, 0, 4);
    System.arraycopy(key2, 0, snByte, 28, 4);
    System.arraycopy(encodedSnMain, 0, snByte, 4, 24);
    char[] snCharArray = Hex.encodeHex(snByte);
    String sn = new String(snCharArray);
    System.out.println("sn=" + sn);
}