List of usage examples for java.lang String endsWith
public boolean endsWith(String suffix)
From source file:Main.java
public static void main(String[] args) { String str = "This is a test"; // Test str, if it starts with "This" if (str.startsWith("This")) { System.out.println("String starts with This"); } else {// w ww.j a v a2 s . c o m System.out.println("String does not start with This"); } // Test str, if it ends with "program" if (str.endsWith("program")) { System.out.println("String ends with program"); } else { System.out.println("String does not end with program"); } }
From source file:org.cbio.portal.pipelines.FoundationPipeline.java
public static void main(String[] args) throws Exception { Options gnuOptions = FoundationPipeline.getOptions(args); CommandLineParser parser = new GnuParser(); CommandLine commandLine = parser.parse(gnuOptions, args); if (commandLine.hasOption("h") || !commandLine.hasOption("source") || !commandLine.hasOption("output") || !commandLine.hasOption("cancer_study_id")) { help(gnuOptions, 0);/*from w w w . j av a 2s . co m*/ } for (String v : commandLine.getArgList()) { System.out.println(v); } // light pre-processing for source directory and output directory paths String sourceDirectory = commandLine.getOptionValue("source"); String outputDirectory = commandLine.getOptionValue("output"); String cancerStudyId = commandLine.getOptionValue("cancer_study_id"); if (!sourceDirectory.endsWith(File.separator)) sourceDirectory += File.separator; if (!outputDirectory.endsWith(File.separator)) outputDirectory += File.separator; // determine whether to run xml document generator job or not boolean generateXmlDocument = commandLine.hasOption("generate_xml"); launchJob(args, sourceDirectory, outputDirectory, cancerStudyId, generateXmlDocument); }
From source file:edu.ucla.cs.scai.swim.qa.ontology.dbpedia.tipicality.DbpediaCategoryAttributeCounts.java
public static void main(String args[]) throws FileNotFoundException, IOException { stopAttributes.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); stopAttributes.add("http://www.w3.org/2002/07/owl#sameAs"); stopAttributes.add("http://dbpedia.org/ontology/wikiPageRevisionID"); stopAttributes.add("http://dbpedia.org/ontology/wikiPageID"); stopAttributes.add("http://purl.org/dc/elements/1.1/description"); stopAttributes.add("http://dbpedia.org/ontology/thumbnail"); //stopAttributes.add("http://dbpedia.org/ontology/type"); String path = DBpediaOntology.DBPEDIA_CSV_FOLDER; if (args != null && args.length > 0) { path = args[0];//from w ww . j av a 2 s . c o m if (!path.endsWith("/")) { path = path + "/"; } } File folder = new File(path); if (!folder.exists()) { System.out.println("The path with DBpedia CSV files is set as " + path); System.out.println("You need to change the path with the correct one on your PC"); System.exit(0); } for (File f : new File(path).listFiles()) { if (f.isFile() && f.getName().endsWith(".csv.gz")) { System.out.println("Processing file " + f.getName() + "..."); processFile(f, f.getName().replaceAll("\\.csv.gz", "")); } } System.out.println(entities.size() + " entities processed"); System.out.println(categories.size() + " categories found"); System.out.println(attributes.size() + " attributes found"); try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(path + "counts.bin"))) { oos.writeObject(categories); oos.writeObject(attributes); oos.writeObject(categoryCount); oos.writeObject(attributeCount); oos.writeObject(categoryAttributeCount); oos.writeObject(attributeCategoryCount); } }
From source file:es.eucm.ead.exporter.ExporterMain.java
@SuppressWarnings("all") public static void main(String args[]) { Options options = new Options(); Option help = new Option("h", "help", false, "print this message"); Option quiet = new Option("q", "quiet", false, "be extra quiet"); Option verbose = new Option("v", "verbose", false, "be extra verbose"); Option legacy = OptionBuilder.withArgName("s> <t").hasArgs(3) .withDescription(/* w w w. j av a 2 s . com*/ "source is a version 1.x game; must specify\n" + "<simplify> if 'true', simplifies result\n" + "<translate> if 'true', enables translation") .withLongOpt("import").create("i"); Option war = OptionBuilder.withArgName("web-base").hasArg() .withDescription("WAR packaging (web app); " + "must specify\n<web-base> the base WAR directory") .withLongOpt("war").create("w"); Option jar = OptionBuilder.withDescription("JAR packaging (desktop)").withLongOpt("jar").create("j"); Option apk = OptionBuilder.withArgName("props> <adk> <d").hasArgs(3) .withDescription("APK packaging (android); must specify \n" + "<props> (a properties file) \n" + "<adk> (location of the ADK to use) \n" + "<deploy> ('true' to install & deploy)") .withLongOpt("apk").create("a"); // EAD option Option ead = OptionBuilder.withDescription("EAD packaging (eAdventure)").withLongOpt("ead").create("e"); options.addOption(legacy); options.addOption(help); options.addOption(quiet); options.addOption(verbose); options.addOption(jar); options.addOption(war); options.addOption(apk); options.addOption(ead); CommandLineParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException pe) { System.err.println("Error parsing command-line: " + pe.getMessage()); showHelp(options); return; } // general options String[] extras = cmd.getArgs(); if (cmd.hasOption(help.getOpt()) || extras.length < 2) { showHelp(options); return; } if (cmd.hasOption(verbose.getOpt())) { verbosity = Verbose; } if (cmd.hasOption(quiet.getOpt())) { verbosity = Quiet; } // import String source = extras[0]; // optional import step if (cmd.hasOption(legacy.getOpt())) { String[] values = cmd.getOptionValues(legacy.getOpt()); AdventureConverter converter = new AdventureConverter(); if (values.length > 0 && values[0].equalsIgnoreCase("true")) { converter.setEnableSimplifications(true); } if (values.length > 1 && values[1].equalsIgnoreCase("true")) { converter.setEnableTranslations(true); } // set source for next steps to import-target source = converter.convert(source, null); } if (cmd.hasOption(jar.getOpt())) { if (checkFilesExist(cmd, options, source)) { JarExporter e = new JarExporter(); e.export(source, extras[1], verbosity.equals(Quiet) ? new QuietStream() : System.err); } } else if (cmd.hasOption(apk.getOpt())) { String[] values = cmd.getOptionValues(apk.getOpt()); if (checkFilesExist(cmd, options, values[0], values[1], source)) { AndroidExporter e = new AndroidExporter(); Properties props = new Properties(); File propsFile = new File(values[0]); try { props.load(new FileReader(propsFile)); props.setProperty(AndroidExporter.SDK_HOME, props.getProperty(AndroidExporter.SDK_HOME, values[1])); } catch (IOException ioe) { System.err.println("Could not load properties from " + propsFile.getAbsolutePath()); return; } e.export(source, extras[1], props, values.length > 2 && values[2].equalsIgnoreCase("true")); } } else if (cmd.hasOption(war.getOpt())) { if (checkFilesExist(cmd, options, extras[0])) { WarExporter e = new WarExporter(); e.setWarPath(cmd.getOptionValue(war.getOpt())); e.export(source, extras[1]); } } else if (cmd.hasOption(ead.getOpt())) { String destiny = extras[1]; if (!destiny.endsWith(".ead")) { destiny += ".ead"; } FileUtils.zip(new File(destiny), new File(source)); } else { showHelp(options); } }
From source file:net.sf.firemox.xml.magic.Oracle2XmlNoRules.java
/** * <ul>/* w w w . j a va 2 s. c o m*/ * Argument are (in this order : * <li>Oracle source file * <li>destination directory * </ul> * * @param args */ public static void main(String... args) { options = new Options(); final CmdLineParser parser = new CmdLineParser(options); try { parser.parseArgument(args); } catch (CmdLineException e) { // Display help if (!options.isHelp()) { System.out.println("Wrong parameters : " + e.getMessage()); } else { System.out.println("Usage"); } parser.setUsageWidth(100); parser.printUsage(System.out); System.exit(-1); return; } if (options.isVersion()) { // Display version System.out.println("Version is " + IdConst.VERSION); System.exit(-1); return; } if (options.isHelp()) { // Display help System.out.println("Usage"); parser.setUsageWidth(100); parser.printUsage(System.out); System.exit(-1); return; } // The oracle source file final String oracle = options.getOracleFile(); // the directory destination end with the file separator String destination = FilenameUtils.separatorsToWindows(options.getDestination()); if (!destination.endsWith("/")) { destination += "/"; } // Create the destination directories try { new File(destination).mkdirs(); } catch (Exception e) { // Ignore this error and continue } new Oracle2XmlNoRules().serialize(MToolKit.getFile(oracle), MToolKit.getFile(destination), MToolKit.getFile("tbs/norules-mtg/recycled/")); }
From source file:org.biopax.validator.BiopaxValidatorClient.java
/** * Checks BioPAX files using the online BioPAX Validator. * //from www . j av a2s. com * @see <a href="http://www.biopax.org/validator">BioPAX Validator Webservice</a> * * @param argv * @throws IOException */ public static void main(String[] argv) throws IOException { if (argv.length == 0) { System.err.println("Available parameters: \n" + "<path> <output> [xml|html|biopax] [auto-fix] [only-errors] [maxerrors=n] [notstrict]\n" + "\t- validate a BioPAX file/directory (up to ~25MB in total size, -\n" + "\totherwise, please use the biopax-validator.jar instead)\n" + "\tin the directory using the online BioPAX Validator service\n" + "\t(generates html or xml report, or gets the processed biopax\n" + "\t(cannot fix all errros though) see http://www.biopax.org/validator)"); System.exit(-1); } final String input = argv[0]; final String output = argv[1]; File fileOrDir = new File(input); if (!fileOrDir.canRead()) { System.err.println("Cannot read from " + input); System.exit(-1); } if (output == null || output.isEmpty()) { System.err.println("No output file specified (for the validation report)."); System.exit(-1); } // default options RetFormat outf = RetFormat.HTML; boolean fix = false; Integer maxErrs = null; Behavior level = null; //will report both errors and warnings String profile = null; // match optional arguments for (int i = 2; i < argv.length; i++) { if ("html".equalsIgnoreCase(argv[i])) { outf = RetFormat.HTML; } else if ("xml".equalsIgnoreCase(argv[i])) { outf = RetFormat.XML; } else if ("biopax".equalsIgnoreCase(argv[i])) { outf = RetFormat.OWL; } else if ("auto-fix".equalsIgnoreCase(argv[i])) { fix = true; } else if ("only-errors".equalsIgnoreCase(argv[i])) { level = Behavior.ERROR; } else if ((argv[i]).toLowerCase().startsWith("maxerrors=")) { String num = argv[i].substring(10); maxErrs = Integer.valueOf(num); } else if ("notstrict".equalsIgnoreCase(argv[i])) { profile = "notstrict"; } } // collect files Collection<File> files = new HashSet<File>(); if (fileOrDir.isDirectory()) { // validate all the OWL files in the folder FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return (name.endsWith(".owl")); } }; for (String s : fileOrDir.list(filter)) { files.add(new File(fileOrDir.getCanonicalPath() + File.separator + s)); } } else { files.add(fileOrDir); } // upload and validate using the default URL: http://www.biopax.org/biopax-validator/check.html if (!files.isEmpty()) { BiopaxValidatorClient val = new BiopaxValidatorClient(); val.validate(fix, profile, outf, level, maxErrs, null, files.toArray(new File[] {}), new FileOutputStream(output)); } }
From source file:com.jbrisbin.groovy.mqdsl.RabbitMQDsl.java
public static void main(String[] argv) { // Parse command line arguments CommandLine args = null;//from www .j a v a2s. c om try { Parser p = new BasicParser(); args = p.parse(cliOpts, argv); } catch (ParseException e) { log.error(e.getMessage(), e); } // Check for help if (args.hasOption('?')) { printUsage(); return; } // Runtime properties Properties props = System.getProperties(); // Check for ~/.rabbitmqrc File userSettings = new File(System.getProperty("user.home"), ".rabbitmqrc"); if (userSettings.exists()) { try { props.load(new FileInputStream(userSettings)); } catch (IOException e) { log.error(e.getMessage(), e); } } // Load Groovy builder file StringBuffer script = new StringBuffer(); BufferedInputStream in = null; String filename = "<STDIN>"; if (args.hasOption("f")) { filename = args.getOptionValue("f"); try { in = new BufferedInputStream(new FileInputStream(filename)); } catch (FileNotFoundException e) { log.error(e.getMessage(), e); } } else { in = new BufferedInputStream(System.in); } // Read script if (null != in) { byte[] buff = new byte[4096]; try { for (int read = in.read(buff); read > -1;) { script.append(new String(buff, 0, read)); read = in.read(buff); } } catch (IOException e) { log.error(e.getMessage(), e); } } else { System.err.println("No script file to evaluate..."); } PrintStream stdout = System.out; PrintStream out = null; if (args.hasOption("o")) { try { out = new PrintStream(new FileOutputStream(args.getOptionValue("o")), true); System.setOut(out); } catch (FileNotFoundException e) { log.error(e.getMessage(), e); } } String[] includes = (System.getenv().containsKey("MQDSL_INCLUDE") ? System.getenv("MQDSL_INCLUDE").split(String.valueOf(File.pathSeparatorChar)) : new String[] { System.getenv("HOME") + File.separator + ".mqdsl.d" }); try { // Setup RabbitMQ String username = (args.hasOption("U") ? args.getOptionValue("U") : props.getProperty("mq.user", "guest")); String password = (args.hasOption("P") ? args.getOptionValue("P") : props.getProperty("mq.password", "guest")); String virtualHost = (args.hasOption("v") ? args.getOptionValue("v") : props.getProperty("mq.virtualhost", "/")); String host = (args.hasOption("h") ? args.getOptionValue("h") : props.getProperty("mq.host", "localhost")); int port = Integer.parseInt( args.hasOption("p") ? args.getOptionValue("p") : props.getProperty("mq.port", "5672")); CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host); connectionFactory.setPort(port); connectionFactory.setUsername(username); connectionFactory.setPassword(password); if (null != virtualHost) { connectionFactory.setVirtualHost(virtualHost); } // The DSL builder RabbitMQBuilder builder = new RabbitMQBuilder(); builder.setConnectionFactory(connectionFactory); // Our execution environment Binding binding = new Binding(args.getArgs()); binding.setVariable("mq", builder); String fileBaseName = filename.replaceAll("\\.groovy$", ""); binding.setVariable("log", LoggerFactory.getLogger(fileBaseName.substring(fileBaseName.lastIndexOf("/") + 1))); if (null != out) { binding.setVariable("out", out); } // Include helper files GroovyShell shell = new GroovyShell(binding); for (String inc : includes) { File f = new File(inc); if (f.isDirectory()) { File[] files = f.listFiles(new FilenameFilter() { @Override public boolean accept(File file, String s) { return s.endsWith(".groovy"); } }); for (File incFile : files) { run(incFile, shell, binding); } } else { run(f, shell, binding); } } run(script.toString(), shell, binding); while (builder.isActive()) { try { Thread.sleep(500); } catch (InterruptedException e) { log.error(e.getMessage(), e); } } if (null != out) { out.close(); System.setOut(stdout); } } finally { System.exit(0); } }
From source file:kilim.tools.Weaver.java
/** * <pre>//from w w w. j a va 2s.co m * Usage: java kilim.tools.Weaver -d <output directory> {source classe, jar, directory ...} * </pre> * * If directory names or jar files are given, all classes in that container are processed. It is * perfectly fine to specify the same directory for source and output like this: * <pre> * java kilim.tools.Weaver -d ./classes ./classes * </pre> * Ensure that all classes to be woven are in the classpath. The output directory does not have to be * in the classpath during weaving. * * @see #weave(List) for run-time weaving. */ public static void main(String[] args) throws IOException { // System.out.println(System.getProperty("java.class.path")); Detector detector = Detector.DEFAULT; String currentName = null; for (String name : parseArgs(args)) { try { if (name.endsWith(".class")) { if (exclude(name)) continue; currentName = name; weaveFile(name, new BufferedInputStream(new FileInputStream(name)), detector); } else if (name.endsWith(".jar")) { for (FileLister.Entry fe : new FileLister(name)) { currentName = fe.getFileName(); if (currentName.endsWith(".class")) { currentName = currentName.substring(0, currentName.length() - 6).replace('/', '.'); if (exclude(currentName)) continue; weaveFile(currentName, fe.getInputStream(), detector); } } } else if (new File(name).isDirectory()) { for (FileLister.Entry fe : new FileLister(name)) { currentName = fe.getFileName(); if (currentName.endsWith(".class")) { if (exclude(currentName)) continue; weaveFile(currentName, fe.getInputStream(), detector); } } } else { weaveClass(name, detector); } } catch (KilimException ke) { log.error("Error weaving " + currentName + ". " + ke.getMessage()); // ke.printStackTrace(); System.exit(1); } catch (IOException ioe) { log.error("Unable to find/process '" + currentName + "'"); System.exit(1); } catch (Throwable t) { log.error("Error weaving " + currentName); t.printStackTrace(); System.exit(1); } } System.exit(err); }
From source file:marytts.tools.analysis.CopySynthesis.java
/** * @param args//from w ww . j a v a 2s . c om */ public static void main(String[] args) throws Exception { String wavFilename = null; String labFilename = null; String pitchFilename = null; String textFilename = null; String locale = System.getProperty("locale"); if (locale == null) { throw new IllegalArgumentException("No locale given (-Dlocale=...)"); } for (String arg : args) { if (arg.endsWith(".txt")) textFilename = arg; else if (arg.endsWith(".wav")) wavFilename = arg; else if (arg.endsWith(".ptc")) pitchFilename = arg; else if (arg.endsWith(".lab")) labFilename = arg; else throw new IllegalArgumentException("Don't know how to treat argument: " + arg); } // The intonation contour double[] contour = null; double frameShiftTime = -1; if (pitchFilename == null) { // need to create pitch contour from wav file if (wavFilename == null) { throw new IllegalArgumentException("Need either a pitch file or a wav file"); } AudioInputStream ais = AudioSystem.getAudioInputStream(new File(wavFilename)); AudioDoubleDataSource audio = new AudioDoubleDataSource(ais); PitchFileHeader params = new PitchFileHeader(); params.fs = (int) ais.getFormat().getSampleRate(); F0TrackerAutocorrelationHeuristic tracker = new F0TrackerAutocorrelationHeuristic(params); tracker.pitchAnalyze(audio); frameShiftTime = tracker.getSkipSizeInSeconds(); contour = tracker.getF0Contour(); } else { // have a pitch file -- ignore any wav file PitchReaderWriter f0rw = new PitchReaderWriter(pitchFilename); if (f0rw.contour == null) { throw new NullPointerException("Cannot read f0 contour from " + pitchFilename); } contour = f0rw.contour; frameShiftTime = f0rw.header.skipSizeInSeconds; } assert contour != null; assert frameShiftTime > 0; // The ALLOPHONES data and labels if (labFilename == null) { throw new IllegalArgumentException("No label file given"); } if (textFilename == null) { throw new IllegalArgumentException("No text file given"); } MaryTranscriptionAligner aligner = new MaryTranscriptionAligner(); aligner.SetEnsureInitialBoundary(false); String labels = MaryTranscriptionAligner.readLabelFile(aligner.getEntrySeparator(), aligner.getEnsureInitialBoundary(), labFilename); MaryHttpClient mary = new MaryHttpClient(); String text = FileUtils.readFileToString(new File(textFilename), "ASCII"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); mary.process(text, "TEXT", "ALLOPHONES", locale, null, null, baos); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); docFactory.setNamespaceAware(true); DocumentBuilder builder = docFactory.newDocumentBuilder(); Document doc = builder.parse(bais); aligner.alignXmlTranscriptions(doc, labels); assert doc != null; // durations double[] endTimes = new LabelfileDoubleDataSource(new File(labFilename)).getAllData(); assert endTimes.length == labels.split(Pattern.quote(aligner.getEntrySeparator())).length; // Now add durations and f0 targets to document double prevEnd = 0; NodeIterator ni = MaryDomUtils.createNodeIterator(doc, MaryXML.PHONE, MaryXML.BOUNDARY); for (int i = 0; i < endTimes.length; i++) { Element e = (Element) ni.nextNode(); if (e == null) throw new IllegalStateException("More durations than elements -- this should not happen!"); double durInSeconds = endTimes[i] - prevEnd; int durInMillis = (int) (1000 * durInSeconds); if (e.getTagName().equals(MaryXML.PHONE)) { e.setAttribute("d", String.valueOf(durInMillis)); e.setAttribute("end", new Formatter(Locale.US).format("%.3f", endTimes[i]).toString()); // f0 targets at beginning, mid, and end of phone StringBuilder f0String = new StringBuilder(); double startF0 = getF0(contour, frameShiftTime, prevEnd); if (startF0 != 0 && !Double.isNaN(startF0)) { f0String.append("(0,").append((int) startF0).append(")"); } double midF0 = getF0(contour, frameShiftTime, prevEnd + 0.5 * durInSeconds); if (midF0 != 0 && !Double.isNaN(midF0)) { f0String.append("(50,").append((int) midF0).append(")"); } double endF0 = getF0(contour, frameShiftTime, endTimes[i]); if (endF0 != 0 && !Double.isNaN(endF0)) { f0String.append("(100,").append((int) endF0).append(")"); } if (f0String.length() > 0) { e.setAttribute("f0", f0String.toString()); } } else { // boundary e.setAttribute("duration", String.valueOf(durInMillis)); } prevEnd = endTimes[i]; } if (ni.nextNode() != null) { throw new IllegalStateException("More elements than durations -- this should not happen!"); } // TODO: add pitch values String acoustparams = DomUtils.document2String(doc); System.out.println("ACOUSTPARAMS:"); System.out.println(acoustparams); }
From source file:com.linkedin.restli.tools.snapshot.check.RestLiSnapshotCompatibilityChecker.java
public static void main(String[] args) { final Options options = new Options(); options.addOption("h", "help", false, "Print help"); options.addOption(OptionBuilder.withArgName("compatibility_level").withLongOpt("compat").hasArg() .withDescription("Compatibility level " + listCompatLevelOptions()).create('c')); options.addOption(OptionBuilder.withLongOpt("report").withDescription( "Prints a report at the end of the execution that can be parsed for reporting to other tools") .create("report")); final String cmdLineSyntax = RestLiSnapshotCompatibilityChecker.class.getCanonicalName() + " [pairs of <prevRestspecPath currRestspecPath>]"; final CommandLineParser parser = new PosixParser(); final CommandLine cmd; try {//from w w w . ja v a2 s . c o m cmd = parser.parse(options, args); } catch (ParseException e) { new HelpFormatter().printHelp(cmdLineSyntax, options, true); System.exit(255); return; // to suppress IDE warning } final String[] targets = cmd.getArgs(); if (cmd.hasOption('h') || targets.length < 2 || targets.length % 2 != 0) { new HelpFormatter().printHelp(cmdLineSyntax, options, true); System.exit(255); } final String compatValue; if (cmd.hasOption('c')) { compatValue = cmd.getOptionValue('c'); } else { compatValue = CompatibilityLevel.DEFAULT.name(); } final CompatibilityLevel compat; try { compat = CompatibilityLevel.valueOf(compatValue.toUpperCase()); } catch (IllegalArgumentException e) { new HelpFormatter().printHelp(cmdLineSyntax, options, true); System.exit(255); return; } final String resolverPath = System.getProperty(AbstractGenerator.GENERATOR_RESOLVER_PATH); final RestLiSnapshotCompatibilityChecker checker = new RestLiSnapshotCompatibilityChecker(); checker.setResolverPath(resolverPath); for (int i = 1; i < targets.length; i += 2) { String prevTarget = targets[i - 1]; String currTarget = targets[i]; checker.checkCompatibility(prevTarget, currTarget, compat, prevTarget.endsWith(".restspec.json")); } String summary = checker.getInfoMap().createSummary(); if (compat != CompatibilityLevel.OFF && summary.length() > 0) { System.out.println(summary); } if (cmd.hasOption("report")) { System.out.println(new CompatibilityReport(checker.getInfoMap(), compat).createReport()); System.exit(0); } System.exit(checker.getInfoMap().isCompatible(compat) ? 0 : 1); }