List of usage examples for java.lang String substring
public String substring(int beginIndex)
From source file:Main.java
public static void main(String[] args) { File f = new File("c:/test"); FilenameFilter fileNameFilter = new FilenameFilter() { @Override// ww w . j av a 2 s . c om public boolean accept(File dir, String name) { if (name.lastIndexOf('.') > 0) { int lastIndex = name.lastIndexOf('.'); String str = name.substring(lastIndex); if (str.equals(".txt")) { return true; } } return false; } }; File[] paths = f.listFiles(fileNameFilter); for (File path : paths) { System.out.println(path); } }
From source file:com.mtag.trafficservice.TrafficApplication.java
public static void main(String[] args) { for (String arg : args) { String a = arg.toLowerCase(); if (a.startsWith("--port=")) { Integer port = new Integer(a.substring(7)); if (port != null) { ServerCustomizationBean.port = port; }// w w w. java 2s . co m } else { System.out.println("--- unknown argument '" + arg + "' ---"); System.out.println(); System.out.println("options are:"); System.out.println("--port=n change http-port to n (default is 8080)"); System.out.println(); } } // new AnnotationConfigApplicationContext(Tra) SpringApplication.run(TrafficApplication.class, args); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String encoding = "ISO-8859-1"; URL u = new URL("http://www.java2s.com"); URLConnection uc = u.openConnection(); String contentType = uc.getContentType(); int encodingStart = contentType.indexOf("charset="); if (encodingStart != -1) { encoding = contentType.substring(encodingStart + 8); }//from w ww.j a v a 2 s . c o m InputStream in = new BufferedInputStream(uc.getInputStream()); Reader r = new InputStreamReader(in, encoding); int c; while ((c = r.read()) != -1) { System.out.print((char) c); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Set result = new HashSet(); Provider[] providers = Security.getProviders(); for (int i = 0; i < providers.length; i++) { Set keys = providers[i].keySet(); for (Iterator it = keys.iterator(); it.hasNext();) { String key = (String) it.next(); key = key.split(" ")[0]; if (key.startsWith("Alg.Alias.")) { // Strip the alias key = key.substring(10); }// w w w. jav a 2 s .c o m int ix = key.indexOf('.'); result.add(key.substring(0, ix)); } } System.out.println(result); }
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); }/*from ww w. ja va 2 s . c om*/ 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:WebLauncher.java
public static void main(String[] args) { DirectJNI.init();/*from ww w .j ava2 s .c o m*/ for (String className : DirectJNI._rPackageInterfacesHash.keySet()) { String shortClassName = className.substring(className.lastIndexOf('.') + 1); try { Class packageWebClass = DirectJNI._mappingClassLoader.loadClass(className + "Web"); if (packageWebClass.getDeclaredMethods().length > 0) { try { String url = "http://localhost:8080/" + "ws/" + shortClassName; Endpoint.publish(url, packageWebClass.newInstance()); System.out.println(shortClassName + "Web" + " has been successfully published to " + url); } catch (Exception ie) { ie.printStackTrace(); } } } catch (ClassNotFoundException e) { } } }
From source file:at.gv.egiz.pdfas.cli.test.SignaturProfileTest.java
public static void main(String[] args) { String user_home = System.getProperty("user.home"); String pdfas_dir = user_home + File.separator + ".pdfas"; PdfAs pdfas = PdfAsFactory.createPdfAs(new File(pdfas_dir)); try {/*from w w w . j a v a2s .c o m*/ Configuration config = pdfas.getConfiguration(); ISettings settings = (ISettings) config; List<String> signatureProfiles = new ArrayList<String>(); List<String> signaturePDFAProfiles = new ArrayList<String>(); Iterator<String> itKeys = settings.getFirstLevelKeys("sig_obj.types.").iterator(); while (itKeys.hasNext()) { String key = itKeys.next(); String profile = key.substring("sig_obj.types.".length()); System.out.println("[" + profile + "]: " + settings.getValue(key)); if (settings.getValue(key).equals("on")) { signatureProfiles.add(profile); if (profile.contains("PDFA")) { signaturePDFAProfiles.add(profile); } } } byte[] input = IOUtils.toByteArray(new FileInputStream(sourcePDF)); IPlainSigner signer = new PAdESSignerKeystore(KS_FILE, KS_ALIAS, KS_PASS, KS_KEY_PASS, KS_TYPE); Iterator<String> itProfiles = signatureProfiles.iterator(); while (itProfiles.hasNext()) { String profile = itProfiles.next(); System.out.println("Testing " + profile); DataSource source = new ByteArrayDataSource(input); FileOutputStream fos = new FileOutputStream(targetFolder + profile + ".pdf"); SignParameter signParameter = PdfAsFactory.createSignParameter(config, source, fos); signParameter.setPlainSigner(signer); signParameter.setSignatureProfileId(profile); SignResult result = pdfas.sign(signParameter); fos.close(); } byte[] inputPDFA = IOUtils.toByteArray(new FileInputStream(sourcePDFA)); Iterator<String> itPDFAProfiles = signaturePDFAProfiles.iterator(); while (itPDFAProfiles.hasNext()) { String profile = itPDFAProfiles.next(); System.out.println("Testing " + profile); DataSource source = new ByteArrayDataSource(inputPDFA); FileOutputStream fos = new FileOutputStream(targetFolder + "PDFA_" + profile + ".pdf"); SignParameter signParameter = PdfAsFactory.createSignParameter(config, source, fos); signParameter.setPlainSigner(signer); signParameter.setSignatureProfileId(profile); SignResult result = pdfas.sign(signParameter); fos.close(); } } catch (Throwable e) { e.printStackTrace(); } }
From source file:SubStringDemo.java
/** * @author suraj.gupta// w w w. ja v a2 s .c o m */ public static void main(String[] args) { String s = "suraj.gupta@yahoo.com"; // email id in a String int IndexOf = s.indexOf("@"); // returns an integer which tells the position of this substring "@" in the parent String "suraj.gupta@yahoo.com" String domainName = s.substring(IndexOf); //prints the String after that index System.out.println("Taking Domain name from an email id " + domainName); }
From source file:net.kamhon.ieagle.vo.ManagerList.java
public static void main(String a[]) { try {/*from w ww . j ava 2 s .c o m*/ Set<String> clazzStr = ReflectionUtil.findFileNames("com", true, "net.kamhon.+?\\.manager\\..+?"); for (String str : clazzStr) { // if (clazz.) { // add(clazz); // } // add(str.getClass().getName()); log.info((str.substring(str.lastIndexOf(".") + 1).charAt(0) + "").toLowerCase() + str.substring(str.lastIndexOf(".") + 2)); } } catch (Exception e) { e.printStackTrace(); } }
From source file:MinAppletviewer.java
public static void main(String args[]) throws Exception { AppSupport theAppSupport = new AppSupport(); JFrame f = new JFrame(); URL toload = new URL(args[0]); String host = toload.getHost(); int port = toload.getPort(); String protocol = toload.getProtocol(); String path = toload.getFile(); int join = path.lastIndexOf('/'); String file = path.substring(join + 1); path = path.substring(0, join + 1);/*from w w w . j a v a2 s .c o m*/ theAppSupport.setCodeBase(new URL(protocol, host, port, path)); theAppSupport.setDocumentBase(theAppSupport.getCodeBase()); URL[] bases = { theAppSupport.getCodeBase() }; URLClassLoader loader = new URLClassLoader(bases); Class theAppletClass = loader.loadClass(file); Applet theApplet = (Applet) (theAppletClass.newInstance()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(theApplet, BorderLayout.CENTER); theApplet.setStub(theAppSupport); f.setSize(200, 200); f.setVisible(true); theApplet.init(); theApplet.start(); }