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

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

   MulticastSocket socket = new MulticastSocket(4446);
   InetAddress address = InetAddress.getByName("230.0.0.1");
   socket.joinGroup(address);/*from  www. j a  v  a  2s .  c  o  m*/

   DatagramPacket packet;

   // get a few quotes
   for (int i = 0; i < 5; i++) {

      byte[] buf = new byte[256];
      packet = new DatagramPacket(buf, buf.length);
      socket.receive(packet);

      String received = new String(packet.getData());
      System.out.println("Quote of the Moment: " + received);
   }

   socket.leaveGroup(address);
   socket.close();
}

From source file:net.padlocksoftware.padlock.keymaker.Main.java

/**
 * @param args the command line arguments
 *//*w  w w .j a  v a 2  s. c  om*/
public static void main(String[] args) {

    int keySize = 1024;
    File file = null;

    if (args.length < 1 || args.length > 3) {
        showUsageAndExit();
    }

    for (int x = 0; x < args.length; x++) {
        String arg = args[x];

        if (arg.equals("-s")) {
            try {
                x++;
            } catch (Exception e) {
                showUsageAndExit();
            }
        } else {
            file = new File(arg);
        }
    }

    KeyPair pair = KeyManager.createKeyPair();
    try {
        KeyManager.exportKeyPair(pair, file);
        String[] lines = formatOutput(new String(Hex.encodeHex(pair.getPublic().getEncoded())));
        System.out.println("Your public key code: \n");
        for (int x = 0; x < lines.length; x++) {
            String line = lines[x];
            if (x == 0) {
                // First line
                System.out.println("\t private static final String publicKey = \n\t\t\"" + line + "\" + ");
            } else if (x == lines.length - 1) {
                // Last line
                System.out.println("\t\t\"" + line + "\";\n");
            } else {
                System.out.println("\t\t\"" + line + "\" + ");
            }
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:RSA.java

/** Trivial test program. */
public static void main(String[] args) {
    RSA rsa = new RSA(1024);

    String text1 = "Yellow and Black Border Collies";
    System.out.println("Plaintext: " + text1);
    BigInteger plaintext = new BigInteger(text1.getBytes());

    BigInteger ciphertext = rsa.encrypt(plaintext);
    System.out.println("Ciphertext: " + ciphertext);
    plaintext = rsa.decrypt(ciphertext);

    String text2 = new String(plaintext.toByteArray());
    System.out.println("Plaintext: " + text2);
}

From source file:edu.uci.ics.asterix.transaction.management.service.locking.LockManagerDeterministicUnitTest.java

public static void main(String args[]) throws ACIDException, IOException, AsterixException {
    //prepare configuration file
    File cwd = new File(System.getProperty("user.dir"));
    File asterixdbDir = cwd.getParentFile();
    File srcFile = new File(asterixdbDir.getAbsoluteFile(),
            "asterix-app/src/main/resources/asterix-build-configuration.xml");
    File destFile = new File(cwd, "target/classes/asterix-configuration.xml");
    FileUtils.copyFile(srcFile, destFile);

    //initialize controller thread
    String requestFileName = new String(
            "src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/LockRequestFile");
    Thread t = new Thread(new LockRequestController(requestFileName));
    t.start();//w w  w.j av a  2  s .c om
}

From source file:com.booktrack.vader.Main.java

/**
 * main entry point and demo case for Vader
 * @param args the arguments - explained below in the code
 * @throws Exception anything goes wrong - except
 *///from  ww w . j a va  2 s .  c o m
public static void main(String[] args) throws Exception {

    // create Options object for command line parsing
    Options options = new Options();
    options.addOption("file", true, "input text-file (-file) to read and analyse using Vader");

    CommandLineParser cmdParser = new DefaultParser();
    CommandLine line = null;
    try {
        // parse the command line arguments
        line = cmdParser.parse(options, args);
    } catch (ParseException exp) {
        // oops, something went wrong
        logger.error("invalid command line: " + exp.getMessage());
        System.exit(0);
    }

    // get the command line argument -file
    String inputFile = line.getOptionValue("file");
    if (inputFile == null) {
        help(options);
        System.exit(0);
    }
    if (!new File(inputFile).exists()) {
        logger.error("file does not exist: " + inputFile);
        System.exit(0);
    }

    // example use of the classes
    // read the entire input file
    String fileText = new String(Files.readAllBytes(Paths.get(inputFile)));

    // setup Vader
    Vader vader = new Vader();
    vader.init(); // load vader

    // setup nlp processor
    VaderNLP vaderNLP = new VaderNLP();
    vaderNLP.init(); // load open-nlp

    // parse the text into a set of sentences
    List<List<Token>> sentenceList = vaderNLP.parse(fileText);

    // apply vader analysis to each sentence
    for (List<Token> sentence : sentenceList) {
        VScore vaderScore = vader.analyseSentence(sentence);
        logger.info("sentence:" + Token.tokenListToString(sentence));
        logger.info("Vader score:" + vaderScore.toString());
    }

}

From source file:org.mitre.mpf.rest.client.Main.java

public static void main(String[] args) throws RestClientException, IOException, InterruptedException {
    System.out.println("Starting rest-client!");

    //not necessary for localhost, but left if a proxy configuration is needed
    //System.setProperty("http.proxyHost","");
    //System.setProperty("http.proxyPort","");  

    String currentDirectory;/*from  w w w  .j av  a  2 s .c  o  m*/
    currentDirectory = System.getProperty("user.dir");
    System.out.println("Current working directory : " + currentDirectory);

    String username = "mpf";
    String password = "mpf123";
    byte[] encodedBytes = Base64.encodeBase64((username + ":" + password).getBytes());
    String base64 = new String(encodedBytes);
    System.out.println("encodedBytes " + base64);
    final String mpfAuth = "Basic " + base64;

    RequestInterceptor authorize = new RequestInterceptor() {
        @Override
        public void intercept(HttpRequestBase request) {
            request.addHeader("Authorization", mpfAuth /*credentials*/);
        }
    };

    //RestClient client = RestClient.builder().requestInterceptor(authorize).build();
    CustomRestClient client = (CustomRestClient) CustomRestClient.builder()
            .restClientClass(CustomRestClient.class).requestInterceptor(authorize).build();

    //getAvailableWorkPipelineNames
    String url = "http://localhost:8080/workflow-manager/rest/pipelines";
    Map<String, String> params = new HashMap<String, String>();
    List<String> availableWorkPipelines = client.get(url, params, new TypeReference<List<String>>() {
    });
    System.out.println("availableWorkPipelines size: " + availableWorkPipelines.size());
    System.out.println(Arrays.toString(availableWorkPipelines.toArray()));

    //processMedia        
    JobCreationRequest jobCreationRequest = new JobCreationRequest();
    URI uri = Paths.get(currentDirectory,
            "/trunk/workflow-manager/src/test/resources/samples/meds/aa/S001-01-t10_01.jpg").toUri();
    jobCreationRequest.getMedia().add(new JobCreationMediaData(uri.toString()));
    uri = Paths.get(currentDirectory,
            "/trunk/workflow-manager/src/test/resources/samples/meds/aa/S008-01-t10_01.jpg").toUri();
    jobCreationRequest.getMedia().add(new JobCreationMediaData(uri.toString()));
    jobCreationRequest.setExternalId("external id");

    //get first DLIB pipeline
    String firstDlibPipeline = availableWorkPipelines.stream()
            //.peek(pipepline -> System.out.println("will filter - " + pipepline))
            .filter(pipepline -> pipepline.startsWith("DLIB")).findFirst().get();

    System.out.println("found firstDlibPipeline: " + firstDlibPipeline);

    jobCreationRequest.setPipelineName(firstDlibPipeline); //grabbed from 'rest/pipelines' - see #1
    //two optional params
    jobCreationRequest.setBuildOutput(true);
    //jobCreationRequest.setPriority(priority); //will be set to 4 (default) if not set
    JobCreationResponse jobCreationResponse = client.customPostObject(
            "http://localhost:8080/workflow-manager/rest/jobs", jobCreationRequest, JobCreationResponse.class);
    System.out.println("jobCreationResponse job id: " + jobCreationResponse.getJobId());

    System.out.println("\n---Sleeping for 10 seconds to let the job process---\n");
    Thread.sleep(10000);

    //getJobStatus
    url = "http://localhost:8080/workflow-manager/rest/jobs"; // /status";
    params = new HashMap<String, String>();
    //OPTIONAL
    //params.put("v", "") - no versioning currently implemented         
    //id is now a path var - if not set, all job info will returned
    url = url + "/" + Long.toString(jobCreationResponse.getJobId());
    SingleJobInfo jobInfo = client.get(url, params, SingleJobInfo.class);
    System.out.println("jobInfo id: " + jobInfo.getJobId());

    //getSerializedOutput
    String jobIdToGetOutputStr = Long.toString(jobCreationResponse.getJobId());
    url = "http://localhost:8080/workflow-manager/rest/jobs/" + jobIdToGetOutputStr + "/output/detection";
    params = new HashMap<String, String>();
    //REQUIRED  - job id is now a path var and required for this endpoint
    String serializedOutput = client.getAsString(url, params);
    System.out.println("serializedOutput: " + serializedOutput);
}

From source file:com.sm.store.TestHessianPhp.java

public static void main(String[] args) throws Exception {
    HessianSerializer hs = new HessianSerializer();
    //        Map<String, String> map = new HashMap<String, String>();
    //        map.put("Header", "com.sm.message.Header");
    //        map.put("StoreParas", "com.sm.store.StoreParas");
    //        map.put("Value","com.sm.store.Value");
    //        map.put("array", "java.util.HashMap");
    HessianPhp hessianPhp = new HessianPhp(getNameMap());
    Map<String, Header> mapH = new HashMap<String, Header>();
    mapH.put("key-1", new Header("test-1", 1, (byte) 2, 3));
    mapH.put("key-2", new Header("test-2", 2, (byte) 3, 4));
    //        byte[] m1 = hs.toBytes( mapH);
    //        System.out.println("m1 "+m1.length);
    //        Header hd = new Header("test-1", 2, (byte)1, 3);
    //        byte[] d2 = hs.toBytes( hd);
    //        HessianReader reader = new HessianReader( m1);
    //        reader.readObject();
    //        System.out.println(new String( reader.getBytes()));
    List list = new ArrayList();
    list.add(new Header("test-1", 1, (byte) 2, 3));
    list.add(new Header("test-2", 2, (byte) 3, 4));
    byte[] d3 = hs.toBytes(list);
    HessianReader reader = new HessianReader(d3);
    reader.readObject();// w  w w. j a  v a 2 s. c o  m
    System.out.println(new String(reader.getBytes()));
    //        byte[] data = hessianPhp.php2Hessian( header.getBytes());
    //        Header header = new Header("test-1",10, (byte) 3,1 );
    //        byte[] d1 = hs.toBytes( header);
    //logger.info("len "+data.length+" "+d1.length);
    //Object obj = hs.toObject(data);
    //logger.info(obj.getClass().getName()+" obj "+obj.toString());
    //        byte[] s1 = hessianPhp.php2Hessian( storePara.getBytes());
    //        Object obj = hs.toObject( s1);
    //        logger.info(obj.toString());

}

From source file:backtype.storm.security.serialization.BlowfishTupleSerializer.java

/**
 * Produce a blowfish key to be used in "Storm jar" command
 *///from   w w w .j  a  v  a 2 s  .co  m
public static void main(String[] args) {
    try {
        KeyGenerator kgen = KeyGenerator.getInstance("Blowfish");
        SecretKey skey = kgen.generateKey();
        byte[] raw = skey.getEncoded();
        String keyString = new String(Hex.encodeHex(raw));
        System.out.println("storm -c " + SECRET_KEY + "=" + keyString + " -c "
                + Config.TOPOLOGY_TUPLE_SERIALIZER + "=" + BlowfishTupleSerializer.class.getName() + " ...");
    } catch (Exception ex) {
        LOG.error(ex.getMessage());
        ex.printStackTrace();
    }
}

From source file:gov.nih.nci.cadsr.cadsrpasswordchange.core.OracleObfuscation.java

public static void main(String[] args) throws Exception {
    OracleObfuscation x = new OracleObfuscation("$_12345&"); // just a
    // random// www.j a  va 2 s  .  co m
    // pick for
    // testing
    String text = CommonUtil.pad("BB", Constants.MAX_ANSWER_LENGTH); //args[0];

    byte[] encrypted = x.encrypt(text.getBytes());
    String encoded = new String(Hex.encodeHex(encrypted));
    System.out.println("Encrypted/Encoded: \"" + encoded + "\"");

    byte[] decoded = Hex.decodeHex(encoded.toCharArray());
    String decrypted = new String(x.decrypt(decoded));
    //      String decrypted = new String(x.decrypt(encrypted));
    System.out.println("Decoded/Decrypted: \"" + decrypted + "\"");
}

From source file:com.taobao.metamorphosis.client.http.SimpleHttpClientUnitTest.java

/**
 * Use main because it will quit after main flow of test finish running if
 * using test case.//from  w w w . jav  a  2s. c o m
 * 
 * @param args
 * @throws MetaClientException
 */
public final static void main(final String[] args) throws MetaClientException {
    final HttpClientConfig httpClientConfig = new HttpClientConfig("localhost", 8080);

    final ProxoolDataSource dataSource = new ProxoolDataSource();
    dataSource.setDriver("com.mysql.jdbc.Driver");
    dataSource.setDriverUrl("jdbc:mysql://localhost:3306/meta");
    dataSource.setUser("root");
    dataSource.setPassword("1234QWER");
    httpClientConfig.setDataSource(dataSource);
    final SimpleHttpConsumer client = new SimpleHttpConsumer(httpClientConfig);
    client.subscribe("meta-test", new Partition(1, 1), 99999, new MessageListener() {

        @Override
        public void recieveMessages(final Message message) {
            logger.info(new String(message.getData()));
        }

        @Override
        public Executor getExecutor() {
            return null;
        }
    });

    client.completeSubscribe();
}