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:net.itransformers.bgpPeeringMap.DavidPiegzaFormatTransformer.java

public static void main(String[] args) throws Exception {
    ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream();

    XsltTransformer transformer = new XsltTransformer();
    File xsltFileName1 = new File("/Users/niau/trunk/bgpPeeringMap/conf/xslt/david_piegza.xslt");
    byte[] rawData = readRawDataFile("/Users/niau/test1/network/version1/undirected/imap.graphml");
    ByteArrayInputStream inputStream1 = new ByteArrayInputStream(rawData);
    transformer.transformXML(inputStream1, xsltFileName1, outputStream1, null, null);
    File outputFile1 = new File("/Users/niau/trunk/bgpPeeringMap/src/main/resources", "imap.xml");
    FileUtils.writeStringToFile(outputFile1, new String(outputStream1.toByteArray()));

}

From source file:loanbroker.normalizer.NormalizerOurSoapXmlBank.java

public static void main(String[] argv) throws IOException, InterruptedException, TimeoutException {
    //Connection//  w  w w.ja  v  a 2  s .  c om
    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.queueBind(queueName, EXCHANGE_NAME, "");
    QueueingConsumer consumer = new QueueingConsumer(channel);
    channel.basicConsume(queueName, true, consumer);
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

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

    LoanResponse loanResponse;
    DtoOurSoapXmlBank dtoOurSoapXmlBank;
    while (true) {
        QueueingConsumer.Delivery delivery = consumer.nextDelivery();
        String message = new String(delivery.getBody());
        String routingKey = delivery.getEnvelope().getRoutingKey();

        dtoOurSoapXmlBank = JAXB.unmarshal(new StringReader(message), DtoOurSoapXmlBank.class);
        loanResponse = new LoanResponse(dtoOurSoapXmlBank.getSsn(), dtoOurSoapXmlBank.getInterestRate(),
                "Our Soap Xml bank", delivery.getProperties().getCorrelationId());
        // loanResponse.setBank(routingKey);

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

From source file:org.salever.rcp.remoteSystem.server.util.ClientAbortMethod.java

public final static void main(String[] args) throws Exception {
    HttpClient httpclient = new DefaultHttpClient();
    try {/*from   w  ww .  j av  a 2s  . c o  m*/

        String queryString = "wd=?ddd=";
        String decodeUrl = URLEncoder.encode(queryString, "GBK");
        String string = new String(decodeUrl);
        System.out.println("--------------" + string + "--------------------------");
        HttpGet httpget = new HttpGet("http://www.baidu.com/s?" + string);

        System.out.println("executing request " + httpget.getURI());
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();

        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        if (entity != null) {
            System.out.println("Response content length: " + entity.getContentLength());
            BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
            String line;
            while ((line = reader.readLine()) != null) {
                // System.out.println(line);
            }
        }
        System.out.println("----------------------------------------");

    } finally {
        // 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:org.spring.resource.FileSourceExample.java

public static void main(String[] args) {
    try {//from   w  ww.  j  a  v  a 2  s.  c o  m
        String filePath = "E:\\JEELearning\\ideaworlplace\\springdream\\springdream.ioc\\src\\main\\resources\\FileSource.txt";
        // ?
        Resource res1 = new FileSystemResource(filePath);
        // ?
        Resource res2 = new ClassPathResource("FileSource.txt");

        System.out.println("?:" + res1.getFilename());
        System.out.println("?:" + res2.getFilename());

        InputStream in1 = res1.getInputStream();
        InputStream in2 = res2.getInputStream();
        //            System.out.println("?:" + read(in1));
        //            System.out.println("?:" + read(in2));
        System.out.println("?:" + new String(FileCopyUtils.copyToByteArray(in1)));
        System.out.println("?:" + new String(FileCopyUtils.copyToByteArray(in2)));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:SyncMultipleLeads.java

public static void main(String[] args) {
    System.out.println("Executing syncMultipleLeads");
    try {/*from w  ww . ja  v  a  2s  .co m*/
        URL marketoSoapEndPoint = new URL("https://100-AEK-913.mktoapi.com/soap/mktows/2_1" + "?WSDL");
        String marketoUserId = "demo17_1_809934544BFABAE58E5D27";
        String marketoSecretKey = "27272727aa";

        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
        ParamsSyncMultipleLeads request = new ParamsSyncMultipleLeads();

        ObjectFactory objectFactory = new ObjectFactory();

        JAXBElement<Boolean> dedup = objectFactory.createParamsSyncMultipleLeadsDedupEnabled(true);
        request.setDedupEnabled(dedup);

        ArrayOfLeadRecord arrayOfLeadRecords = new ArrayOfLeadRecord();

        // Create First Lead Record
        LeadRecord rec1 = new LeadRecord();

        JAXBElement<String> email = objectFactory.createLeadRecordEmail("t@t.com");
        rec1.setEmail(email);

        Attribute attr1 = new Attribute();
        attr1.setAttrName("FirstName");
        attr1.setAttrValue("George");

        Attribute attr2 = new Attribute();
        attr2.setAttrName("LastName");
        attr2.setAttrValue("of the Jungle");

        ArrayOfAttribute aoa = new ArrayOfAttribute();
        aoa.getAttributes().add(attr1);
        aoa.getAttributes().add(attr2);

        QName qname = new QName("http://www.marketo.com/mktows/", "leadAttributeList");
        JAXBElement<ArrayOfAttribute> attrList = new JAXBElement(qname, ArrayOfAttribute.class, aoa);

        rec1.setLeadAttributeList(attrList);
        arrayOfLeadRecords.getLeadRecords().add(rec1);

        // Create Second Lead Record
        LeadRecord rec2 = new LeadRecord();

        JAXBElement<String> email2 = objectFactory.createLeadRecordEmail("myemail@test.com");
        rec2.setEmail(email2);

        Attribute attr11 = new Attribute();
        attr11.setAttrName("FirstName");
        attr11.setAttrValue("Nancy");

        Attribute attr21 = new Attribute();
        attr21.setAttrName("LastName");
        attr21.setAttrValue("Lady");

        ArrayOfAttribute aoa2 = new ArrayOfAttribute();
        aoa2.getAttributes().add(attr11);
        aoa2.getAttributes().add(attr21);

        qname = new QName("http://www.marketo.com/mktows/", "leadAttributeList");
        JAXBElement<ArrayOfAttribute> attrList2 = new JAXBElement(qname, ArrayOfAttribute.class, aoa2);

        rec2.setLeadAttributeList(attrList);
        arrayOfLeadRecords.getLeadRecords().add(rec2);

        request.setLeadRecordList(arrayOfLeadRecords);

        SuccessSyncMultipleLeads result = port.syncMultipleLeads(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessSyncMultipleLeads.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:GetLeadChanges.java

public static void main(String[] args) {
    System.out.println("Executing Get Lead Changes");
    try {/*  w w  w .j a v a 2  s .  c  om*/
        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
        ParamsGetLeadChanges request = new ParamsGetLeadChanges();

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

        ArrayOfString activities = new ArrayOfString();
        activities.getStringItems().add("Visit Webpage");
        activities.getStringItems().add("Click Link");

        JAXBElement<ArrayOfString> activityFilter = objectFactory
                .createParamsGetLeadChangesActivityNameFilter(activities);
        request.setActivityNameFilter(activityFilter);

        // Create oldestCreateAt timestamp from 5 days ago
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTimeInMillis(new Date().getTime());
        gc.add(GregorianCalendar.DAY_OF_YEAR, -5);

        DatatypeFactory factory = DatatypeFactory.newInstance();
        JAXBElement<XMLGregorianCalendar> oldestCreateAtValue = objectFactory
                .createStreamPositionOldestCreatedAt(factory.newXMLGregorianCalendar(gc));

        StreamPosition sp = new StreamPosition();
        sp.setOldestCreatedAt(oldestCreateAtValue);
        request.setStartPosition(sp);

        SuccessGetLeadChanges result = port.getLeadChanges(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessGetLeadChanges.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:net.dv8tion.jda.player.Bot.java

public static void main(String[] args) {
    try {//from w  w w . ja v a2  s. co m
        JSONObject obj = new JSONObject(new String(Files.readAllBytes(Paths.get("Config.json"))));
        JDA api = new JDABuilder().setBotToken(obj.getString("botToken")).addListener(new Bot())
                .buildBlocking();

    } catch (IllegalArgumentException e) {
        System.out.println("The config was not populated. Please provide a token.");
    } catch (LoginException e) {
        System.out.println("The provided botToken was incorrect. Please provide valid details.");
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        System.err.println(
                "Encountered a JSON error. Most likely caused due to an outdated or ill-formated config.\n"
                        + "Please delete the config so that it can be regenerated. JSON Error:\n");
        e.printStackTrace();
    } catch (IOException e) {
        JSONObject obj = new JSONObject();
        obj.put("botToken", "");
        try {
            Files.write(Paths.get("Config.json"), obj.toString(4).getBytes());
            System.out.println("No config file was found. Config.json has been generated, please populate it!");
        } catch (IOException e1) {
            System.out.println("No config file was found and we failed to generate one.");
            e1.printStackTrace();
        }
    }
}

From source file:ImportToList.java

public static void main(String[] args) {
    System.out.println("Executing Import To List");
    try {/*w  w  w  .  j  a v  a2 s.co 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
        ParamsImportToList request = new ParamsImportToList();

        request.setProgramName("Trav-Demo-Program");
        request.setCampaignName("Batch Campaign Example");
        request.setImportFileHeader("Last Name,First Name,Job Title,Company Name,Email Address");

        ArrayOfString rows = new ArrayOfString();
        rows.getStringItems().add("Awesomesauce,Developer,Code Slinger,Marketo,dawesomesauce@marketo.com");
        rows.getStringItems().add("Doe,Jane,VP Marketing,Jane Consulting,jdoe@janeconsulting.com");
        request.setImportFileRows(rows);

        request.setImportListMode(ImportToListModeEnum.UPSERTLEADS);
        request.setListName("Trav-Test-List");
        request.setClearList(false);

        SuccessImportToList result = port.importToList(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessImportToList.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:ScheduleCampaign.java

public static void main(String[] args) {
    System.out.println("Executing Schedule Campaign");
    try {/*from   w w w. j  a  va 2s . com*/
        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
        ParamsScheduleCampaign request = new ParamsScheduleCampaign();

        request.setProgramName("Trav-Demo-Program");
        request.setCampaignName("Batch Campaign Example");

        // Create setCampaignRunAt timestamp
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTimeInMillis(new Date().getTime());

        DatatypeFactory factory = DatatypeFactory.newInstance();
        ObjectFactory objectFactory = new ObjectFactory();
        JAXBElement<XMLGregorianCalendar> setCampaignRunAtValue = objectFactory
                .createParamsScheduleCampaignCampaignRunAt(factory.newXMLGregorianCalendar(gc));
        request.setCampaignRunAt(setCampaignRunAtValue);

        request.setCloneToProgramName("TestProgramCloneFromSOAP");

        ArrayOfAttrib aoa = new ArrayOfAttrib();

        Attrib attrib = new Attrib();
        attrib.setName("{{my.message}}");
        attrib.setValue("Updated message");

        aoa.getAttribs().add(attrib);

        JAXBElement<ArrayOfAttrib> arrayOfAttrib = objectFactory
                .createParamsScheduleCampaignProgramTokenList(aoa);
        request.setProgramTokenList(arrayOfAttrib);

        SuccessScheduleCampaign result = port.scheduleCampaign(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessScheduleCampaign.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:com.sm.test.TestClient.java

public static void main(String[] args) {
    ccf = ClusterClientFactory.connect(HOST_CONNECT_URL, STORENAME);
    client = ccf.getDefaultStore();//from  ww w  . j a va2s.  c  o m
    while (true) {
        try {
            long time = System.currentTimeMillis() / 1000;
            ByteArrayConverter converter = new ByteArrayConverter();
            Key<ByteArray> key = Key.createKey(new ByteArray("1.abcdef".getBytes()));
            Bar bar = new Bar();
            client.put(key, new ByteArray("FooBar".getBytes()));
            Value<ByteArray> value = client.get(key);
            System.out.println("" + new String(value.getData().get()));
            try {
                Thread.sleep(3000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        if (false)
            break;
    }
    client.close();
    ccf.close();
}