List of usage examples for java.lang String startsWith
public boolean startsWith(String prefix)
From source file:com.ibm.research.rdf.store.runtime.service.sql.UpdateHelper.java
public static void main(String[] args) { String JDBC_URL = "jdbc:db2://localhost:10997/lubm"; String user = "db2inst1"; String password = "db2admin"; String backend = "db2"; String schema = "db2inst1"; String store = "lubm_100m_r"; int lock = 1; int dph_size = 11; int rph_size = 4; String[][] triples = { { "http://usersub1/", "http://testpred1/", "http://userobj1/" }, { "http://usersub1/", "http://testpred2/", "http://userobj2/" }, { "http://usersub1/", "http://testpred1/", "userobj3" }, { "http://usersub2/", "http://testpred2/", "http://userobj2/" }, { "http://usersub1/", "http://testpred3/", "userobj4" }, { "http://usersub1/", "http://testpred4/", "userobj4" }, { "http://usersub2/", "http://testpred8/", "http://userobj2/" }, { "http://usersub2/", "http://testpred6/", "http://userobj2/" }, { "http://usersub2/", "http://testpred7/", "http://userobj2/" }, { "http://usersub1/", "http://testpred5/", "userobj5" }, { "http://usersub2/", "http://testpred9/", "http://userobj2/" }, { "http://usersub3/", "http://testpred2/", "http://userobj2/" }, { "http://usersub1/", "http://testpred1/", "userobj4" }, { "http://usersub1/", "http://testpred1/", "userobj5" }, { "http://usersub1/", "http://testpred3/", "userobj5" }, { "http://usersub4/", "http://testpred2/", "http://userobj2/" }, { "http://usersub3/", "http://testpred1/", "userobj3" } }; try {// ww w .j av a2s . c om String classNameString = new String("com.ibm.db2.jcc.DB2Driver"); Class.forName(classNameString); Connection conn = DriverManager.getConnection(JDBC_URL, user, password); String gid = "DEF"; //add triples to graph DEF for (int i = 0; i < triples.length; i++) { String sub = triples[i][0]; String pred = triples[i][1]; String obj = triples[i][2]; int obj_dt = obj.startsWith("http://") ? 10002 : 5001; int dft_col = i % 2; addTriple(conn, backend, schema, store, sub, pred, obj, obj_dt, dft_col, dft_col, gid, lock); } gid = "G1"; //add triples to graph G1 //some operations will fail due to UNIQUE indexes (on DS, RS) without GID for (int i = 0; i < triples.length; i++) { String sub = triples[i][0]; String pred = triples[i][1]; String obj = triples[i][2]; int obj_dt = obj.startsWith("http://") ? 10002 : 5001; int dft_col = i % 2; addTriple(conn, backend, schema, store, sub, pred, obj, obj_dt, dft_col, dft_col, gid, lock); } gid = "DEF"; //delete triples to graph DEF for (int i = triples.length - 1; i >= 0; i--) { String sub = triples[i][0]; String pred = triples[i][1]; String obj = triples[i][2]; int dft_col = i % 2; deleteTriple(conn, backend, schema, store, sub, pred, obj, dph_size, rph_size, dft_col, dft_col, gid, lock); } gid = "G1"; //delete triples to graph G1 for (int i = triples.length - 1; i >= 0; i--) { String sub = triples[i][0]; String pred = triples[i][1]; String obj = triples[i][2]; int dft_col = i % 2; deleteTriple(conn, backend, schema, store, sub, pred, obj, dph_size, rph_size, dft_col, dft_col, gid, lock); } } catch (SQLException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } }
From source file:org.biopax.validator.Main.java
public static void main(String[] args) throws Exception { setUpLogger();/*from w w w . j a va2 s.c o m*/ if (args == null || args.length == 0) { log.warn("At least input file/dir must be specified."); printHelpAndQuit(); } String input = args[0]; if (input == null || input.isEmpty() || input.startsWith("--")) { log.warn("Input (file, url, or directory) is probably missing"); printHelpAndQuit(); } // match optional parameters for (int i = 1; i < args.length; i++) { if ("--auto-fix".equalsIgnoreCase(args[i])) { autofix = true; } else if (args[i].startsWith("--max-errors=")) { String n = args[i].substring(13); maxErrors = Integer.parseInt(n); } else if (args[i].startsWith("--profile=")) { profile = args[i].substring(10); } else if (args[i].startsWith("--xmlBase=")) { xmlBase = args[i].substring(10); } else if (args[i].startsWith("--output=")) { output = args[i].substring(9); } else if (args[i].startsWith("--out-format=")) { outFormat = args[i].substring(13); if (outFormat.isEmpty()) outFormat = "html"; } } // this does 90% of the job ;) ctx = new ClassPathXmlApplicationContext(new String[] { "META-INF/spring/appContext-loadTimeWeaving.xml", "META-INF/spring/appContext-validator.xml" }); // Rules are now loaded, and AOP is listening for BioPAX model method calls. // get the beans to work with Validator validator = (Validator) ctx.getBean("validator"); // go validate all runBatch(validator, getResourcesToValidate(input)); }
From source file:at.treedb.util.SevenZip.java
public static void main(String args[]) throws IOException { System.out.println("Extract"); HashMap<String, byte[]> map = exctact(new File("c:/TreeDBdata/domains/ZooDB.7z"), "info.xml", "classes/"); for (String s : map.keySet()) { if (s.startsWith("classes/")) { String className = s.substring("classes/".length(), s.lastIndexOf(".class")).replace("/", "."); System.out.println(className); }//w ww.ja v a 2 s . co m } }
From source file:edu.stanford.muse.email.MboxEmailStore.java
public static void main(String args[]) throws MessagingException, IOException { LineNumberReader lnr = new LineNumberReader(new BufferedReader( new InputStreamReader(new FileInputStream("/Users/hangal/Local Folders/gmail-sent")))); int count = 0; while (true) { String line = lnr.readLine(); if (line == null) break; if (line.startsWith("From ")) count++;/*from w ww. ja va2 s . com*/ } System.out.println(count + " messages found"); }
From source file:SelectorChat.java
/** Main program entry point. */ public static void main(String argv[]) { // Is there anything to do? if (argv.length == 0) { printUsage();/* www . j a va2s .c om*/ System.exit(1); } // Values to be read from parameters String broker = DEFAULT_BROKER_NAME; String username = null; String password = DEFAULT_PASSWORD; String selection = null; // Check parameters for (int i = 0; i < argv.length; i++) { String arg = argv[i]; // Options if (!arg.startsWith("-")) { System.err.println("error: unexpected argument - " + arg); printUsage(); System.exit(1); } else { if (arg.equals("-b")) { if (i == argv.length - 1 || argv[i + 1].startsWith("-")) { System.err.println("error: missing broker name:port"); System.exit(1); } broker = argv[++i]; continue; } if (arg.equals("-u")) { if (i == argv.length - 1 || argv[i + 1].startsWith("-")) { System.err.println("error: missing user name"); System.exit(1); } username = argv[++i]; continue; } if (arg.equals("-p")) { if (i == argv.length - 1 || argv[i + 1].startsWith("-")) { System.err.println("error: missing password"); System.exit(1); } password = argv[++i]; continue; } if (arg.equals("-s")) { if (i == argv.length - 1 || argv[i + 1].startsWith("-")) { System.err.println("error: missing selection"); System.exit(1); } selection = argv[++i]; continue; } if (arg.equals("-h")) { printUsage(); System.exit(1); } } } // Check values read in. if (username == null) { System.err.println("error: user name must be supplied"); printUsage(); } if (selection == null) { System.err.println("error: selection must be supplied"); printUsage(); System.exit(1); } // Start the JMS client for the "chat". SelectorChat chat = new SelectorChat(); chat.chatter(broker, username, password, selection); }
From source file:HierarchicalChat.java
/** Main program entry point. */ public static void main(String argv[]) { // Is there anything to do? if (argv.length == 0) { printUsage();/*from w w w . j a v a 2s . c om*/ System.exit(1); } // Values to be read from parameters String broker = DEFAULT_BROKER_NAME; String username = null; String password = DEFAULT_PASSWORD; String pubTopicname = DEFAULT_PUBLISHER_TOPIC; String subTopicname = DEFAULT_SUBSCRIBER_TOPIC; // Check parameters for (int i = 0; i < argv.length; i++) { String arg = argv[i]; // Options if (!arg.startsWith("-")) { System.err.println("error: unexpected argument - " + arg); printUsage(); System.exit(1); } else { if (arg.equals("-b")) { if (i == argv.length - 1 || argv[i + 1].startsWith("-")) { System.err.println("error: missing broker name:port"); System.exit(1); } broker = argv[++i]; continue; } if (arg.equals("-u")) { if (i == argv.length - 1 || argv[i + 1].startsWith("-")) { System.err.println("error: missing user name"); System.exit(1); } username = argv[++i]; continue; } if (arg.equals("-p")) { if (i == argv.length - 1 || argv[i + 1].startsWith("-")) { System.err.println("error: missing password"); System.exit(1); } password = argv[++i]; continue; } if (arg.equals("-t")) { if (i == argv.length - 1 || argv[i + 1].startsWith("-")) { System.err.println("error: missing publisher topic name"); System.exit(1); } pubTopicname = argv[++i]; continue; } if (arg.equals("-s")) { if (i == argv.length - 1 || argv[i + 1].startsWith("-")) { System.err.println("error: missing subscriber topic name"); System.exit(1); } subTopicname = argv[++i]; continue; } if (arg.equals("-h")) { printUsage(); System.exit(1); } } } // Check values read in. if (username == null) { System.err.println("error: user name must be supplied"); printUsage(); } // Start the JMS client for the "chat". HierarchicalChat chat = new HierarchicalChat(); chat.chatter(broker, username, password, pubTopicname, subTopicname); }
From source file:bixo.tools.LengthenUrlsTool.java
/** * @param args - URL to fetch, or path to file of URLs *//*from ww w .j a va2 s . c o m*/ @SuppressWarnings("rawtypes") public static void main(String[] args) { try { String url = null; if (args.length == 0) { System.out.print("URL to lengthen: "); url = readInputLine(); if (url.length() == 0) { System.exit(0); } if (!url.startsWith("http://")) { url = "http://" + url; } } else if (args.length != 1) { System.out.print("A single URL or filename parameter is allowed"); System.exit(0); } else { url = args[0]; } String filename; if (!url.startsWith("http://")) { // It's a path to a file of URLs filename = url; } else { // We have a URL that we need to write to a temp file. File tempFile = File.createTempFile("LengthenUrlsTool", "txt"); filename = tempFile.getAbsolutePath(); FileWriter fw = new FileWriter(tempFile); IOUtils.write(url, fw); fw.close(); } System.setProperty("bixo.root.level", "TRACE"); // Uncomment this to see the wire log for HttpClient // System.setProperty("bixo.http.level", "DEBUG"); BaseFetcher fetcher = UrlLengthener.makeFetcher(10, ConfigUtils.BIXO_TOOL_AGENT); Pipe pipe = new Pipe("urls"); pipe = new Each(pipe, new UrlLengthener(fetcher)); pipe = new Each(pipe, new Debug()); BixoPlatform platform = new BixoPlatform(LengthenUrlsTool.class, Platform.Local); BasePath filePath = platform.makePath(filename); TextLine textLineLocalScheme = new TextLine(new Fields("url")); Tap sourceTap = platform.makeTap(textLineLocalScheme, filePath, SinkMode.KEEP); SinkTap sinkTap = new NullSinkTap(new Fields("url")); FlowConnector flowConnector = platform.makeFlowConnector(); Flow flow = flowConnector.connect(sourceTap, sinkTap, pipe); flow.complete(); } catch (Exception e) { System.err.println("Exception running tool: " + e.getMessage()); e.printStackTrace(System.err); System.exit(-1); } }
From source file:Talk.java
/** Main program entry point. */ public static void main(String argv[]) { // Is there anything to do? if (argv.length == 0) { printUsage();/*from w w w. j av a 2 s . com*/ System.exit(1); } // Values to be read from parameters String broker = DEFAULT_BROKER_NAME; String username = null; String password = DEFAULT_PASSWORD; String qSender = null; String qReceiver = null; // Check parameters for (int i = 0; i < argv.length; i++) { String arg = argv[i]; // Options if (!arg.startsWith("-")) { System.err.println("error: unexpected argument - " + arg); printUsage(); System.exit(1); } else { if (arg.equals("-b")) { if (i == argv.length - 1 || argv[i + 1].startsWith("-")) { System.err.println("error: missing broker name:port"); System.exit(1); } broker = argv[++i]; continue; } if (arg.equals("-u")) { if (i == argv.length - 1 || argv[i + 1].startsWith("-")) { System.err.println("error: missing user name"); System.exit(1); } username = argv[++i]; continue; } if (arg.equals("-p")) { if (i == argv.length - 1 || argv[i + 1].startsWith("-")) { System.err.println("error: missing password"); System.exit(1); } password = argv[++i]; continue; } if (arg.equals("-qr")) { if (i == argv.length - 1 || argv[i + 1].startsWith("-")) { System.err.println("error: missing receive queue parameter"); System.exit(1); } qReceiver = argv[++i]; continue; } if (arg.equals("-qs")) { if (i == argv.length - 1 || argv[i + 1].startsWith("-")) { System.err.println("error: missing send queue parameter"); System.exit(1); } qSender = argv[++i]; continue; } if (arg.equals("-h")) { printUsage(); System.exit(1); } } } // Check values read in. if (username == null) { System.err.println("error: user name must be supplied"); printUsage(); System.exit(1); } if (qReceiver == null && qSender == null) { System.err.println("error: receive queue, or send queue, must be supplied"); printUsage(); System.exit(1); } // Start the JMS client for the "Talk". Talk talk = new Talk(); talk.talker(broker, username, password, qReceiver, qSender); }
From source file:com.mgmtp.jfunk.core.JFunk.java
/** * Starts jFunk./*from w w w . j a v a 2 s.c om*/ * * <pre> * -threadcount=<count> Optional Number of threads to be used. Allows for parallel * execution of test scripts. * -parallel Optional Allows a single script to be executed in parallel * depending on the number of threads specified. The * argument is ignored if multiple scripts are specified. * <script parameters> Optional Similar to Java system properties they can be provided * as key-value-pairs preceded by -S, e.g. -Skey=value. * These parameters are then available in the script as * Groovy variables. * <script(s)> Required At least one test script must be specified. * * Example: * java -cp <jFunkClasspath> com.mgmtp.jfunk.core.JFunk -Skey=value -threadcount=4 -parallel mytest.script * </pre> * * @param args * The program arguments. */ public static void main(final String[] args) { SLF4JBridgeHandler.install(); boolean exitWithError = true; StopWatch stopWatch = new StopWatch(); try { RESULT_LOG.info("jFunk started"); stopWatch.start(); int threadCount = 1; boolean parallel = false; Properties scriptProperties = new Properties(); List<File> scripts = Lists.newArrayList(); for (String arg : args) { if (arg.startsWith("-threadcount")) { String[] split = arg.split("="); Preconditions.checkArgument(split.length == 2, "The number of threads must be specified as follows: -threadcount=<value>"); threadCount = Integer.parseInt(split[1]); RESULT_LOG.info("Using " + threadCount + (threadCount == 1 ? " thread" : " threads")); } else if (arg.startsWith("-S")) { arg = arg.substring(2); String[] split = arg.split("="); Preconditions.checkArgument(split.length == 2, "Script parameters must be given in the form -S<name>=<value>"); scriptProperties.setProperty(split[0], normalizeScriptParameterValue(split[1])); RESULT_LOG.info("Using script parameter " + split[0] + " with value " + split[1]); } else if (arg.equals("-parallel")) { parallel = true; RESULT_LOG.info("Using parallel mode"); } else { scripts.add(new File(arg)); } } if (scripts.isEmpty()) { scripts.addAll(requestScriptsViaGui()); if (scripts.isEmpty()) { RESULT_LOG.info("Execution finished (took " + stopWatch + " H:mm:ss.SSS)"); System.exit(0); } } String propsFileName = System.getProperty("jfunk.props.file", "jfunk.properties"); Module module = ModulesLoader.loadModulesFromProperties(new JFunkDefaultModule(), propsFileName); Injector injector = Guice.createInjector(module); JFunkFactory factory = injector.getInstance(JFunkFactory.class); JFunkBase jFunk = factory.create(threadCount, parallel, scripts, scriptProperties); jFunk.execute(); exitWithError = false; } catch (JFunkExecutionException ex) { // no logging necessary } catch (Exception ex) { Logger.getLogger(JFunk.class).error("jFunk terminated unexpectedly.", ex); } finally { stopWatch.stop(); RESULT_LOG.info("Execution finished (took " + stopWatch + " H:mm:ss.SSS)"); } System.exit(exitWithError ? -1 : 0); }
From source file:com.sun.faban.harness.util.CLI.java
/** * The first argument to the CLI is the action. It can be:<ul> * <li>pending</li>//from w w w.j ava 2 s . c o m * <li>status runId</li> * <li>submit benchmark profile configfile.xml</ul> * </ul> * * @param args The command line arguments. */ public static void main(String[] args) { if (args.length == 0) { printUsage(); System.exit(1); } ArrayList<String> argList = new ArrayList<String>(); // Do the getopt thing. char opt = (char) -1; String master = null; String user = null; String password = null; for (String arg : args) { if (arg.startsWith("-M")) { String optArg = arg.substring(2); if (optArg.length() == 0) { opt = 'M'; continue; } master = optArg; } else if (arg.startsWith("-U")) { String optArg = arg.substring(2); if (optArg.length() == 0) { opt = 'U'; continue; } user = optArg; } else if (arg.startsWith("-P")) { String optArg = arg.substring(2); if (optArg.length() == 0) { opt = 'P'; continue; } password = optArg; } else if (opt != (char) -1) { switch (opt) { case 'M': master = arg; opt = (char) -1; break; case 'U': user = arg; opt = (char) -1; break; case 'P': password = arg; opt = (char) -1; break; } } else { argList.add(arg); opt = (char) -1; } } if (master == null) master = "http://localhost:9980/"; else if (!master.endsWith("/")) master += '/'; CLI cli = new CLI(); String action = argList.get(0); try { if ("pending".equals(action)) { cli.doGet(master + "pending"); } else if ("status".equals(action)) { if (argList.size() > 1) cli.doGet(master + "status/" + argList.get(1)); else printUsage(); } else if ("submit".equals(action)) { if (argList.size() > 3) { cli.doPostSubmit(master, user, password, argList); } else { printUsage(); System.exit(1); } } else if ("kill".equals(action)) { if (argList.size() > 1) { cli.doPostKill(master, user, password, argList); } else { printUsage(); System.exit(1); } } else if ("wait".equals(action)) { if (argList.size() > 1) { cli.pollStatus(master + "status/" + argList.get(1)); } else { printUsage(); System.exit(1); } } else if ("showlogs".equals(action)) { StringBuilder url = new StringBuilder(); if (argList.size() > 1) { url.append(master).append("logs/"); url.append(argList.get(1)); } else { printUsage(); } for (int i = 2; i < argList.size(); i++) { if ("-t".equals(argList.get(i))) url.append("/tail"); if ("-f".equals(argList.get(i))) url.append("/follow"); if ("-ft".equals(argList.get(i))) url.append("/tail/follow"); if ("-tf".equals(argList.get(i))) url.append("/tail/follow"); } cli.doGet(url.toString()); } else { printUsage(); } } catch (IOException e) { System.err.println(e.getMessage()); System.exit(1); } }