List of usage examples for java.lang String split
public String[] split(String regex)
From source file:cn.lhfei.spark.streaming.NginxlogSorterApp.java
public static void main(String[] args) { JavaSparkContext sc = null;/*from w ww . ja va 2 s . c om*/ try { SparkConf conf = new SparkConf().setMaster("local").setAppName("NginxlogSorterApp"); sc = new JavaSparkContext(conf); JavaRDD<String> lines = sc.textFile(ORIGIN_PATH); JavaRDD<NginxLog> items = lines.map(new Function<String, NginxLog>() { private static final long serialVersionUID = -1530783780334450383L; @Override public NginxLog call(String v1) throws Exception { NginxLog item = new NginxLog(); String[] arrays = v1.split("[\\t]"); if (arrays.length == 3) { item.setIp(arrays[0]); item.setLiveTime(Long.parseLong(arrays[1])); item.setAgent(arrays[2]); } return item; } }); log.info("=================================Length: [{}]", items.count()); JavaPairRDD<String, Iterable<NginxLog>> keyMaps = items.groupBy(new Function<NginxLog, String>() { @Override public String call(NginxLog v1) throws Exception { return v1.getIp(); } }); log.info("=================================Group by Key Length: [{}]", keyMaps.count()); keyMaps.foreach(new VoidFunction<Tuple2<String, Iterable<NginxLog>>>() { @Override public void call(Tuple2<String, Iterable<NginxLog>> t) throws Exception { log.info("++++++++++++++++++++++++++++++++ key: {}", t._1); Iterator<NginxLog> ts = t._2().iterator(); while (ts.hasNext()) { log.info("=====================================[{}]", ts.next().toString()); } } }); FileUtils.deleteDirectory(new File(DESTI_PATH)); keyMaps.saveAsTextFile(DESTI_PATH); } catch (Exception e) { e.printStackTrace(); } finally { sc.close(); } }
From source file:math2605.gn_log.java
/** * @param args the command line arguments *//* w w w . j a v a2 s. c om*/ public static void main(String[] args) { //get file name System.out.println("Please enter a file name:"); Scanner scanner = new Scanner(System.in); String fileName = scanner.nextLine(); List<String[]> pairs = new ArrayList<>(); //get coordinate pairs and add to arraylist try { BufferedReader br = new BufferedReader(new FileReader(fileName)); String line; while ((line = br.readLine()) != null) { String[] pair = line.split(","); pairs.add(pair); } br.close(); } catch (Exception e) { } System.out.println("Please enter the value of a:"); double a = scanner.nextInt(); System.out.println("Please enter the value of b:"); double b = scanner.nextInt(); System.out.println("Please enter the value of c:"); double c = scanner.nextInt(); //init B, vector with 3 coordinates RealMatrix B = new Array2DRowRealMatrix(3, 1); B.setEntry(0, 0, a); B.setEntry(1, 0, b); B.setEntry(2, 0, c); System.out.println("Please enter the number of iteration for the Gauss-newton:"); //init N, number of iterations int N = scanner.nextInt(); //init r, vector of residuals RealMatrix r = new Array2DRowRealMatrix(); setR(pairs, a, b, c, r); //init J, Jacobian of r RealMatrix J = new Array2DRowRealMatrix(); setJ(pairs, a, b, c, r, J); System.out.println("J"); System.out.println(J); System.out.println("r"); System.out.println(r); RealMatrix sub = findQR(J, r); for (int i = N; i > 0; i--) { B = B.subtract(sub); double B0 = B.getEntry(0, 0); double B1 = B.getEntry(1, 0); double B2 = B.getEntry(2, 0); //CHANGE ABC TO USE B0, B1, B2 setR(pairs, B0, B1, B2, r); setJ(pairs, B0, B1, B2, r, J); } System.out.println("B"); System.out.println(B.toString()); }
From source file:de.jackwhite20.japs.server.Main.java
public static void main(String[] args) throws Exception { Config config = null;//from w w w. j a va 2s.co m if (args.length > 0) { Options options = new Options(); options.addOption("h", true, "Address to bind to"); options.addOption("p", true, "Port to bind to"); options.addOption("b", true, "The backlog"); options.addOption("t", true, "Worker thread count"); options.addOption("d", false, "If debug is enabled or not"); options.addOption("c", true, "Add server as a cluster"); options.addOption("ci", true, "Sets the cache check interval"); options.addOption("si", true, "Sets the snapshot interval"); CommandLineParser commandLineParser = new BasicParser(); CommandLine commandLine = commandLineParser.parse(options, args); if (commandLine.hasOption("h") && commandLine.hasOption("p") && commandLine.hasOption("b") && commandLine.hasOption("t")) { List<ClusterServer> clusterServers = new ArrayList<>(); if (commandLine.hasOption("c")) { for (String c : commandLine.getOptionValues("c")) { String[] splitted = c.split(":"); clusterServers.add(new ClusterServer(splitted[0], Integer.parseInt(splitted[1]))); } } config = new Config(commandLine.getOptionValue("h"), Integer.parseInt(commandLine.getOptionValue("p")), Integer.parseInt(commandLine.getOptionValue("b")), commandLine.hasOption("d"), Integer.parseInt(commandLine.getOptionValue("t")), clusterServers, (commandLine.hasOption("ci")) ? Integer.parseInt(commandLine.getOptionValue("ci")) : 300, (commandLine.hasOption("si")) ? Integer.parseInt(commandLine.getOptionValue("si")) : -1); } else { System.out.println( "Usage: java -jar japs-server.jar -h <Host> -p <Port> -b <Backlog> -t <Threads> [-c IP:Port IP:Port] [-d]"); System.out.println( "Example (with debugging enabled): java -jar japs-server.jar -h localhost -p 1337 -b 100 -t 4 -d"); System.out.println( "Example (with debugging enabled and cluster setup): java -jar japs-server.jar -h localhost -p 1337 -b 100 -t 4 -c localhost:1338 -d"); System.exit(-1); } } else { File configFile = new File("config.json"); if (!configFile.exists()) { try { Files.copy(JaPS.class.getClassLoader().getResourceAsStream("config.json"), configFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { System.err.println("Unable to load default config!"); System.exit(-1); } } try { config = new Gson().fromJson( Files.lines(configFile.toPath()).map(String::toString).collect(Collectors.joining(" ")), Config.class); } catch (IOException e) { System.err.println("Unable to load 'config.json' in current directory!"); System.exit(-1); } } if (config == null) { System.err.println("Failed to create a Config!"); System.err.println("Please check the program parameters or the 'config.json' file!"); } else { System.err.println("Using Config: " + config); JaPS jaPS = new JaPS(config); jaPS.init(); jaPS.start(); jaPS.stop(); } }
From source file:math2605.gn_exp.java
/** * @param args the command line arguments *//*w w w . jav a 2 s . c o m*/ public static void main(String[] args) { //get file name System.out.println("Please enter a file name:"); Scanner scanner = new Scanner(System.in); String fileName = scanner.nextLine(); List<String[]> pairs = new ArrayList<>(); //get coordinate pairs and add to arraylist try { BufferedReader br = new BufferedReader(new FileReader(fileName)); String line; while ((line = br.readLine()) != null) { String[] pair = line.split(","); pairs.add(pair); } br.close(); } catch (Exception e) { } System.out.println("Please enter the value of a:"); double a = scanner.nextInt(); System.out.println("Please enter the value of b:"); double b = scanner.nextInt(); System.out.println("Please enter the value of c:"); double c = scanner.nextInt(); //init B, vector with 3 coordinates RealMatrix B = new Array2DRowRealMatrix(3, 1); B.setEntry(0, 0, a); B.setEntry(1, 0, b); B.setEntry(2, 0, c); System.out.println("Please enter the number of iteration for the Gauss-newton:"); //init N, number of iterations int N = scanner.nextInt(); //init r, vector of residuals RealMatrix r = new Array2DRowRealMatrix(); setR(pairs, a, b, c, r); //init J, Jacobian of r RealMatrix J = new Array2DRowRealMatrix(); setJ(pairs, a, b, c, r, J); System.out.println("J"); System.out.println(J); System.out.println("r"); System.out.println(r); RealMatrix sub = findQR(J, r); for (int i = N; i > 0; i--) { B = B.subtract(sub); double B0 = B.getEntry(0, 0); double B1 = B.getEntry(1, 0); double B2 = B.getEntry(2, 0); //CHANGE ABC TO USE B0, B1, B2 setR(pairs, B0, B1, B2, r); setJ(pairs, B0, B1, B2, r, J); } System.out.println("B"); System.out.println(B.toString()); }
From source file:math2605.gn_qua.java
/** * @param args the command line arguments *///from w w w . ja v a 2s. c o m public static void main(String[] args) { //get file name System.out.println("Please enter a file name:"); Scanner scanner = new Scanner(System.in); String fileName = scanner.nextLine(); List<String[]> pairs = new ArrayList<>(); //get coordinate pairs and add to arraylist try { BufferedReader br = new BufferedReader(new FileReader(fileName)); String line; while ((line = br.readLine()) != null) { String[] pair = line.split(","); pairs.add(pair); } br.close(); } catch (Exception e) { System.out.println(e.getMessage()); } System.out.println("Please enter the value of a:"); double a = scanner.nextInt(); System.out.println("Please enter the value of b:"); double b = scanner.nextInt(); System.out.println("Please enter the value of c:"); double c = scanner.nextInt(); //init B, vector with 3 coordinates RealMatrix B = new Array2DRowRealMatrix(3, 1); B.setEntry(0, 0, a); B.setEntry(1, 0, b); B.setEntry(2, 0, c); System.out.println("Please enter the number of iteration for the Gauss-newton:"); //init N, number of iterations int N = scanner.nextInt(); //init r, vector of residuals RealMatrix r = new Array2DRowRealMatrix(pairs.size(), 1); setR(pairs, a, b, c, r); //init J, Jacobian of r RealMatrix J = new Array2DRowRealMatrix(pairs.size(), 3); setJ(pairs, a, b, c, r, J); System.out.println("J"); System.out.println(J); System.out.println("r"); System.out.println(r); RealMatrix sub = findQR(J, r); for (int i = N; i > 0; i--) { B = B.subtract(sub); double B0 = B.getEntry(0, 0); double B1 = B.getEntry(1, 0); double B2 = B.getEntry(2, 0); //CHANGE ABC TO USE B0, B1, B2 setR(pairs, B0, B1, B2, r); setJ(pairs, B0, B1, B2, r, J); } System.out.println("B"); System.out.println(B.toString()); }
From source file:edu.cuhk.hccl.TripRealRatingsApp.java
public static void main(String[] args) throws IOException { File dir = new File(args[0]); File outFile = new File(args[1]); outFile.delete();/* w ww. j a va2s. c om*/ StringBuilder buffer = new StringBuilder(); for (File file : dir.listFiles()) { List<String> lines = FileUtils.readLines(file, "UTF-8"); String hotelID = file.getName().split("_")[1]; String author = null; boolean noContent = false; for (String line : lines) { if (line.startsWith("<Author>")) { try { author = line.split(">")[1].trim(); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("[ERROR] An error occured on this line:"); System.out.println(line); continue; } } else if (line.startsWith("<Content>")) { // ignore records if they have no content String content = line.split(">")[1].trim(); if (content == null || content.equals("")) noContent = true; } else if (line.startsWith("<Rating>")) { String[] rates = line.split(">")[1].trim().split("\t"); if (noContent || rates.length != 8) continue; // Change missing rating from -1 to 0 for (int i = 0; i < rates.length; i++) { if (rates[i].equals("-1")) rates[i] = "0"; } buffer.append(author + "\t"); buffer.append(hotelID + "\t"); // overall buffer.append(rates[0] + "\t"); // location buffer.append(rates[3] + "\t"); // room buffer.append(rates[2] + "\t"); // service buffer.append(rates[6] + "\t"); // value buffer.append(rates[1] + "\t"); // cleanliness buffer.append(rates[4] + "\t"); buffer.append("\n"); } } // Write once for each file FileUtils.writeStringToFile(outFile, buffer.toString(), true); // Clear buffer buffer.setLength(0); System.out.printf("[INFO] Finished processing %s\n", file.getName()); } System.out.println("[INFO] All processinig are finished!"); }
From source file:ca.uwaterloo.cpami.mahout.matrix.utils.GramSchmidt.java
public static void main(String[] args) throws IOException { //final Configuration conf = new Configuration(); //final FileSystem fs = FileSystem.get(conf); //final SequenceFile.Reader reader = new SequenceFile.Reader(fs, // new Path("R1.dat"), conf); //IntWritable key = new IntWritable(); //VectorWritable vec = new VectorWritable(); Matrix mat = new SparseMatrix(1500, 100); //SparseRealMatrix mat2 = new OpenMapRealMatrix(12419,1500 ); BufferedReader reader = new BufferedReader(new FileReader("R.3.csv")); String line = null; while ((line = reader.readLine()) != null) { String[] parts = line.split(","); mat.set(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Double.parseDouble(parts[2])); /*/*ww w . j ava 2s . c om*/ Vector v = vec.get(); int i=0; Iterator<Vector.Element> itr = v.iterateNonZero(); while(itr.hasNext()){ double elem = itr.next().get(); if(elem !=0) mat2.setEntry(i, key.get(), elem); i++; } */ } //mat = mat.transpose(); System.out.println(mat.viewColumn(0).isDense()); System.out.println(mat.viewRow(0).isDense()); mat = mat.transpose(); GramSchmidt.orthonormalizeColumns(mat); /* System.out.println("started QR"); System.out.println(Runtime.getRuntime().maxMemory()); System.out.println(Runtime.getRuntime().maxMemory()-Runtime.getRuntime().freeMemory()); QRDecomposition qr = new QRDecomposition(mat2); System.out.println(qr.getQ().getColumnDimension()); System.out.println(qr.getQ().getRowDimension()); */ //mat = mat.transpose(); //storeSparseColumns(mat); //for (int i = 0; i < 10; i++) { // System.out.println(mat.viewRow(i).getNumNondefaultElements()); //} }
From source file:cc.twittertools.search.api.TrecSearchThriftServer.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(HELP_OPTION, "show help")); options.addOption(OptionBuilder.withArgName("port").hasArg().withDescription("port").create(PORT_OPTION)); options.addOption(//from ww w.j a v a 2s . c o m OptionBuilder.withArgName("index").hasArg().withDescription("index location").create(INDEX_OPTION)); options.addOption(OptionBuilder.withArgName("num").hasArg() .withDescription("max number of threads in thread pool").create(MAX_THREADS_OPTION)); options.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("file containing access tokens").create(CREDENTIALS_OPTION)); 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(HELP_OPTION) || !cmdline.hasOption(INDEX_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(TrecSearchThriftServer.class.getName(), options); System.exit(-1); } int port = cmdline.hasOption(PORT_OPTION) ? Integer.parseInt(cmdline.getOptionValue(PORT_OPTION)) : DEFAULT_PORT; int maxThreads = cmdline.hasOption(MAX_THREADS_OPTION) ? Integer.parseInt(cmdline.getOptionValue(MAX_THREADS_OPTION)) : DEFAULT_MAX_THREADS; File index = new File(cmdline.getOptionValue(INDEX_OPTION)); Map<String, String> credentials = null; if (cmdline.hasOption(CREDENTIALS_OPTION)) { credentials = Maps.newHashMap(); File cfile = new File(cmdline.getOptionValue(CREDENTIALS_OPTION)); if (!cfile.exists()) { System.err.println("Error: " + cfile + " does not exist!"); System.exit(-1); } for (String s : Files.readLines(cfile, Charsets.UTF_8)) { try { String[] arr = s.split(":"); credentials.put(arr[0], arr[1]); } catch (Exception e) { // Catch any exceptions from parsing file contain access tokens System.err.println("Error reading access tokens from " + cfile + "!"); System.exit(-1); } } } if (!index.exists()) { System.err.println("Error: " + index + " does not exist!"); System.exit(-1); } TServerSocket serverSocket = new TServerSocket(port); TrecSearch.Processor<TrecSearch.Iface> searchProcessor = new TrecSearch.Processor<TrecSearch.Iface>( new TrecSearchHandler(index, credentials)); TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverSocket); serverArgs.maxWorkerThreads(maxThreads); TServer thriftServer = new TThreadPoolServer( serverArgs.processor(searchProcessor).protocolFactory(new TBinaryProtocol.Factory())); thriftServer.serve(); }
From source file:com.guye.baffle.obfuscate.Main.java
public static void main(String[] args) throws IOException, BaffleException { Options opt = new Options(); opt.addOption("c", "config", true, "config file path,keep or mapping"); opt.addOption("o", "output", true, "output mapping writer file"); opt.addOption("v", "verbose", false, "explain what is being done."); opt.addOption("h", "help", false, "print help for the command."); opt.getOption("c").setArgName("file list"); opt.getOption("o").setArgName("file path"); String formatstr = "baffle [-c/--config filepaths list ][-o/--output filepath][-h/--help] ApkFile TargetApkFile"; HelpFormatter formatter = new HelpFormatter(); CommandLineParser parser = new PosixParser(); CommandLine cl = null;/*from w ww . j av a2 s . c o m*/ try { // ?Options? cl = parser.parse(opt, args); } catch (ParseException e) { formatter.printHelp(formatstr, opt); // ??? return; } if (cl == null || cl.getArgs() == null || cl.getArgs().length == 0) { formatter.printHelp(formatstr, opt); return; } // ?-h--help?? if (cl.hasOption("h")) { HelpFormatter hf = new HelpFormatter(); hf.printHelp(formatstr, "", opt, ""); return; } // ???DirectoryName String[] str = cl.getArgs(); if (str == null || str.length != 2) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("not specify apk file or taget apk file", opt); return; } if (str[1].equals(str[0])) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("apk file can not rewrite , please specify new target file", opt); return; } File apkFile = new File(str[0]); if (!apkFile.exists()) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("apk file not exists", opt); return; } File[] configs = null; if (cl.hasOption("c")) { String cfg = cl.getOptionValue("c"); String[] fs = cfg.split(","); int len = fs.length; configs = new File[fs.length]; for (int i = 0; i < len; i++) { configs[i] = new File(fs[i]); if (!configs[i].exists()) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("config file " + fs[i] + " not exists", opt); return; } } } File mappingfile = null; if (cl.hasOption("o")) { String mfile = cl.getOptionValue("o"); mappingfile = new File(mfile); if (mappingfile.getParentFile() != null) { mappingfile.getParentFile().mkdirs(); } } if (cl.hasOption('v')) { Logger.getLogger(Obfuscater.LOG_NAME).setLevel(Level.CONFIG); } else { Logger.getLogger(Obfuscater.LOG_NAME).setLevel(Level.OFF); } Logger.getLogger(Obfuscater.LOG_NAME).addHandler(new ConsoleHandler()); Obfuscater obfuscater = new Obfuscater(configs, mappingfile, apkFile, str[1]); obfuscater.obfuscate(); }
From source file:de.dakror.jagui.parser.NGuiParser.java
public static void main(String[] args) { try {//from w w w . j av a 2s. c om DIR.mkdirs(); if (!new File(DIR, "convert.exe").exists()) Helper.copyInputStream(NGuiParser.class.getResourceAsStream("/res/convert.exe"), new FileOutputStream(new File(DIR, "convert.exe"))); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); JFileChooser jfc = new JFileChooser( new File(NGuiParser.class.getProtectionDomain().getCodeSource().getLocation().toURI())); jfc.setMultiSelectionEnabled(false); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setFileFilter(new FileNameExtensionFilter("Unity ngui Gui-Skin (*.guiskin)", "guiskin")); if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { p("Collecting GUIDs, Converting Resources"); HashMap<String, File> guids = collectGUIDs(jfc.getCurrentDirectory()); p("Parsing Guiskin file"); String s = Helper.getFileContent(jfc.getSelectedFile()); String[] lines = s.split("\n"); ArrayList<String> l = new ArrayList<>(Arrays.asList(lines)); String string = ""; for (int i = 0; i < l.size(); i++) if (!l.get(i).startsWith("%") && !l.get(i).startsWith("---")) string += l.get(i) + "\n"; Yaml yaml = new Yaml(); for (Iterator<Object> iter = yaml.loadAll(string).iterator(); iter.hasNext();) { JSONObject o = new JSONObject((Map<?, ?>) iter.next()); p("Cconverting Guiskin"); replaceGuidDeep(o, guids, jfc.getSelectedFile()); p("Writing converted file"); Helper.setFileContent(new File(jfc.getSelectedFile().getParentFile(), jfc.getSelectedFile().getName() + ".json"), o.toString(4)); p("DONE"); } } } catch (Exception e) { e.printStackTrace(); } }