List of usage examples for java.lang String indexOf
public int indexOf(String str)
From source file:fuse.okuyamafs.OkuyamaFuse.java
public static void main(String[] args) { String fuseArgs[] = new String[args.length - 1]; System.arraycopy(args, 0, fuseArgs, 0, fuseArgs.length); ImdstDefine.valueCompresserLevel = 9; try {/* ww w . j a v a2 s .c om*/ String okuyamaStr = args[args.length - 1]; // Raid0????????? if (okuyamaStr.indexOf("#") != -1) { stripingDataBlock = true; okuyamaStr = okuyamaStr.substring(0, (okuyamaStr.length() - 1)); } String[] masterNodeInfos = null; if (okuyamaStr.indexOf(",") != -1) { masterNodeInfos = okuyamaStr.split(","); } else { masterNodeInfos = (okuyamaStr + "," + okuyamaStr).split(","); } // 1=Memory // 2=okuyama // 3=LocalCacheOkuyama String[] optionParams = { "2", "true" }; String fsystemMode = optionParams[0].trim(); boolean singleFlg = new Boolean(optionParams[1].trim()).booleanValue(); OkuyamaFilesystem.storageType = new Integer(fsystemMode).intValue(); if (OkuyamaFilesystem.storageType == 1) OkuyamaFilesystem.blockSize = OkuyamaFilesystem.blockSize; CoreMapFactory.init(new Integer(fsystemMode.trim()).intValue(), masterNodeInfos, stripingDataBlock); FilesystemCheckDaemon loopDaemon = new FilesystemCheckDaemon(1, fuseArgs[fuseArgs.length - 1]); loopDaemon.start(); if (OkuyamaFilesystem.storageType == 2) { FilesystemCheckDaemon bufferCheckDaemon = new FilesystemCheckDaemon(2, null); bufferCheckDaemon.start(); } Runtime.getRuntime().addShutdownHook(new JVMShutdownSequence()); FuseMount.mount(fuseArgs, new OkuyamaFilesystem(fsystemMode, singleFlg), log); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.wipro.ats.bdre.dq.DQMain.java
/** * @param args/* ww w . j av a 2 s.com*/ * @throws Exception */ public static void main(String[] args) throws Exception { CommandLine commandLine = new DQMain().getCommandLine(args, PARAMS_STRUCTURE); String processId = commandLine.getOptionValue("process-id"); String sPath = commandLine.getOptionValue("source-file-path"); String destDir = commandLine.getOptionValue("destination-directory"); int result = 0; if (sPath.indexOf(';') != -1 || sPath.indexOf(',') != -1) { String[] lof = sPath.split(";"); String[] entries = lof[0].split(","); String[] params = { processId, entries[2], destDir }; result = ToolRunner.run(new Configuration(), new DQDriver(), params); } else { String[] params = { processId, sPath, destDir }; result = ToolRunner.run(new Configuration(), new DQDriver(), params); } if (result != 0) throw new DQValidationException(new DQStats()); }
From source file:com.idega.util.Stripper.java
public static void main(String[] args) { // Stripper stripper1 = new Stripper(); if (args.length != 2) { System.err.println("Auli. tt a hafa tvo parametra me essu, innskr og tskr"); return;/*from w ww. jav a2 s. c o m*/ } BufferedReader in = null; BufferedWriter out = null; try { in = new BufferedReader(new FileReader(args[0])); } catch (java.io.FileNotFoundException e) { System.err.println("Auli. Error : " + e.toString()); return; } try { out = new BufferedWriter(new FileWriter(args[1])); } catch (java.io.IOException e) { System.err.println("Auli. Error : " + e.toString()); IOUtils.closeQuietly(in); return; } try { String input = in.readLine(); int count = 0; while (input != null) { int index = input.indexOf("\\CVS\\"); if (index > -1) { System.out.println("Skipping : " + input); count++; } else { out.write(input); out.newLine(); } input = in.readLine(); } System.out.println("Skipped : " + count); } catch (java.io.IOException e) { System.err.println("Error reading or writing file : " + e.toString()); } try { in.close(); out.close(); } catch (java.io.IOException e) { System.err.println("Error closing files : " + e.toString()); } }
From source file:SparkStreaming.java
public static void main(String[] args) throws Exception { JSONObject jo = new JSONObject(); SparkConf sparkConf = new SparkConf().setAppName("mytestapp").setMaster("local[2]"); JavaStreamingContext jssc = new JavaStreamingContext(sparkConf, new Duration(2000)); int numThreads = Integer.parseInt("2"); Map<String, Integer> topicMap = new HashMap<>(); String[] topics = "testdemo".split(","); for (String topic : topics) { topicMap.put(topic, numThreads); }/*w w w .j a va 2 s .co m*/ JavaPairReceiverInputDStream<String, String> messages = KafkaUtils.createStream(jssc, "localhost:2181", "testdemo", topicMap); JavaDStream<String> lines = messages.map(new Function<Tuple2<String, String>, String>() { @Override public String call(Tuple2<String, String> tuple2) { return tuple2._2(); } }); JavaDStream<String> words = lines.flatMap(new FlatMapFunction<String, String>() { @Override public Iterable<String> call(String x) throws IOException { String temperature = x.substring(x.indexOf(":") + 1); /* System.out.println("Temperature from spark++++++++++ "+temperature); URL url = new URL("http://localhost:8080/apachetest/Test?var1="+temperature); URLConnection conn = url.openConnection(); conn.setDoOutput(true);*/ final ThermometerDemo2 demo = new ThermometerDemo2("Thermometer Demo 2", temperature); demo.pack(); demo.setVisible(true); return Arrays.asList(x.split(" ")); } }); JavaPairDStream<String, Integer> wordCounts = words.mapToPair(new PairFunction<String, String, Integer>() { @Override public Tuple2<String, Integer> call(String s) { return new Tuple2<>(s, 1); } }).reduceByKey(new Function2<Integer, Integer, Integer>() { @Override public Integer call(Integer i1, Integer i2) { return i1 + i2; } }); wordCounts.print(); jssc.start(); jssc.awaitTermination(); }
From source file:GetWebPage.java
public static void main(String args[]) throws IOException, UnknownHostException { String resource, host, file; int slashPos; resource = "http://www.java2s.com/index.htm".substring(7); // skip HTTP:// slashPos = resource.indexOf('/'); if (slashPos < 0) { resource = resource + "/"; slashPos = resource.indexOf('/'); }/*from ww w . ja va2 s. co m*/ file = resource.substring(slashPos); // isolate host and file parts host = resource.substring(0, slashPos); System.out.println("Host to contact: '" + host + "'"); System.out.println("File to fetch : '" + file + "'"); MyHTTPConnection webConnection = new MyHTTPConnection(host); if (webConnection != null) { BufferedReader in = webConnection.get(file); String line; while ((line = in.readLine()) != null) { // read until EOF System.out.println(line); } } System.out.println("\nDone."); }
From source file:MainClass.java
public static void main(String args[]) { String org = "This is a test. This is, too."; String search = "is"; String sub = "was"; String result = ""; int i;/*w w w . j av a 2s. c om*/ do { System.out.println(org); i = org.indexOf(search); if (i != -1) { result = org.substring(0, i); result = result + sub; result = result + org.substring(i + search.length()); org = result; } } while (i != -1); }
From source file:org.eclipse.swt.snippets.SnippetLauncher.java
public static void main(String[] args) { File sourceDir = SnippetsConfig.SNIPPETS_SOURCE_DIR; boolean hasSource = sourceDir.exists(); int count = 500; if (hasSource) { File[] files = sourceDir.listFiles(); if (files.length > 0) count = files.length;//from www .java 2s .c o m } for (int i = 1; i < count; i++) { if (SnippetsConfig.isPrintingSnippet(i)) continue; // avoid printing to printer String className = "Snippet" + i; Class<?> clazz = null; try { clazz = Class.forName(SnippetsConfig.SNIPPETS_PACKAGE + "." + className); } catch (ClassNotFoundException e) { } if (clazz != null) { System.out.println("\n" + clazz.getName()); if (hasSource) { File sourceFile = new File(sourceDir, className + ".java"); try (FileReader reader = new FileReader(sourceFile);) { char[] buffer = new char[(int) sourceFile.length()]; reader.read(buffer); String source = String.valueOf(buffer); int start = source.indexOf("package"); start = source.indexOf("/*", start); int end = source.indexOf("* For a list of all"); System.out.println(source.substring(start, end - 3)); boolean skip = false; String platform = SWT.getPlatform(); if (source.contains("PocketPC")) { platform = "PocketPC"; skip = true; } else if (source.contains("OpenGL")) { platform = "OpenGL"; skip = true; } else if (source.contains("JavaXPCOM")) { platform = "JavaXPCOM"; skip = true; } else { String[] platforms = { "win32", "gtk" }; for (int p = 0; p < platforms.length; p++) { if (!platforms[p].equals(platform) && source.contains("." + platforms[p])) { platform = platforms[p]; skip = true; break; } } } if (skip) { System.out.println("...skipping " + platform + " example..."); continue; } } catch (Exception e) { } } Method method = null; String[] param = SnippetsConfig.getSnippetArguments(i); try { method = clazz.getMethod("main", param.getClass()); } catch (NoSuchMethodException e) { System.out.println(" Did not find main(String [])"); } if (method != null) { try { method.invoke(clazz, new Object[] { param }); } catch (IllegalAccessException e) { System.out.println(" Failed to launch (illegal access)"); } catch (IllegalArgumentException e) { System.out.println(" Failed to launch (illegal argument to main)"); } catch (InvocationTargetException e) { System.out.println(" Exception in Snippet: " + e.getTargetException()); } } } } }
From source file:com.doculibre.constellio.utils.license.ApplyLicenseUtils.java
/** * @param args/*from w ww .j a va2s . co m*/ */ @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { URL licenceHeaderURL = ApplyLicenseUtils.class.getResource("LICENSE_HEADER"); File binDir = ClasspathUtils.getClassesDir(); File projectDir = binDir.getParentFile(); // File dryrunDir = new File(projectDir, "dryrun"); File licenceFile = new File(licenceHeaderURL.toURI()); List<String> licenceLines = readLines(licenceFile); // for (int i = 0; i < licenceLines.size(); i++) { // String licenceLine = licenceLines.get(i); // licenceLines.set(i, " * " + licenceLine); // } // licenceLines.add(0, "/**"); // licenceLines.add(" */"); List<File> javaFiles = (List<File>) org.apache.commons.io.FileUtils.listFiles(projectDir, new String[] { "java" }, true); for (File javaFile : javaFiles) { if (isValidPackage(javaFile)) { List<String> javaFileLines = readLines(javaFile); if (!javaFileLines.isEmpty()) { boolean modified = false; String firstLineTrim = javaFileLines.get(0).trim(); if (firstLineTrim.startsWith("package")) { modified = true; javaFileLines.addAll(0, licenceLines); } else if (firstLineTrim.startsWith("/**")) { int indexOfEndCommentLine = -1; loop2: for (int i = 0; i < javaFileLines.size(); i++) { String javaFileLine = javaFileLines.get(i); if (javaFileLine.indexOf("*/") != -1) { indexOfEndCommentLine = i; break loop2; } } if (indexOfEndCommentLine != -1) { modified = true; int i = 0; loop3: for (Iterator<String> it = javaFileLines.iterator(); it.hasNext();) { it.next(); if (i <= indexOfEndCommentLine) { it.remove(); } else { break loop3; } i++; } javaFileLines.addAll(0, licenceLines); } else { throw new RuntimeException( "Missing end comment for file " + javaFile.getAbsolutePath()); } } if (modified) { // String outputFilePath = javaFile.getPath().substring(projectDir.getPath().length()); // File outputFile = new File(dryrunDir, outputFilePath); // outputFile.getParentFile().mkdirs(); // System.out.println(outputFile.getPath()); // FileOutputStream fos = new FileOutputStream(outputFile); System.out.println(javaFile.getPath()); FileOutputStream fos = new FileOutputStream(javaFile); IOUtils.writeLines(javaFileLines, "\n", fos); IOUtils.closeQuietly(fos); } } } } }
From source file:Main.java
public static void main(String[] args) { Set<Object> result = new HashSet<Object>(); Provider[] providers = Security.getProviders(); for (Provider provider : providers) { Set<Object> keys = provider.keySet(); for (Object key : keys) { String data = (String) key; data = data.split(" ")[0]; if (data.startsWith("Alg.Alias")) { data = data.substring(10); }/*from www .java2 s .c om*/ data = data.substring(0, data.indexOf('.')); result.add(data); } } for (Object o : result) { System.out.println("Service Type = " + o); } }
From source file:com.msopentech.odatajclient.engine.performance.PerfTestReporter.java
public static void main(final String[] args) throws Exception { // 1. check input directory final File reportdir = new File(args[0] + File.separator + "target" + File.separator + "surefire-reports"); if (!reportdir.isDirectory()) { throw new IllegalArgumentException("Expected directory, got " + args[0]); }/*from w ww . j a va2s.c o m*/ // 2. read test data from surefire output final File[] xmlReports = reportdir.listFiles(new FilenameFilter() { @Override public boolean accept(final File dir, final String name) { return name.endsWith("-output.txt"); } }); final Map<String, Map<String, Double>> testData = new TreeMap<String, Map<String, Double>>(); for (File xmlReport : xmlReports) { final BufferedReader reportReader = new BufferedReader(new FileReader(xmlReport)); try { while (reportReader.ready()) { String line = reportReader.readLine(); final String[] parts = line.substring(0, line.indexOf(':')).split("\\."); final String testClass = parts[0]; if (!testData.containsKey(testClass)) { testData.put(testClass, new TreeMap<String, Double>()); } line = reportReader.readLine(); testData.get(testClass).put(parts[1], Double.valueOf(line.substring(line.indexOf(':') + 2, line.indexOf('[')))); } } finally { IOUtils.closeQuietly(reportReader); } } // 3. build XSLX output (from template) final HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(args[0] + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator + XLS)); for (Map.Entry<String, Map<String, Double>> entry : testData.entrySet()) { final Sheet sheet = workbook.getSheet(entry.getKey()); int rows = 0; for (Map.Entry<String, Double> subentry : entry.getValue().entrySet()) { final Row row = sheet.createRow(rows++); Cell cell = row.createCell(0); cell.setCellValue(subentry.getKey()); cell = row.createCell(1); cell.setCellValue(subentry.getValue()); } } final FileOutputStream out = new FileOutputStream( args[0] + File.separator + "target" + File.separator + XLS); try { workbook.write(out); } finally { IOUtils.closeQuietly(out); } }