Example usage for java.lang String split

List of usage examples for java.lang String split

Introduction

In this page you can find the example usage for java.lang String split.

Prototype

public String[] split(String regex) 

Source Link

Document

Splits this string around matches of the given regular expression.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    URL url = new URL("http://hostname:80");
    URLConnection conn = url.openConnection();

    for (int i = 0;; i++) {
        String headerName = conn.getHeaderFieldKey(i);
        String headerValue = conn.getHeaderField(i);

        if (headerName == null && headerValue == null) {
            break;
        }//from  ww  w .j a v a 2s. c  om
        if ("Set-Cookie".equalsIgnoreCase(headerName)) {
            String[] fields = headerValue.split(";\\s*");
            for (int j = 1; j < fields.length; j++) {
                if ("secure".equalsIgnoreCase(fields[j])) {
                    System.out.println("secure=true");
                } else if (fields[j].indexOf('=') > 0) {
                    String[] f = fields[j].split("=");
                    if ("expires".equalsIgnoreCase(f[0])) {
                        System.out.println("expires" + f[1]);
                    } else if ("domain".equalsIgnoreCase(f[0])) {
                        System.out.println("domain" + f[1]);
                    } else if ("path".equalsIgnoreCase(f[0])) {
                        System.out.println("path" + f[1]);
                    }
                }
            }
        }
    }
}

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

public static void main(String[] args) {
    String[] opts = new String[] { "-store", "-path", "-port", "-mode", "-delay" };
    String[] defaults = new String[] { "store", "./data", "7100", "0", "false" };
    String[] paras = getOpts(args, opts, defaults);
    String p0 = paras[0];
    int port = Integer.valueOf(paras[2]);
    String path = paras[1];// w w  w  .  j a  v  a 2s.  com
    int mode = Integer.valueOf(paras[3]);
    boolean delay = Boolean.valueOf(paras[4]);
    String[] stores = p0.split(",");
    List<TupleThree<String, String, Integer>> storeList = new ArrayList<TupleThree<String, String, Integer>>();
    for (String store : stores) {
        storeList.add(new TupleThree<String, String, Integer>(store, path, mode));

    }
    GZRemoteStoreServer rs = new GZRemoteStoreServer(port, storeList, delay);
    logger.info("hookup jvm shutdown process");
    rs.hookShutdown();
    List list = new ArrayList();
    //add jmx metric
    for (String store : stores) {
        list.add(rs.getRemoteStore(store));
    }
    list.add(rs);
    JmxService jms = new JmxService(list);
}

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

public static void main(String[] args) {
    String[] opts = new String[] { "-store", "-path", "-port", "-mode", "-delay" };
    String[] defaults = new String[] { "store", "./storepath", "7100", "0", "false" };
    String[] paras = getOpts(args, opts, defaults);
    String p0 = paras[0];
    int port = Integer.valueOf(paras[2]);
    String path = paras[1];//  w ww  .  ja v a  2 s.  com
    int mode = Integer.valueOf(paras[3]);
    boolean delay = Boolean.valueOf(paras[4]);
    String[] stores = p0.split(",");
    List<TupleThree<String, String, Integer>> storeList = new ArrayList<TupleThree<String, String, Integer>>();
    for (String store : stores) {
        storeList.add(new TupleThree<String, String, Integer>(store, path, mode));

    }
    RemoteStoreServer rs = new RemoteStoreServer(port, storeList, delay);
    logger.info("hookup jvm shutdown process");
    rs.hookShutdown();
    List list = new ArrayList();
    //add jmx metric
    for (String store : stores) {
        list.add(rs.getRemoteStore(store));
    }
    list.add(rs);
    JmxService jms = new JmxService(list);
}

From source file:com.norconex.jefmon.server.JEFMonServer.java

public static void main(String[] args) throws Exception {
    Properties props = getSetupProperties();

    String localesString = props.getString("locales");
    String[] localeStrings = localesString.split(",");
    Locale[] locales = new Locale[localeStrings.length];
    for (int i = 0; i < localeStrings.length; i++) {
        locales[i] = LocaleUtils.toLocale(localeStrings[i].trim());
    }/*  w  ww .ja  v a  2s. c  o  m*/

    final JEFMonServer server = new JEFMonServer(props.getInt("port", 80), props.getBoolean("https", false),
            locales);
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                server.stop();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    server.run();
}

From source file:edu.uci.mhlee.BasicCrawler.java

public static void main(String[] args) {
    String href = "http://aaaa/?alskdjfalk=10";
    String[] aaa = href.split("(\\?.*)?$");
    System.out.println(aaa[0]);// ww w .  ja  va  2  s. co  m
    System.out.println(aaa.length);
    Pattern URL_QUERY = Pattern.compile(".*\\.(\\?.*)?$");
    System.out.println(URL_QUERY.matcher(href).matches());
    System.out.println(href.contains("?"));
}

From source file:com.navercorp.client.Main.java

public static void main(String[] args) {
    Client clnt = null;//w  w  w  . java  2  s  .co  m
    try {
        CommandLine cmd = new DefaultParser()
                .parse(new Options().addOption("z", true, "zookeeper address (ip:port,ip:port,...)")
                        .addOption("t", true, "zookeeper connection timeout")
                        .addOption("c", true, "command and arguments"), args);

        final String connectionString = cmd.hasOption("z") ? cmd.getOptionValue("z") : "127.0.0.1:2181";
        final int timeout = cmd.hasOption("t") ? Integer.valueOf(cmd.getOptionValue("t")) : 10000;
        clnt = new Client(connectionString, timeout);

        String command;
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        while ((command = in.readLine()) != null) {
            printResult(clnt.execute(command.split(" ")));
        }
        System.exit(Code.OK.n());
    } catch (ParseException e) {
        e.printStackTrace(System.err);
        System.err.println(Client.getUsage());
        System.exit(INVALID_ARGUMENT.n());
    } catch (IOException e) {
        e.printStackTrace(System.err);
        System.exit(ZK_CONNECTION_LOSS.n());
    } catch (InterruptedException e) {
        e.printStackTrace(System.err);
        System.exit(INTERNAL_ERROR.n());
    } finally {
        if (clnt != null) {
            try {
                clnt.close();
            } catch (Exception e) {
                ; // nothing to do
            }
        }
    }
}

From source file:metaTile.Main.java

/**
 * @param args/*from   w  ww  . ja  v  a 2  s. co m*/
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    try {
        /* parse the command line arguments */
        // create the command line parser
        CommandLineParser parser = new PosixParser();

        // create the Options
        Options options = new Options();
        options.addOption("i", "input", true, "File to read original tile list from.");
        options.addOption("o", "output", true, "File to write shorter meta-tile list to.");
        options.addOption("m", "metatiles", true,
                "Number of tiles in x and y direction to group into one meta-tile.");

        // parse the command line arguments
        CommandLine commandLine = parser.parse(options, args);

        if (!commandLine.hasOption("input") || !commandLine.hasOption("output")
                || !commandLine.hasOption("metatiles"))
            printUsage(options);

        String inputFileName = commandLine.getOptionValue("input");
        String outputFileName = commandLine.getOptionValue("output");
        int metaTileSize = Integer.parseInt(commandLine.getOptionValue("metatiles"));

        ArrayList<RenderingTile> tiles = new ArrayList<RenderingTile>();

        BufferedReader tileListReader = new BufferedReader(new FileReader(new File(inputFileName)));

        BufferedWriter renderMetatileListWriter = new BufferedWriter(new FileWriter(new File(outputFileName)));

        String line = tileListReader.readLine();
        while (line != null) {
            String[] columns = line.split("/");

            if (columns.length == 3)
                tiles.add(new RenderingTile(Integer.parseInt(columns[0]), Integer.parseInt(columns[1]),
                        Integer.parseInt(columns[2])));

            line = tileListReader.readLine();
        }

        tileListReader.close();

        int hits = 0;

        // tiles which we are already rendering as the top left corner of 4x4 metatiles
        HashSet<RenderingTile> whitelist = new HashSet<RenderingTile>();

        // for each tile in the list see if it has a meta-tile in the whitelist already
        for (int i = 0; i < tiles.size(); i++) {
            boolean hit = false; // by default we aren't already rendering this tile as part of another metatile
            for (int dx = 0; dx < metaTileSize; dx++) {
                for (int dy = 0; dy < metaTileSize; dy++) {
                    RenderingTile candidate = new RenderingTile(tiles.get(i).z, tiles.get(i).x - dx,
                            tiles.get(i).y - dy);
                    if (whitelist.contains(candidate)) {
                        hit = true;
                        // now exit the two for loops iterating over tiles inside a meta-tile
                        dx = metaTileSize;
                        dy = metaTileSize;
                    }
                }
            }

            // if this tile doesn't already have a meta-tile in the whitelist, add it
            if (hit == false) {
                hits++;
                renderMetatileListWriter.write(tiles.get(i).toString() + "/" + metaTileSize + "\n");
                whitelist.add(tiles.get(i));
            }
        }
        renderMetatileListWriter.close();
        System.out.println(
                "Reduced " + tiles.size() + " tiles into " + hits + " metatiles of size " + metaTileSize);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:SequentialPageRank.java

@SuppressWarnings({ "static-access" })
public static void main(String[] args) throws IOException {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT));
    options.addOption(//from   ww w  . j av a2  s .c o m
            OptionBuilder.withArgName("val").hasArg().withDescription("random jump factor").create(JUMP));

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!cmdline.hasOption(INPUT)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(SequentialPageRank.class.getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        System.exit(-1);
    }

    String infile = cmdline.getOptionValue(INPUT);
    float alpha = cmdline.hasOption(JUMP) ? Float.parseFloat(cmdline.getOptionValue(JUMP)) : 0.15f;

    int edgeCnt = 0;
    DirectedSparseGraph<String, Integer> graph = new DirectedSparseGraph<String, Integer>();

    BufferedReader data = new BufferedReader(new InputStreamReader(new FileInputStream(infile)));

    String line;
    while ((line = data.readLine()) != null) {
        line.trim();
        String[] arr = line.split("\\t");

        for (int i = 1; i < arr.length; i++) {
            graph.addEdge(new Integer(edgeCnt++), arr[0], arr[i]);
        }
    }

    data.close();

    WeakComponentClusterer<String, Integer> clusterer = new WeakComponentClusterer<String, Integer>();

    Set<Set<String>> components = clusterer.transform(graph);
    int numComponents = components.size();
    System.out.println("Number of components: " + numComponents);
    System.out.println("Number of edges: " + graph.getEdgeCount());
    System.out.println("Number of nodes: " + graph.getVertexCount());
    System.out.println("Random jump factor: " + alpha);

    // Compute PageRank.
    PageRank<String, Integer> ranker = new PageRank<String, Integer>(graph, alpha);
    ranker.evaluate();

    // Use priority queue to sort vertices by PageRank values.
    PriorityQueue<Ranking<String>> q = new PriorityQueue<Ranking<String>>();
    int i = 0;
    for (String pmid : graph.getVertices()) {
        q.add(new Ranking<String>(i++, ranker.getVertexScore(pmid), pmid));
    }

    // Print PageRank values.
    System.out.println("\nPageRank of nodes, in descending order:");
    Ranking<String> r = null;
    while ((r = q.poll()) != null) {
        System.out.println(r.rankScore + "\t" + r.getRanked());
    }
}

From source file:com.wordnik.swagger.testframework.JavaTestCaseExecutor.java

/**
 * Follow the following argument pattern
 * Arguments in calling this method://from  ww w .  ja va  2  s  .co m
 * ApiServerURL
 *
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {

    JavaTestCaseExecutor runner = new JavaTestCaseExecutor();
    String apiServer = args[1];
    String servicePackageName = args[2];
    String apiKey = args[3];
    String authToken = args[4];
    String resource = args[5];
    String httpMethod = args[6];
    String suggestedMethodName = args[7];
    Map<String, String> queryAndPathParameters = new HashMap<String, String>();
    String postData = null;
    if (args.length > 8 && args[8].length() > 0) {
        String[] qpTuple = args[8].split("~");
        for (String tuple : qpTuple) {
            String[] nameValue = tuple.split("=");
            queryAndPathParameters.put(nameValue[0], nameValue[1]);
        }
    }
    if (args.length > 9) {
        postData = args[9];
    }
    queryAndPathParameters.put("authToken", authToken);

    ApiKeyAuthTokenBasedSecurityHandler securityHandler = new ApiKeyAuthTokenBasedSecurityHandler(apiKey,
            authToken);
    APIInvoker aAPIInvoker = APIInvoker.initialize(securityHandler, apiServer, true);

    runner.executeTestCase(resource, servicePackageName, suggestedMethodName, queryAndPathParameters, postData);

}

From source file:com.github.brandtg.StlPlotter.java

public static void main(String[] args) throws Exception {
    List<Long> times = new ArrayList<>();
    List<Number> series = new ArrayList<>();
    try (InputStream is = new FileInputStream(args[1]);
            BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
        String line = reader.readLine(); // header
        while ((line = reader.readLine()) != null) {
            String[] tokens = line.split(",");
            times.add(Long.valueOf(tokens[0]));
            series.add(Double.valueOf(tokens[1]));
        }/*from w  ww  . j  a va  2  s  .  co  m*/
    }

    StlConfig config = new StlConfig();
    config.setNumberOfObservations(Integer.valueOf(args[0]));
    config.setNumberOfDataPoints(times.size());
    config.setNumberOfRobustnessIterations(1);
    config.setPeriodic(true);

    StlResult result = new StlDecomposition(config).decompose(times, series);

    plot(result);
}