List of usage examples for java.lang String substring
public String substring(int beginIndex)
From source file:org.eclipse.swt.snippets.Snippet327.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 327"); shell.setLayout(new FillLayout()); final Browser browser; try {//from w w w.ja v a 2s . com browser = new Browser(shell, SWT.NONE); } catch (SWTError e) { System.out.println("Could not instantiate Browser: " + e.getMessage()); display.dispose(); return; } browser.setText(createPage(0)); browser.addLocationListener(LocationListener.changingAdapter(event -> { String location = event.location; int index = location.indexOf(PREAMBLE); if (index != -1) { int pageNumber = Integer.valueOf(location.substring(index + PREAMBLE.length())).intValue(); browser.setText(createPage(pageNumber)); event.doit = false; } })); shell.setBounds(10, 10, 200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:postenergy.PostHttpClient.java
public static void main(String[] args) { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://iplant.dk/addData.php?n=mindass"); try {/*from w ww . j a va 2 s. c om*/ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("?n", "=mindass")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); if (line.startsWith("Input:")) { String key = line.substring(6); // do something with the key System.out.println("key:" + key); } } } catch (IOException e) { System.out.println("There was an error: " + e); } }
From source file:ListAlgorithms.java
public static void main(String[] args) { Provider[] providers = Security.getProviders(); Set<String> ciphers = new HashSet<String>(); Set<String> keyAgreements = new HashSet<String>(); Set<String> macs = new HashSet<String>(); Set<String> messageDigests = new HashSet<String>(); Set<String> signatures = new HashSet<String>(); for (int i = 0; i != providers.length; i++) { Iterator it = providers[i].keySet().iterator(); while (it.hasNext()) { String entry = (String) it.next(); if (entry.startsWith("Alg.Alias.")) { entry = entry.substring("Alg.Alias.".length()); }// ww w . ja va2 s . c om if (entry.startsWith("Cipher.")) { ciphers.add(entry.substring("Cipher.".length())); } else if (entry.startsWith("KeyAgreement.")) { keyAgreements.add(entry.substring("KeyAgreement.".length())); } else if (entry.startsWith("Mac.")) { macs.add(entry.substring("Mac.".length())); } else if (entry.startsWith("MessageDigest.")) { messageDigests.add(entry.substring("MessageDigest.".length())); } else if (entry.startsWith("Signature.")) { signatures.add(entry.substring("Signature.".length())); } } } printSet("Ciphers", ciphers); printSet("KeyAgreeents", keyAgreements); printSet("Macs", macs); printSet("MessageDigests", messageDigests); printSet("Signatures", signatures); }
From source file:com.data2semantics.yasgui.server.db.ConnectionFactory.java
public static void main(String[] args) { String basename = "delta_10.sql"; basename = basename.substring("delta_".length()); basename = basename.substring(0, basename.length() - ".sql".length()); }
From source file:postenergy.TestHttpClient.java
public static void main(String[] args) { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("https://www.google.com/accounts/ClientLogin"); try {//from ww w. ja va2 s .c o m List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("Email", "youremail")); nameValuePairs.add(new BasicNameValuePair("Passwd", "yourpassword")); nameValuePairs.add(new BasicNameValuePair("accountType", "GOOGLE")); nameValuePairs.add(new BasicNameValuePair("source", "Google-cURL-Example")); nameValuePairs.add(new BasicNameValuePair("service", "ac2dm")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); if (line.startsWith("Auth=")) { String key = line.substring(5); // do something with the key } } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.claresco.tinman.servlet.XapiServletUtility.java
public static void main(String[] args) { ArrayList<String> theData = new ArrayList<String>(); theData.add("aldfjaklfja"); theData.add("duo"); System.out.println(createJsonArray(theData)); try {//from w w w.j a va 2 s . co m System.out.println(decodeBase64("dGVzdDpwYXNzd29yZA==")); } catch (Exception e) { } String st = "Basic dGVzdDpwYXNzd29yZA=="; System.out.println(st.substring(5)); System.out.println(encodeBase64("cremebrulee#$%:Comeatmebro***")); System.out.println(createHeaderString(theData)); }
From source file:dk.statsbiblioteket.util.qa.PackageScannerDriver.java
/** * @param args The command line arguments. * @throws IOException If command line arguments can't be passed or there * is an error reading class files. *//*from ww w .ja v a 2s . c om*/ @SuppressWarnings("deprecation") public static void main(final String[] args) throws IOException { Report report; CommandLine cli = null; String reportType, projectName, baseSrcDir, targetPackage; String[] targets = null; // Build command line options CommandLineParser cliParser = new PosixParser(); Options options = new Options(); options.addOption("h", "help", false, "Print help message and exit"); options.addOption("n", "name", true, "Project name, default 'Unknown'"); options.addOption("o", "output", true, "Type of output, 'plain' or 'html', default is html"); options.addOption("p", "package", true, "Only scan a particular package in input dirs, use dotted " + "package notation to refine selections"); options.addOption("s", "source-dir", true, "Base source dir to use in report, can be a URL. " + "@FILE@ and @MODULE@ will be escaped"); // Parse and validate command line try { cli = cliParser.parse(options, args); targets = cli.getArgs(); if (args.length == 0 || targets.length == 0 || cli.hasOption("help")) { throw new ParseException("Not enough arguments, no input files"); } } catch (ParseException e) { printHelp(options); System.exit(1); } // Extract information from command line reportType = cli.getOptionValue("output") != null ? cli.getOptionValue("output") : "html"; projectName = cli.getOptionValue("name") != null ? cli.getOptionValue("name") : "Unknown"; baseSrcDir = cli.getOptionValue("source-dir") != null ? cli.getOptionValue("source-dir") : System.getProperty("user.dir"); targetPackage = cli.getOptionValue("package") != null ? cli.getOptionValue("package") : ""; targetPackage = targetPackage.replace(".", File.separator); // Set up report type if ("plain".equals(reportType)) { report = new BasicReport(); } else { report = new HTMLReport(projectName, System.out, baseSrcDir); } // Do actual scanning of provided targets for (String target : targets) { PackageScanner scanner; File f = new File(target); if (f.isDirectory()) { scanner = new PackageScanner(report, f, targetPackage); } else { String filename = f.toString(); scanner = new PackageScanner(report, f.getParentFile(), filename.substring(filename.lastIndexOf(File.separator) + 1)); } scanner.scan(); } // Cloce the report before we exit report.end(); }
From source file:au.csiro.casda.sodalint.SodaLinter.java
/** * Command line handler for SodaLinter// www . ja va2 s . c o m * @param args The command line arguments * @throws Exception If an otherwise uncaught error occurs. */ public static void main(String[] args) throws Exception { SodaLinter linter = new SodaLinter(); String[] stages = null; final int defaultMaxRepeat = 9; final int defaultMaxLineLen = 1024; int maxRepeat = defaultMaxRepeat; int maxLineLen = defaultMaxLineLen; String sodaUrl = null; boolean error = false; for (String arg : args) { if (arg.startsWith("stages=")) { stages = arg.substring("stages=".length()).split(" "); } else if (arg.startsWith("maxrepeat=")) { String value = arg.substring("maxrepeat=".length()); if (StringUtils.isNumeric(value)) { maxRepeat = Integer.parseInt(value); } else { error = true; } } else if (arg.startsWith("truncate=")) { String value = arg.substring("truncate=".length()); if (StringUtils.isNumeric(value)) { maxLineLen = Integer.parseInt(value); } else { error = true; } } else { sodaUrl = arg.startsWith("sodaurl=") ? arg.substring("sodaurl=".length()) : arg; } } if (sodaUrl == null || error) { System.out.println( "Usage: java -jar sodalint-full.jar [stages=\"CPV|CAP|AVV|EXM|SVD|ERR|SYN|ASY[ ...]\"] " + "[maxrepeat=<int-value>] [truncate=<int-value>] [sodaurl=]<url-value>"); System.exit(1); } TextOutputReporter reporter = new TextOutputReporter(System.out, ReportType.values(), maxRepeat, false, maxLineLen); // URL serviceUrl = new URL("https://casda-dev-app.pawsey.org.au/casda_data_access/data/"); URL serviceUrl = new URL(sodaUrl); String[] defaultStages = new String[] { Stage.CAP_XML.getCode(), Stage.AVAIL_XML.getCode(), Stage.CAPABILITIES.getCode(), Stage.SYNC.getCode(), Stage.ASYNC.getCode(), Stage.SERVICE_DESC.getCode() }; Set<String> codes = new HashSet<>(Arrays.asList(stages != null ? stages : defaultStages)); Executable executable = linter.createExecutable(reporter, serviceUrl, codes, null); executable.execute(); }
From source file:ShowComponent.java
public static void main(String[] args) { // Process the command line to get the components to display Vector components = getComponentsFromArgs(args); // Create a frame (a window) to display them in JFrame frame = new JFrame("ShowComponent"); // Handle window close requests by exiting the VM frame.addWindowListener(new WindowAdapter() { // Anonymous inner class public void windowClosing(WindowEvent e) { System.exit(0);/* w w w . ja va 2 s. co m*/ } }); // Set up a menu system that allows the user to select the // look-and-feel of the component from a list of installed PLAFs JMenuBar menubar = new JMenuBar(); // Create a menubar frame.setJMenuBar(menubar); // Tell the frame to display it JMenu plafmenu = createPlafMenu(frame); // Create a menu menubar.add(plafmenu); // Add the menu to the menubar // Create a JTabbedPane to display each of the components JTabbedPane pane = new JTabbedPane(); // Now add each component as a tab of the tabbed pane // Use the unqualified component classname as the tab text for (int i = 0; i < components.size(); i++) { Component c = (Component) components.elementAt(i); String classname = c.getClass().getName(); String tabname = classname.substring(classname.lastIndexOf('.') + 1); pane.addTab(tabname, c); } // Add the tabbed pane to the frame. Note the call to getContentPane() // This is required for JFrame, but not for most Swing components frame.getContentPane().add(pane); // Set the frame size and pop it up frame.pack(); // Make frame as big as its kids need frame.setVisible(true); // Make the frame visible on the screen // The main() method exits now but the Java VM keeps running because // all AWT programs automatically start an event-handling thread. }
From source file:org.nira.wso2.nexus.ComponentVersion.java
public static void main(String[] args) { urlList.add(Constants.REPO_MAVEN);//from ww w.ja va 2 s . c o m urlList.add(Constants.REPO_MAVEN_WSO2_RELEASES); urlList.add(Constants.REPO_MAVEN_WSO2_PUBLIC); String pomFilePath = ""; boolean ignoreSameVersion = false; for (String arg : args) { if (arg.startsWith(Constants.CMD_POM_FILE)) { pomFilePath = arg.substring(Constants.CMD_POM_FILE.length() + 1); } else if (arg.startsWith(Constants.CMD_IGNORE_SAME_VERSION)) { String param = arg.substring(Constants.CMD_IGNORE_SAME_VERSION.length() + 1); if ("true".equals(param)) { ignoreSameVersion = true; } } } // pomFilePath = "C:\\Users\\Nira\\Desktop\\as_pom.xml"; if (pomFilePath.isEmpty()) { throw new ComponentException("Pom File path not specified!"); } readPomFile(pomFilePath); displayComponents(ignoreSameVersion); }