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:TestSign.java

/**
 * Method main/*  w  ww  .  jav a2 s.  c o  m*/
 *
 * @param unused
 * @throws Exception
 */
public static void main(String unused[]) throws Exception {
    //J-
    String keystoreType = "JKS";
    String keystoreFile = "data/org/apache/xml/security/samples/input/keystore.jks";
    String keystorePass = "xmlsecurity";
    String privateKeyAlias = "test";
    String privateKeyPass = "xmlsecurity";
    String certificateAlias = "test";
    File signatureFile = new File("signature.xml");
    //J+
    KeyStore ks = KeyStore.getInstance(keystoreType);
    FileInputStream fis = new FileInputStream(keystoreFile);

    ks.load(fis, keystorePass.toCharArray());

    PrivateKey privateKey = (PrivateKey) ks.getKey(privateKeyAlias, privateKeyPass.toCharArray());
    javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();

    dbf.setNamespaceAware(true);

    javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
    org.w3c.dom.Document doc = db.newDocument();
    String BaseURI = signatureFile.toURL().toString();
    XMLSignature sig = new XMLSignature(doc, BaseURI, XMLSignature.ALGO_ID_SIGNATURE_DSA);

    doc.appendChild(sig.getElement());

    {
        ObjectContainer obj = new ObjectContainer(doc);
        Element anElement = doc.createElementNS(null, "InsideObject");

        anElement.appendChild(doc.createTextNode("A text in a box"));
        obj.appendChild(anElement);

        String Id = "TheFirstObject";

        obj.setId(Id);
        sig.appendObject(obj);

        Transforms transforms = new Transforms(doc);

        transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
        sig.addDocument("#" + Id, transforms, Constants.ALGO_ID_DIGEST_SHA1);
    }

    {
        X509Certificate cert = (X509Certificate) ks.getCertificate(certificateAlias);

        sig.addKeyInfo(cert);
        sig.addKeyInfo(cert.getPublicKey());
        System.out.println("Start signing");
        sig.sign(privateKey);
        System.out.println("Finished signing");
    }

    FileOutputStream f = new FileOutputStream(signatureFile);

    XMLUtils.outputDOMc14nWithComments(doc, f);
    f.close();
    System.out.println("Wrote signature to " + BaseURI);

    for (int i = 0; i < sig.getSignedInfo().getSignedContentLength(); i++) {
        System.out.println("--- Signed Content follows ---");
        System.out.println(new String(sig.getSignedInfo().getSignedContentItem(i)));
    }
}

From source file:com.hsbc.frc.SevenHero.ClientProxyAuthentication.java

public static void main(String[] args) throws Exception {

    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {//from  w  ww . j  a  va  2s.c  om
        httpclient.getCredentialsProvider().setCredentials(new AuthScope("133.13.162.149", 8080),
                new UsernamePasswordCredentials("43668069", "wf^O^2013"));

        HttpHost targetHost = new HttpHost("pt.3g.qq.com");
        HttpHost proxy = new HttpHost("133.13.162.149", 8080);

        BasicClientCookie netscapeCookie = null;

        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        // httpclient.getCookieStore().addCookie(netscapeCookie);
        httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);

        HttpGet httpget = new HttpGet("/");
        httpget.addHeader("User-Agent",
                "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19");

        System.out.println("executing request: " + httpget.getRequestLine());
        System.out.println("via proxy: " + proxy);
        System.out.println("to target: " + targetHost);

        HttpResponse response = httpclient.execute(targetHost, httpget);

        HttpEntity entity = response.getEntity();

        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());

        if (entity != null) {
            System.out.println("Response content length: " + entity.getContentLength());
        }
        InputStream is = entity.getContent();
        StringBuffer sb = new StringBuffer(200);
        byte data[] = new byte[65536];
        int n = 1;
        do {
            n = is.read(data);
            if (n > 0) {
                sb.append(new String(data));
            }
        } while (n > 0);

        // System.out.println(sb);
        EntityUtils.consume(entity);

        System.out.println("----------------------------------------");
        Header[] headerlist = response.getAllHeaders();
        for (int i = 0; i < headerlist.length; i++) {
            Header header = headerlist[i];
            if (header.getName().equals("Set-Cookie")) {
                String setCookie = header.getValue();
                String cookies[] = setCookie.split(";");
                for (int j = 0; j < cookies.length; j++) {
                    String cookie[] = cookies[j].split("=");
                    CookieManager.cookie.put(cookie[0], cookie[1]);
                }
            }
            System.out.println(header.getName() + ":" + header.getValue());
        }
        String sid = getSid(sb.toString(), "&");
        System.out.println("sid: " + sid);

        httpclient = new DefaultHttpClient();
        httpclient.getCredentialsProvider().setCredentials(new AuthScope("133.13.162.149", 8080),
                new UsernamePasswordCredentials("43668069", "wf^O^2013"));
        String url = Constant.openUrl + "&" + sid;
        targetHost = new HttpHost(url);

        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        httpget = new HttpGet("/");
        httpget.addHeader("User-Agent",
                "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19");
        Iterator it = CookieManager.cookie.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            netscapeCookie = new BasicClientCookie((String) (key), (String) (value));
            netscapeCookie.setVersion(0);
            netscapeCookie.setDomain(".qq.com");
            netscapeCookie.setPath("/");
            // httpclient.getCookieStore().addCookie(netscapeCookie);
        }

        response = httpclient.execute(targetHost, httpget);

    } 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:com.hadoopvietnam.commons.crypt.J2MECrypto.java

public static void main(String[] args) {
    J2MECrypto crypto = new J2MECrypto("LetfyActionCrypto".getBytes());
    String code = System.currentTimeMillis() + " " + "tk1cntt@gmail.com" + " " + System.currentTimeMillis();
    String encode = new String(Base64.encodeBase64(crypto.encrypt((code).getBytes())));
    System.out.println(encode);/*from   w  w w  .j  a v  a2 s  . c  om*/
    String decode = new String(crypto.decrypt(Base64.decodeBase64(encode.getBytes())));
    System.out.println(decode);
    System.out.println(DigestUtils.md5Hex(code));
}

From source file:com.tcs.ebw.security.EBWSecurity.java

public static void main(String args[]) {

    try {//from   w ww  . j  a v a2 s .c o m

        EBWSecurity sec = new EBWSecurity();

        String testData2 = "Pramodh B Somashekara 231259 Channels !@#$%^&*()";

        if (args.length > 0)
            testData2 = (String) args[0];

        if (testData2 == null) {

            System.out.println("No Arguements in command line...Continuing with 'ELECTUSR'");

            testData2 = "ELECTUSR";

        }

        byte[] enc;

        System.out.println("----------------ENCRYPTION-------------");

        System.out.println("Original String:" + testData2);

        /** Set IMRS Key here **/

        sec.setSecretKey(sec.getSecretKey());

        testData2 = (new String(Base64.encodeBase64(sec.encryptSymmetric(testData2.getBytes()))));

        System.out.println("After Base64 Encode:" + testData2);

        testData2 = java.net.URLEncoder.encode(testData2, "utf-8");

        System.out.println("Encrypted[Base64+EncryptAlgo+URLEncoded][" + testData2 + "]");

        System.out.println("---------------DECRYPTION--------------");

        System.out.println("Encrypted[Base64+EncryptAlgo+URLEncoded]" + testData2);

        testData2 = java.net.URLDecoder.decode(testData2, "utf-8");

        testData2 = new String(sec.decryptSymmetric(
                Base64.decodeBase64(java.net.URLDecoder.decode(testData2, "utf-8").getBytes())));

        System.out.println("Decrypted[Base64+EncryptAlgo][" + testData2 + "]");

    } catch (NoSuchAlgorithmException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

    } catch (NoSuchPaddingException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

    } catch (BadPaddingException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

    } catch (InvalidKeyException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

    } catch (IllegalBlockSizeException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

    } catch (Exception e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

    }

}

From source file:WriteDoubleUsingSockets.java

public static void main(String args[]) {
    WriteDoubleUsingSockets showSavingAClassNet = new WriteDoubleUsingSockets();
    if (args.length < 2) {
        System.out.println("Usage: ServerName PortNumber");
        System.exit(0);/*from www.  jav  a 2 s.c  om*/
    } else {
        String ServerName = new String(args[0]); // Notice local scope of
                                                 // ServerName and PortNumber
        int PortNumber = Integer.parseInt(args[1]);
        showSavingAClassNet.initMain(ServerName, PortNumber);
    }
}

From source file:com.artistech.tuio.mouse.ZeroMqMouse.java

/**
 * Main entry point for ZeroMQ integration.
 *
 * @param args//from ww  w . j av  a  2  s  .  co m
 * @throws AWTException
 * @throws java.io.IOException
 */
public static void main(String[] args) throws AWTException, java.io.IOException {
    //read off the TUIO port from the command line
    String zeromq_port;

    Options options = new Options();
    options.addOption("z", "zeromq-port", true, "ZeroMQ Server:Port to subscribe to. (-z localhost:5565)");
    options.addOption("h", "help", false, "Show this message.");
    HelpFormatter formatter = new HelpFormatter();

    try {
        CommandLineParser parser = new org.apache.commons.cli.BasicParser();
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("help")) {
            formatter.printHelp("tuio-mouse-driver", options);
            return;
        } else {
            if (cmd.hasOption("z") || cmd.hasOption("zeromq-port")) {
                zeromq_port = cmd.getOptionValue("z");
            } else {
                System.err.println("The zeromq-port value must be specified.");
                formatter.printHelp("tuio-mouse-driver", options);
                return;
            }
        }
    } catch (ParseException ex) {
        System.err.println("Error Processing Command Options:");
        formatter.printHelp("tuio-mouse-driver", options);
        return;
    }

    //load conversion services
    ServiceLoader<ProtoConverter> services = ServiceLoader.load(ProtoConverter.class);

    //create zeromq context
    ZMQ.Context context = ZMQ.context(1);

    // Connect our subscriber socket
    ZMQ.Socket subscriber = context.socket(ZMQ.SUB);
    subscriber.setIdentity(ZeroMqMouse.class.getName().getBytes());

    //this could change I guess so we can get different data subscrptions.
    subscriber.subscribe("TuioCursor".getBytes());
    //        subscriber.subscribe("TuioTime".getBytes());
    subscriber.connect("tcp://" + zeromq_port);

    System.out.println("Subscribed to " + zeromq_port + " for ZeroMQ messages.");

    // Get updates, expect random Ctrl-C death
    String msg = "";
    MouseDriver md = new MouseDriver();
    while (!msg.equalsIgnoreCase("END")) {
        boolean success = false;
        byte[] recv = subscriber.recv();

        com.google.protobuf.GeneratedMessage message = null;
        TuioPoint pt = null;
        String type = recv.length > 0 ? new String(recv) : "";
        recv = subscriber.recv();
        switch (type) {
        case "TuioCursor.PROTOBUF":
            try {
                //it is a cursor?
                message = com.artistech.protobuf.TuioProtos.Cursor.parseFrom(recv);
                success = true;
            } catch (Exception ex) {
            }
            break;
        case "TuioTime.PROTOBUF":
            //                    try {
            //                        //it is a cursor?
            //                        message = com.artistech.protobuf.TuioProtos.Time.parseFrom(recv);
            //                        success = true;
            //                    } catch (Exception ex) {
            //                    }
            break;
        case "TuioObject.PROTOBUF":
            try {
                //it is a cursor?
                message = com.artistech.protobuf.TuioProtos.Object.parseFrom(recv);
                success = true;
            } catch (Exception ex) {
            }
            break;
        case "TuioBlob.PROTOBUF":
            try {
                //it is a cursor?
                message = com.artistech.protobuf.TuioProtos.Blob.parseFrom(recv);
                success = true;
            } catch (Exception ex) {
            }
            break;
        case "TuioCursor.JSON":
            try {
                //it is a cursor?
                pt = mapper.readValue(recv, TUIO.TuioCursor.class);
                success = true;
            } catch (Exception ex) {
            }
            break;
        case "TuioTime.JSON":
            //                    try {
            //                        //it is a cursor?
            //                        pt = mapper.readValue(recv, TUIO.TuioTime.class);
            //                        success = true;
            //                    } catch (Exception ex) {
            //                    }
            break;
        case "TuioObject.JSON":
            try {
                //it is a cursor?
                pt = mapper.readValue(recv, TUIO.TuioObject.class);
                success = true;
            } catch (Exception ex) {
            }
            break;
        case "TuioBlob.JSON":
            try {
                //it is a cursor?
                pt = mapper.readValue(recv, TUIO.TuioBlob.class);
                success = true;
            } catch (Exception ex) {
            }
            break;
        case "TuioTime.OBJECT":
            break;
        case "TuioCursor.OBJECT":
        case "TuioObject.OBJECT":
        case "TuioBlob.OBJECT":
            try {
                //Try reading the data as a serialized Java object:
                try (ByteArrayInputStream bis = new ByteArrayInputStream(recv)) {
                    //Try reading the data as a serialized Java object:
                    ObjectInput in = new ObjectInputStream(bis);
                    Object o = in.readObject();
                    //if it is of type Point (Cursor, Object, Blob), process:
                    if (TuioPoint.class.isAssignableFrom(o.getClass())) {
                        pt = (TuioPoint) o;
                        process(pt, md);
                    }

                    success = true;
                }
            } catch (java.io.IOException | ClassNotFoundException ex) {
            } finally {
            }
            break;
        default:
            success = false;
            break;
        }

        if (message != null && success) {
            //ok, so we have a message that is not null, so it was protobuf:
            Object o = null;

            //look for a converter that will suppor this objec type and convert:
            for (ProtoConverter converter : services) {
                if (converter.supportsConversion(message)) {
                    o = converter.convertFromProtobuf(message);
                    break;
                }
            }

            //if the type is of type Point (Cursor, Blob, Object), process:
            if (o != null && TuioPoint.class.isAssignableFrom(o.getClass())) {
                pt = (TuioPoint) o;
            }
        }

        if (pt != null) {
            process(pt, md);
        }
    }
}

From source file:com.mirth.connect.plugins.datatypes.ncpdp.test.NCPDPTest.java

public static void main(String[] args) throws Exception {
    String testMessage = "";
    ArrayList<String> testFiles = new ArrayList<String>();
    testFiles.add("C:\\NCPDP_51_B1_Request.txt");
    testFiles.add("C:\\NCPDP_51_B1_Request_v2.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v4.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v5.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v6.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v7.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v8.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v9.txt");
    testFiles.add("C:\\NCPDP_51_B2_Request.txt");
    testFiles.add("C:\\NCPDP_51_B2_Request_v2.txt");
    testFiles.add("C:\\NCPDP_51_B2_Response.txt");
    testFiles.add("C:\\NCPDP_51_B2_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_B2_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_B3_Request.txt");
    testFiles.add("C:\\NCPDP_51_B3_Response.txt");
    testFiles.add("C:\\NCPDP_51_B3_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_B3_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_E1_Request.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v4.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v5.txt");
    testFiles.add("C:\\NCPDP_51_N1_Request.txt");
    testFiles.add("C:\\NCPDP_51_N2_Request.txt");
    testFiles.add("C:\\NCPDP_51_P1_Request.txt");
    testFiles.add("C:\\NCPDP_51_P1_Response.txt");
    testFiles.add("C:\\NCPDP_51_P1_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_P1_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_P2_Request.txt");
    testFiles.add("C:\\NCPDP_51_P2_Response.txt");
    testFiles.add("C:\\NCPDP_51_P3_Request.txt");
    testFiles.add("C:\\NCPDP_51_P3_Response.txt");
    testFiles.add("C:\\NCPDP_51_P3_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_P4_Request.txt");
    testFiles.add("C:\\NCPDP_51_P4_Response.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_1.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_2.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_3.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_4.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_5.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_6.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_7.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_8.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_9.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_10.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_11.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_12.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_13.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_14.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_15.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_16.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_17.txt");

    for (String testFile : testFiles) {
        testMessage = new String(FileUtils.readFileToByteArray(new File(testFile)));
        System.out.println("Processing test file:" + testFile);

        try {//from  ww  w  .j av  a 2  s  .c  o  m
            long totalExecutionTime = 0;
            int iterations = 1;
            for (int i = 0; i < iterations; i++) {
                totalExecutionTime += runTest(testMessage);
            }

            //System.out.println("Execution time average: " + totalExecutionTime/iterations + " ms");
        }
        // System.out.println(new X12Serializer().serialize("SEG*1*2**4*5"));
        catch (SAXException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.mirth.connect.model.converters.tests.NCPDPTest.java

public static void main(String[] args) throws Exception {
    String testMessage = "";
    ArrayList<String> testFiles = new ArrayList<String>();
    testFiles.add("C:\\NCPDP_51_B1_Request.txt");
    testFiles.add("C:\\NCPDP_51_B1_Request_v2.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v4.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v5.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v6.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v7.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v8.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v9.txt");
    testFiles.add("C:\\NCPDP_51_B2_Request.txt");
    testFiles.add("C:\\NCPDP_51_B2_Request_v2.txt");
    testFiles.add("C:\\NCPDP_51_B2_Response.txt");
    testFiles.add("C:\\NCPDP_51_B2_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_B2_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_B3_Request.txt");
    testFiles.add("C:\\NCPDP_51_B3_Response.txt");
    testFiles.add("C:\\NCPDP_51_B3_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_B3_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_E1_Request.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v4.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v5.txt");
    testFiles.add("C:\\NCPDP_51_N1_Request.txt");
    testFiles.add("C:\\NCPDP_51_N2_Request.txt");
    testFiles.add("C:\\NCPDP_51_P1_Request.txt");
    testFiles.add("C:\\NCPDP_51_P1_Response.txt");
    testFiles.add("C:\\NCPDP_51_P1_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_P1_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_P2_Request.txt");
    testFiles.add("C:\\NCPDP_51_P2_Response.txt");
    testFiles.add("C:\\NCPDP_51_P3_Request.txt");
    testFiles.add("C:\\NCPDP_51_P3_Response.txt");
    testFiles.add("C:\\NCPDP_51_P3_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_P4_Request.txt");
    testFiles.add("C:\\NCPDP_51_P4_Response.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_1.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_2.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_3.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_4.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_5.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_6.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_7.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_8.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_9.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_10.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_11.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_12.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_13.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_14.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_15.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_16.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_17.txt");

    for (String testFile : testFiles) {
        testMessage = new String(FileUtils.readFileToByteArray(new File(testFile)));
        System.out.println("Processing test file:" + testFile);

        try {/*ww  w . j a  v  a2  s. c  om*/
            long totalExecutionTime = 0;
            int iterations = 1;
            for (int i = 0; i < iterations; i++) {
                totalExecutionTime += runTest(testMessage);
            }

            //System.out.println("Execution time average: " + totalExecutionTime/iterations + " ms");
        }
        // System.out.println(new X12Serializer().toXML("SEG*1*2**4*5"));
        catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:com.github.trohovsky.jira.analyzer.Main.java

public static void main(String[] args) throws Exception {

    final Options options = new Options();
    options.addOption("u", true, "username");
    options.addOption("p", true, "password (optional, if not provided, the password is prompted)");
    options.addOption("h", false, "show this help");
    options.addOption("s", true,
            "use the strategy for querying and output, the strategy can be either 'issues_toatal' (default) or"
                    + " 'per_month'");
    options.addOption("d", true, "CSV delimiter");

    // parsing of the command line arguments
    final CommandLineParser parser = new DefaultParser();
    CommandLine cmdLine = null;/*from ww  w. j ava2s .  c o m*/
    try {
        cmdLine = parser.parse(options, args);
        if (cmdLine.hasOption('h') || cmdLine.getArgs().length == 0) {
            final HelpFormatter formatter = new HelpFormatter();
            formatter.setOptionComparator(null);
            formatter.printHelp(HELP_CMDLINE, HELP_HEADER, options, null);
            return;
        }
        if (cmdLine.getArgs().length != 3) {
            throw new ParseException("You should specify exactly three arguments JIRA_SERVER JQL_QUERY_TEMPLATE"
                    + " PATH_TO_PARAMETER_FILE");
        }
    } catch (ParseException e) {
        System.err.println("Error parsing command line: " + e.getMessage());
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(HELP_CMDLINE, HELP_HEADER, options, null);
        return;
    }
    final String csvDelimiter = (String) (cmdLine.getOptionValue('d') != null ? cmdLine.getOptionObject('d')
            : CSV_DELIMITER);

    final URI jiraServerUri = URI.create(cmdLine.getArgs()[0]);
    final String jqlQueryTemplate = cmdLine.getArgs()[1];
    final List<List<String>> queryParametersData = readCSVFile(cmdLine.getArgs()[2], csvDelimiter);
    final String username = cmdLine.getOptionValue("u");
    String password = cmdLine.getOptionValue("p");
    final String strategy = cmdLine.getOptionValue("s");

    try {
        // initialization of the REST client
        final AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
        if (username != null) {
            if (password == null) {
                final Console console = System.console();
                final char[] passwordCharacters = console.readPassword("Password: ");
                password = new String(passwordCharacters);
            }
            restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, username, password);
        } else {
            restClient = factory.create(jiraServerUri, new AnonymousAuthenticationHandler());
        }
        final SearchRestClient searchRestClient = restClient.getSearchClient();

        // choosing of an analyzer strategy
        AnalyzerStrategy analyzer = null;
        if (strategy != null) {
            switch (strategy) {
            case "issues_total":
                analyzer = new IssuesTotalStrategy(searchRestClient);
                break;
            case "issues_per_month":
                analyzer = new IssuesPerMonthStrategy(searchRestClient);
                break;
            default:
                System.err.println("The strategy does not exist");
                return;
            }
        } else {
            analyzer = new IssuesTotalStrategy(searchRestClient);
        }

        // analyzing
        for (List<String> queryParameters : queryParametersData) {
            analyzer.analyze(jqlQueryTemplate, queryParameters);
        }
    } finally {
        // destroy the REST client, otherwise it stucks
        restClient.close();
    }
}

From source file:io.covert.binary.analysis.ExecutorThread.java

public static void main(String[] args) throws Exception {

    HashMap<String, Object> substitutionMap = new HashMap<String, Object>();
    substitutionMap.put("file", "/home/jtrost/workspace/hadoop-binary-analysis/pom.xml");

    ExecutorThread e = new ExecutorThread("sha1sum", new String[] { "${file}" }, substitutionMap,
            new int[] { 0, 1 }, Long.MAX_VALUE, new File("/tmp"));
    e.start();/*from  w w  w .j a v  a2 s . c  o m*/
    e.join();

    System.out.println("exitCode = " + e.getExitCode());
    System.out.println("exitCode = " + e.getExecuteException());

    if (e.isProcessStarted() && !e.isProcessDestroyed()) {
        System.out.println("stdout: " + new String(e.getStdOut().toByteArray()));
        System.out.println("stderr: " + new String(e.getStdErr().toByteArray()));
    } else if (e.isProcessStarted()) {
        System.out.println("Process was launched, but process destroyed");
    } else {
        System.out.println("Process not launched");
    }
}