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

public static String getOSString() {
    String patch;//  ww w.j  ava  2 s . c  o m
    if (checkForNoSandbox()) {
        patch = System.getProperty("sun.os.patch.level") + " (" + System.getProperty("sun.arch.data.model")
                + "bit)";
    } else {
        patch = "?";
    }
    return System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + patch + " on "
            + System.getProperty("os.arch");
}

From source file:Main.java

public static int getJavaVersion() {
    int ver = -1;
    String verstr = System.getProperty("java.version");
    if (verstr != null) {
        String[] numbers = verstr.split("\\.");
        try {/*from ww  w. ja v a2s. com*/
            ver = Integer.parseInt(numbers[1]);
        } catch (NumberFormatException e) {
            ver = -1;
        }
    }
    return ver;
}

From source file:Main.java

/**
 * MacOS Look and feel test/*  ww  w.j  a  v a2 s. c om*/
 * @return true if using Aqua Look n' Feel
 */
public static boolean isAquaLookAndFeel() {
    return System.getProperty("mrj.version") != null && UIManager.getSystemLookAndFeelClassName()
            .equals(UIManager.getLookAndFeel().getClass().getName());
}

From source file:OSUtils.java

public static final boolean isMacOSX() {
    return System.getProperty("os.name").equals("Mac OS X");
}

From source file:Main.java

private static String getImgDirPath() {
    StringBuilder dirPath = new StringBuilder();
    dirPath.append(System.getProperty("user.dir"));
    dirPath.append(SEPARATOR + "report" + SEPARATOR + "worktemp" + SEPARATOR + "images" + SEPARATOR);
    return dirPath.toString();
}

From source file:htmlwordtag.HtmlWordTag.java

public static void main(String[] args)
        throws RepositoryException, MalformedQueryException, QueryEvaluationException {
    //get current path
    String current = System.getProperty("user.dir");
    //get html file from internet
    loadhtml();/*w  w w.ja va  2  s  .c  o  m*/
    //make director for output
    verifyArgs();
    //translate html file to rdf
    HtmlWordTag httpClientPost = new HtmlWordTag();
    httpClientPost.input = new File("input");
    httpClientPost.output = new File("output");
    httpClientPost.client = new HttpClient();
    httpClientPost.client.getParams().setParameter("http.useragent", "Calais Rest Client");

    httpClientPost.run();

    //create main memory repository
    Repository repo = new SailRepository(new MemoryStore());
    repo.initialize();

    File file = new File(current + "\\output\\website1.html.xml");

    RepositoryConnection con = repo.getConnection();
    try {
        con.add(file, null, RDFFormat.RDFXML);
    } catch (OpenRDFException e) {
        // handle exception
    } catch (java.io.IOException e) {
        // handle io exception
    }

    System.out.println(con.isEmpty());

    //query entire repostiory
    String queryString = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
            + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
            + "PREFIX c: <http://s.opencalais.com/1/type/em/e/>\n"
            + "PREFIX p: <http://s.opencalais.com/1/pred/>\n"
            + "PREFIX geo: <http://s.opencalais.com/1/type/er/Geo/>\n"

            + "SELECT  distinct ?s ?n\n" + "WHERE {\n" + "{  ?s rdf:type c:Organization.\n"
            + "   ?s p:name ?n.\n}" + "  UNION \n" + "{  ?s rdf:type c:Person.\n" + "   ?s p:name ?n.\n}"
            + "  UNION \n" + "{  ?s rdf:type geo:City.\n" + "   ?s p:name ?n.\n}" + "}";

    //System.out.println(queryString);

    //insert query through sparql repository connection
    TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    TupleQueryResult result = tupleQuery.evaluate();

    File queryresultdir = new File(current + "\\queryresult");
    if (!queryresultdir.exists()) {
        if (queryresultdir.mkdir()) {
            System.out.println("Directory is created!");
        } else {
            System.out.println("Failed to create directory!");
        }
    }

    File queryresult = null;
    try {
        // create new file
        queryresult = new File(current + "\\queryresult\\queryresult1.txt");

        // tries to create new file in the system
        if (queryresult.exists()) {
            if (queryresult.delete()) {
                System.out.println("file queryresult1.txt is already exist.");
                System.out.println("file queryresult1.txt has been delete.");
                if (queryresult.createNewFile()) {
                    System.out.println("create queryresult1.txt success");
                } else {
                    System.out.println("fail to create queryresult1.txt");
                }
            } else {
                System.out.println("fail to delete queryresult1.txt.");
            }
        } else {
            if (queryresult.createNewFile()) {
                System.out.println("create queryresult1.txt success");
            } else {
                System.out.println("fail to create queryresult1.txt");
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        PrintWriter outputStream = null;
        try {
            outputStream = new PrintWriter(new FileOutputStream(current + "\\queryresult\\queryresult1.txt"));
        } catch (FileNotFoundException e) {
            System.out.println("Error to find file queryresult1.txt");
            System.exit(0);
        }
        //go through all triple in sparql repository
        while (result.hasNext()) { // iterate over the result
            BindingSet bindingSet = result.next();
            Value valueOfS = bindingSet.getValue("s");
            Value valueOfN = bindingSet.getValue("n");

            System.out.println(valueOfS + " " + valueOfN);

            outputStream.println(valueOfS + " " + valueOfN);

        }
        outputStream.close();
    } finally {
        result.close();
    }
    //create main memory repository
    Repository repo2 = new SailRepository(new MemoryStore());
    repo2.initialize();

    File file2 = new File(current + "\\output\\website2.html.xml");

    RepositoryConnection con2 = repo2.getConnection();
    try {
        con2.add(file2, null, RDFFormat.RDFXML);
    } catch (OpenRDFException e) {
        // handle exception
    } catch (java.io.IOException e) {
        // handle io exception
    }

    System.out.println(con2.isEmpty());

    //query entire repostiory
    String queryString2 = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
            + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
            + "PREFIX c: <http://s.opencalais.com/1/type/em/e/>\n"
            + "PREFIX p: <http://s.opencalais.com/1/pred/>\n"
            + "PREFIX geo: <http://s.opencalais.com/1/type/er/Geo/>\n"

            + "SELECT  distinct ?s ?n\n" + "WHERE {\n" + "{  ?s rdf:type c:Organization.\n"
            + "   ?s p:name ?n.\n}" + "  UNION \n" + "{  ?s rdf:type c:Person.\n" + "   ?s p:name ?n.\n}"
            + "  UNION \n" + "{  ?s rdf:type geo:City.\n" + "   ?s p:name ?n.\n}" + "}";

    //System.out.println(queryString2);

    //insert query through sparql repository connection
    TupleQuery tupleQuery2 = con2.prepareTupleQuery(QueryLanguage.SPARQL, queryString2);
    TupleQueryResult result2 = tupleQuery2.evaluate();

    File queryresult2 = null;
    try {
        // create new file
        queryresult2 = new File(current + "\\queryresult\\queryresult2.txt");

        // tries to create new file in the system
        if (queryresult2.exists()) {
            if (queryresult2.delete()) {
                System.out.println("file queryresult2.txt is already exist.");
                System.out.println("file queryresult2.txt has been delete.");
                if (queryresult2.createNewFile()) {
                    System.out.println("create queryresult2.txt success");
                } else {
                    System.out.println("fail to create queryresult2.txt");
                }
            } else {
                System.out.println("fail to delete queryresult2.txt.");
            }
        } else {
            if (queryresult2.createNewFile()) {
                System.out.println("create queryresult2.txt success");
            } else {
                System.out.println("fail to create queryresult2.txt");
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        PrintWriter outputStream2 = null;
        try {
            outputStream2 = new PrintWriter(new FileOutputStream(current + "\\queryresult\\queryresult2.txt"));
        } catch (FileNotFoundException e) {
            System.out.println("Error to find file queryresult2.txt");
            System.exit(0);
        }
        //go through all triple in sparql repository
        while (result2.hasNext()) { // iterate over the result
            BindingSet bindingSet = result2.next();
            Value valueOfS = bindingSet.getValue("s");
            Value valueOfN = bindingSet.getValue("n");

            System.out.println(valueOfS + " " + valueOfN);

            outputStream2.println(valueOfS + " " + valueOfN);

        }
        outputStream2.close();
    } finally {
        result2.close();
    }

}

From source file:Main.java

public static File getSaveGameDir() {

    if (savesDir != null) {
        return savesDir;
    }/*from  w ww.ja va  2  s .  c  om*/

    File userHome = new File(System.getProperty("user.home"));
    File userMaps = new File(userHome, "saves");
    if (!userMaps.isDirectory() && !userMaps.mkdirs()) { // if it does not exist and i cant make it
        throw new RuntimeException("can not create dir " + userMaps);
    }

    savesDir = userMaps;
    return userMaps;
}

From source file:Main.java

public static void generateFile(String str) throws Exception {
    File target = new File(System.getProperty("user.dir") + "/src/sql1.txt");
    FileOutputStream fos = new FileOutputStream(target);
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, "utf-8"));
    bw.write(str.toString());/*  w  ww.  j  a  v a2s  .c  o m*/
    bw.close();
}

From source file:Main.java

public static JFileChooser makeFileChooser() {
    final JFileChooser temp = new JFileChooser();
    final String dir = System.getProperty("user.dir");
    final File fileDir = new File(dir);
    temp.setCurrentDirectory(fileDir);//from   w  ww .  j a  va 2s.  c  o  m
    return temp;
}

From source file:alluxio.examples.JournalCrashTest.java

/**
 * Runs the crash test.//from  ww  w.j  a va2 s  .c o m
 *
 * Usage:
 * {@code java -cp
 * alluxio-<ALLUXIO-VERSION>-jar-with-dependencies.jar alluxio.examples.JournalCrashTest}
 *
 * @param args no arguments
 */
public static void main(String[] args) {
    // Parse the input args.
    if (!parseInputArgs(args)) {
        System.exit(EXIT_FAILED);
    }

    System.out.println("Stop the current Alluxio cluster...");
    stopCluster();

    // Set NO_STORE and NO_PERSIST so that this test can work without AlluxioWorker.
    sCreateFileOptions = CreateFileOptions.defaults().setWriteType(WriteType.NONE);
    // Set the max retry to avoid long pending for client disconnect.
    if (System.getProperty(Constants.MASTER_RETRY_COUNT) == null) {
        System.setProperty(Constants.MASTER_RETRY_COUNT, "10");
    }

    System.out.println("Start Journal Crash Test...");
    long startTimeMs = System.currentTimeMillis();
    boolean ret = true;
    startMaster();

    int rounds = 0;
    while (System.currentTimeMillis() - startTimeMs < sTotalTimeMs) {
        rounds++;
        long aliveTimeMs = (long) (Math.random() * sMaxAliveTimeMs) + 100;
        LOG.info("Round {}: Planning Master Alive Time {}ms.", rounds, aliveTimeMs);

        System.out.println("Round " + rounds + " : Launch Clients...");
        sFileSystem = FileSystem.Factory.get();
        try {
            sFileSystem.delete(new AlluxioURI(sTestDir));
        } catch (Exception e) {
            // Test Directory not exist
        }

        // Launch all the client threads.
        setupClientThreads();
        for (Thread thread : sClientThreadList) {
            thread.start();
        }

        CommonUtils.sleepMs(LOG, aliveTimeMs);
        System.out.println("Round " + rounds + " : Crash Master...");
        killMaster();
        for (ClientThread clientThread : sClientThreadList) {
            clientThread.setIsStopped(true);
        }
        for (Thread thread : sClientThreadList) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                LOG.error("Error when waiting thread", e);
            }
        }

        System.out.println("Round " + rounds + " : Check Status...");
        startMaster();
        boolean checkSuccess = false;
        try {
            checkSuccess = checkStatus();
        } catch (Exception e) {
            LOG.error("Failed to check status", e);
        }
        Utils.printPassInfo(checkSuccess);
        ret &= checkSuccess;
    }

    stopCluster();
    System.exit(ret ? EXIT_SUCCESS : EXIT_FAILED);
}