Example usage for java.lang Math random

List of usage examples for java.lang Math random

Introduction

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

Prototype

public static double random() 

Source Link

Document

Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0 .

Usage

From source file:com.roncoo.pay.thirdpartypay.xinzhongli.api.XzlPayAPI.java

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

    Date date = new Date();
    String tradeamt = "10";
    String merchantid = "105799954663750238208";
    //??/*from   w  ww .j  a  v  a  2  s  .  com*/
    String orderid = "LS" + date.getTime() + (int) (Math.random() * 10000000);
    String backurl = "www";
    String callbackurl = "www";
    String pay_type = "123";
    String manualsettle = "1";
    String orderInfo = "?";
    String settlement_type = "130";
    String platform_code = "880002";
    String key = "f4fcb30e002211584a199ce6ab200afc3c28920dcddeaa59c0558d4439d30b0758661db6247d0ae0d888e9991c4cbd9564473cf787f05f27ecbb7b3f77d9c797+z.1230e5732e6";

    PayInfo payInfo = new PayInfo();
    //        payInfo.setTradeamt(tradeamt);
    //        payInfo.setMerchantid(merchantid);
    //        payInfo.setOrderid(orderid);
    //        payInfo.setBackurl(callbackurl);
    //        payInfo.setCallbackurl(callbackurl);
    //        payInfo.setPay_type(pay_type);
    //        payInfo.setManualsettle(manualsettle);
    //        payInfo.setOrderInfo(orderInfo);
    //        payInfo.setSettlement_type(settlement_type);
    //        payInfo.setPlatform_code(platform_code);
    payInfo.setKey(key);

    //        pay(payInfo);

    //        testpay();
}

From source file:com.wonders.bud.freshmommy.web.openapi.controller.AsqController.java

public static void main(String[] args) {
    AsqParamsVO asqParams = new AsqParamsVO();
    asqParams.setMonth(2);//from   ww  w.j av  a 2  s . co m
    asqParams.setToken("x3q8UfddcQJeE/XMPmtAEQ==");
    asqParams.setbId(1);
    asqParams.setType(new Integer[] { 1, 2 });

    List<AsqAnswersVO> listAsq = new ArrayList<AsqAnswersVO>();
    for (int j = 0; j < 5; j++) {
        for (int i = 0; i < 6; i++) {
            AsqAnswersVO vo = new AsqAnswersVO();
            vo.setType(j + 1);
            vo.setNumber(i + 1);
            vo.setItemNum((int) (Math.random() * 10) % 3);
            listAsq.add(vo);
        }
    }
    try {
        System.out.println(JsonUtils.getJsonData(asqParams));
        System.out.println(EncryptUtil.encode(JsonUtils.getJsonData(asqParams)));
        System.out.println(
                EncryptUtil.encode("{\"type\":[1,2],\"month\":2,\"token\":\"x3q8UfddcQJeE/XMPmtAEQ==\"}"));
        System.out.println(JsonUtils.getJsonData(listAsq));
        System.out.println(EncryptUtil.encode(JsonUtils.getJsonData(listAsq)));
        System.out.println("{\"type\":[1,2],\"month\":2,\"token\":\"x3q8UfddcQJeE/XMPmtAEQ==\"}");
    } catch (Exception e) {
    }
}

From source file:SerialIntList.java

/** A main() method to prove that it works */
public static void main(String[] args) throws Exception {
    SerialIntList list = new SerialIntList();
    for (int i = 0; i < 100; i++)
        list.add((int) (Math.random() * 40000));
    SerialIntList copy = (SerialIntList) Serializer.deepclone(list);
    if (list.equals(copy))
        System.out.println("equal copies");
    Serializer.store(list, new File("intlist.ser"));
}

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

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

    RClient rClient = null;//w w w . ja va2 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 ].");

        /*
         * 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 ].");

        /* 
         * Request storage of entire workspace as a
         * binary rData file to the DeployR-repository
         * following the execution.
         *
         * Alternatively, you could use storageOptions.objects
         * to store individual objects from the workspace.
         */
        ProjectStorageOptions storageOptions = new ProjectStorageOptions();
        // Use random file name for this example.
        storageOptions.workspace = Long.toHexString(Double.doubleToLongBits(Math.random()));
        storageOptions.directory = "example-data-io";
        options.storageOptions = storageOptions;

        log.info("[  EXEC OPTION   ] Repository storage request "
                + "set on execution [ ProjectExecutionOptions.storageOptions ].");

        /*
         * 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 repository-managed file(s) that were 
         * generated by the execution per ProjectStorageOptions.
         *
         * 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<RRepositoryFile> repoFiles = exec.about().repositoryFiles;

        for (RRepositoryFile repoFile : repoFiles) {
            log.info("[  DATA OUTPUT   ] Retrieved repository " + "file output " + repoFile.about().filename
                    + " [ RRepositoryFile ].");
            InputStream fis = null;
            try {
                fis = repoFile.download();
            } catch (Exception ex) {
                log.warn("Repository-managed file download " + ex);
            } finally {
                IOUtils.closeQuietly(fis);
                try { // Clean-up after example.
                    repoFile.delete();
                } catch (Exception dex) {
                    log.warn("Repository-managed file delete " + dex);
                }
            }
        }

    } 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.myJava.util.Util.java

public static void main(String[] args) {
    byte[] data = new byte[128];
    for (int i = 0; i < data.length; i++) {
        data[i] = (byte) (Math.random() * 128.);
    }//from   w  w w  .ja  v  a 2 s .c o m
    String enc = base64Encode(data);
    System.out.println(enc);
    System.out.println(base64Encode(base64Decode(enc)));
}

From source file:org.jfree.chart.demo.PerformanceTest1.java

public static void main(String args[]) {
    ArrayList<Double> arraylist = new ArrayList<Double>();
    for (int i = 0; i < 4000; i++)
        arraylist.add(new Double(Math.random()));

    int j = 0;/*  ww  w  .ja v a  2 s . c om*/
    for (int k = 0; k < 20000; k++) {
        long l = System.currentTimeMillis();
        for (int i1 = 0; i1 < 0xf4240; i1++)
            j += i1;

        long l1 = System.currentTimeMillis();
        System.out.println(k + " --> " + (l1 - l) + " (" + Runtime.getRuntime().freeMemory() + " / "
                + Runtime.getRuntime().totalMemory() + ")");
    }

}

From source file:edu.cmu.lti.oaqa.knn4qa.apps.CollectionSplitter.java

public static void main(String[] args) {
    Options options = new Options();

    options.addOption("i", null, true, "Input file");
    options.addOption("o", null, true, "Output file prefix");
    options.addOption("p", null, true, "Comma separated probabilities e.g., 0.1,0.2,0.7.");
    options.addOption("n", null, true, "Comma separated part names, e.g., dev,test,train");

    CommandLineParser parser = new org.apache.commons.cli.GnuParser();

    try {//from   ww w. j a va2s.c o  m
        CommandLine cmd = parser.parse(options, args);

        InputStream input = null;

        if (cmd.hasOption("i")) {
            input = CompressUtils.createInputStream(cmd.getOptionValue("i"));
        } else {
            Usage("Specify Input file");
        }

        ArrayList<Double> probs = new ArrayList<Double>();
        String[] partNames = null;

        if (cmd.hasOption("p")) {
            String parts[] = cmd.getOptionValue("p").split(",");

            try {
                double sum = 0;
                for (String s : parts) {
                    double p = Double.parseDouble(s);
                    if (p <= 0 || p > 1)
                        Usage("All probabilities must be in the range (0,1)");
                    sum += p;
                    probs.add(p);
                }

                if (Math.abs(sum - 1.0) > Float.MIN_NORMAL) {
                    Usage("The sum of probabilities should be equal to 1, but it's: " + sum);
                }
            } catch (NumberFormatException e) {
                Usage("Can't convert some of the probabilities to a floating-point number.");
            }
        } else {
            Usage("Specify part probabilities.");
        }

        if (cmd.hasOption("n")) {
            partNames = cmd.getOptionValue("n").split(",");

            if (partNames.length != probs.size())
                Usage("The number of probabilities is not equal to the number of parts!");
        } else {
            Usage("Specify part names");
        }

        BufferedWriter[] outFiles = new BufferedWriter[partNames.length];

        if (cmd.hasOption("o")) {
            String outPrefix = cmd.getOptionValue("o");

            for (int partId = 0; partId < partNames.length; ++partId) {
                outFiles[partId] = new BufferedWriter(new OutputStreamWriter(
                        CompressUtils.createOutputStream(outPrefix + "_" + partNames[partId] + ".gz")));
            }
        } else {
            Usage("Specify Output file prefix");
        }

        System.out.println("Using probabilities:");
        for (int partId = 0; partId < partNames.length; ++partId)
            System.out.println(partNames[partId] + " : " + probs.get(partId));
        System.out.println("=================================================");

        XmlIterator inpIter = new XmlIterator(input, YahooAnswersReader.DOCUMENT_TAG);

        String oneRec = inpIter.readNext();
        int docNum = 1;
        for (; !oneRec.isEmpty(); ++docNum, oneRec = inpIter.readNext()) {
            double p = Math.random();

            if (docNum % 1000 == 0) {
                System.out.println(String.format("Processed %d documents", docNum));
            }

            BufferedWriter out = null;

            for (int partId = 0; partId < partNames.length; ++partId) {
                double pp = probs.get(partId);
                if (p <= pp || partId + 1 == partNames.length) {
                    out = outFiles[partId];
                    break;
                }
                p -= pp;
            }

            oneRec = oneRec.trim() + System.getProperty("line.separator");
            out.write(oneRec);
        }
        System.out.println(String.format("Processed %d documents", docNum - 1));
        // It's important to close all the streams here!
        for (BufferedWriter f : outFiles)
            f.close();
    } catch (ParseException e) {
        Usage("Cannot parse arguments");
    } catch (Exception e) {
        System.err.println("Terminating due to an exception: " + e);
        System.exit(1);
    }
}

From source file:com.revo.deployr.client.example.data.io.auth.stateful.exec.RepoFileInRepoFileOut.java

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

    RClient rClient = null;/*from   w ww  .  ja  va 2s  .c  om*/
    RProject rProject = null;

    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 a temporary project (R session).
         *
         * Optionally:
         * ProjectCreationOptions options =
         * new ProjectCreationOptions();
         *
         * Populate options as needed, then:
         *
         * rProject = rUser.createProject(options);
         */
        rProject = rUser.createProject();

        log.info("[  GO STATEFUL   ] Created stateful temporary " + "R session [ RProject ].");

        /*
         * Create a ProjectExecutionOptions instance
         * to specify data inputs and output to the
         * execution of the repository-managed R 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.
         */
        ProjectExecutionOptions options = new ProjectExecutionOptions();

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

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

        /* 
         * Request storage of entire workspace as a
         * binary rData file to the DeployR-repository
         * following the execution.
         *
         * Alternatively, you could use storageOptions.objects
         * to store individual objects from the workspace.
         */
        ProjectStorageOptions storageOptions = new ProjectStorageOptions();
        // Use random file name for this example.
        storageOptions.workspace = Long.toHexString(Double.doubleToLongBits(Math.random()));
        storageOptions.directory = "example-data-io";
        options.storageOptions = storageOptions;

        log.info("[  EXEC OPTION   ] Repository storage request "
                + "set on execution [ ProjectExecutionOptions.storageOptions ].");

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

        log.info("[   EXECUTION    ] Stateful R script " + "execution completed [ RProjectExecution ].");

        /*
         * Retrieve repository-managed file(s) that were 
         * generated by the execution per ProjectStorageOptions.
         *
         * 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<RRepositoryFile> repoFiles = exec.about().repositoryFiles;

        for (RRepositoryFile repoFile : repoFiles) {
            log.info("[  DATA OUTPUT   ] Retrieved repository " + "file output " + repoFile.about().filename
                    + " [ RRepositoryFile ].");
            InputStream fis = null;
            try {
                fis = repoFile.download();
            } catch (Exception ex) {
                log.warn("Repository-managed file download " + ex);
            } finally {
                IOUtils.closeQuietly(fis);
                try { // Clean-up after example.
                    repoFile.delete();
                } catch (Exception dex) {
                    log.warn("Repository-managed file delete " + dex);
                }
            }
        }

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

}

From source file:com.mvdb.etl.actions.ModifyCustomerData.java

public static void main(String[] args) {

    ActionUtils.assertEnvironmentSetupOk();
    ActionUtils.assertFileExists("~/.mvdb", "~/.mvdb missing. Existing.");
    ActionUtils.assertFileExists("~/.mvdb/status.InitCustomerData.complete",
            "300init-customer-data.sh not executed yet. Exiting");
    //This check is not required as data can be modified any number of times
    //ActionUtils.assertFileDoesNotExist("~/.mvdb/status.ModifyCustomerData.complete", "ModifyCustomerData already done. Start with 100init.sh if required. Exiting");
    ActionUtils.setUpInitFileProperty();
    ActionUtils.createMarkerFile("~/.mvdb/status.ModifyCustomerData.start", true);

    String customerName = null;/*from  w w  w . j a va2 s.c  o  m*/
    //Date startDate  = null;
    //Date endDate  = null;
    final CommandLineParser cmdLinePosixParser = new PosixParser();
    final Options posixOptions = constructPosixOptions();
    CommandLine commandLine;
    try {
        commandLine = cmdLinePosixParser.parse(posixOptions, args);
        //            if (commandLine.hasOption("startDate"))
        //            {
        //                String startDateStr = commandLine.getOptionValue("startDate");
        //                startDate = ActionUtils.getDate(startDateStr);
        //            }
        //            if (commandLine.hasOption("endDate"))
        //            {
        //                String endDateStr = commandLine.getOptionValue("endDate");
        //                endDate = ActionUtils.getDate(endDateStr);
        //            }
        if (commandLine.hasOption("customerName")) {
            customerName = commandLine.getOptionValue("customerName");
        }
    } catch (ParseException parseException) // checked exception
    {
        System.err.println(
                "Encountered exception while parsing using PosixParser:\n" + parseException.getMessage());
    }

    if (customerName == null) {
        System.err.println("customerName has not been specified.  Aborting...");
        System.exit(1);
    }

    //        if (startDate == null)
    //        {
    //            System.err.println("startDate has not been specified with the correct format YYYYMMddHHmmss.  Aborting...");
    //            System.exit(1);
    //        }
    //        
    //        if (endDate == null)
    //        {
    //            System.err.println("endDate has not been specified with the correct format YYYYMMddHHmmss.  Aborting...");
    //            System.exit(1);
    //        }
    //        
    //        if (endDate.after(startDate) == false)
    //        {
    //            System.err.println("endDate must be after startDate.  Aborting...");
    //            System.exit(1);
    //        }

    ApplicationContext context = Top.getContext();

    final OrderDAO orderDAO = (OrderDAO) context.getBean("orderDAO");

    long maxId = orderDAO.findMaxId();
    long totalOrders = orderDAO.findTotalOrders();

    long modifyCount = (long) (totalOrders * 0.1);

    String lastUsedEndTimeStr = ActionUtils.getConfigurationValue(customerName,
            ConfigurationKeys.LAST_USED_END_TIME);
    long lastUsedEndTime = Long.parseLong(lastUsedEndTimeStr);
    Date startDate1 = new Date();
    startDate1.setTime(lastUsedEndTime + 1000 * 60 * 60 * 24 * 1);
    Date endDate1 = new Date(startDate1.getTime() + 1000 * 60 * 60 * 24 * 1);

    for (int i = 0; i < modifyCount; i++) {
        Date updateDate = RandomUtil.getRandomDateInRange(startDate1, endDate1);
        long orderId = (long) Math.floor((Math.random() * maxId)) + 1L;
        logger.info("Modify Id " + orderId + " in orders");
        Order theOrder = orderDAO.findByOrderId(orderId);
        //             System.out.println("theOrder : " + theOrder);
        theOrder.setNote(RandomUtil.getRandomString(4));
        theOrder.setUpdateTime(updateDate);
        theOrder.setSaleCode(RandomUtil.getRandomInt());
        orderDAO.update(theOrder);
        //             System.out.println("theOrder Modified: " + theOrder);

    }
    ActionUtils.setConfigurationValue(customerName, ConfigurationKeys.LAST_USED_END_TIME,
            String.valueOf(endDate1.getTime()));
    logger.info("Modified " + modifyCount + " orders");
    ActionUtils.createMarkerFile("~/.mvdb/status.ModifyCustomerData.complete", true);
}

From source file:com.revo.deployr.client.example.data.io.auth.stateful.preload.RepoFileInRepoFileOut.java

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

    RClient rClient = null;/*from w w w.  ja va  2  s  .  c om*/
    RProject rProject = null;

    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 a ProjectCreationOptions instance
         * to specify data inputs that "pre-heat" the R session
         * workspace or working directory for your project.
         */
        ProjectCreationOptions creationOpts = new ProjectCreationOptions();

        /* 
         * Preload from the DeployR repository the following
         * binary R object input file:
         * /testuser/example-data-io/hipStar.rData
         */
        ProjectPreloadOptions preloadWorkspace = new ProjectPreloadOptions();
        preloadWorkspace.filename = "hipStar.rData";
        preloadWorkspace.directory = "example-data-io";
        preloadWorkspace.author = "testuser";
        creationOpts.preloadWorkspace = preloadWorkspace;

        log.info("[ PRELOAD INPUT  ] Repository binary file input "
                + "set on project creation, [ ProjectCreationOptions.preloadWorkspace ].");

        /*
         * Create a temporary project (R session) passing a 
         * ProjectCreationOptions to "pre-heat" data into the
         * workspace and/or working directory.
         */
        rProject = rUser.createProject(creationOpts);

        log.info("[  GO STATEFUL   ] Created stateful temporary " + "R session [ RProject ].");

        /*
         * Create a ProjectExecutionOptions instance
         * to specify data inputs and output to the
         * execution of the repository-managed R 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.
         */
        ProjectExecutionOptions execOpts = new ProjectExecutionOptions();

        /* 
         * Request storage of entire workspace as a
         * binary rData file to the DeployR-repository
         * following the execution.
         *
         * Alternatively, you could use storageOptions.objects
         * to store individual objects from the workspace.
         */
        ProjectStorageOptions storageOptions = new ProjectStorageOptions();
        // Use random file name for this example.
        storageOptions.workspace = Long.toHexString(Double.doubleToLongBits(Math.random()));
        storageOptions.directory = "example-data-io";
        execOpts.storageOptions = storageOptions;

        log.info("[  EXEC OPTION   ] Repository storage request "
                + "set on execution [ ProjectExecutionOptions.storageOptions ].");

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

        log.info("[   EXECUTION    ] Stateful R script " + "execution completed [ RProjectExecution ].");

        /*
         * Retrieve repository-managed file(s) that were 
         * generated by the execution per ProjectStorageOptions.
         *
         * 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<RRepositoryFile> repoFiles = exec.about().repositoryFiles;

        for (RRepositoryFile repoFile : repoFiles) {
            log.info("[  DATA OUTPUT   ] Retrieved repository " + "file output " + repoFile.about().filename
                    + " [ RRepositoryFile ].");
            InputStream fis = null;
            try {
                fis = repoFile.download();
            } catch (Exception ex) {
                log.warn("Repository-managed file download " + ex);
            } finally {
                IOUtils.closeQuietly(fis);
                try { // Clean-up after example.
                    repoFile.delete();
                } catch (Exception dex) {
                    log.warn("Repository-managed file delete " + dex);
                }
            }
        }

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

}