List of usage examples for java.lang String startsWith
public boolean startsWith(String prefix)
From source file:ListAlgorithms.java
public static void main(String[] args) { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); 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>(); Set<String> keyFactory = new HashSet<String>(); Set<String> keyPairGenerator = new HashSet<String>(); Set<String> keyGenerator = 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()); }/*w w w. java 2s .co m*/ 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())); } else if (entry.startsWith("KeyPairGenerator.")) { keyPairGenerator.add(entry.substring("KeyPairGenerator.".length())); } else if (entry.startsWith("KeyFactory.")) { keyFactory.add(entry.substring("KeyFactory.".length())); } else if (entry.startsWith("KeyGenerator.")) { keyGenerator.add(entry.substring("KeyGenerator.".length())); } else { System.out.println(entry); } } } printSet("KeyGenerator", keyGenerator); printSet("KeyFactory", keyFactory); printSet("KeyPairGenerator", keyPairGenerator); printSet("Ciphers", ciphers); printSet("KeyAgreeents", keyAgreements); printSet("Macs", macs); printSet("MessageDigests", messageDigests); printSet("Signatures", signatures); }
From source file:bmsi.util.UnaryPredicate.java
public static void main(String[] argv) throws IOException { String filea = argv[argv.length - 2]; String fileb = argv[argv.length - 1]; String[] a = slurp(filea);//from w ww .ja v a2 s . c o m String[] b = slurp(fileb); Diff d = new Diff(a, b); char style = 'n'; d.heuristic = false; for (int i = 0; i < argv.length - 2; ++i) { String f = argv[i]; if (f.startsWith("-")) { for (int j = 1; j < f.length(); ++j) { switch (f.charAt(j)) { case 'H': // heuristic on d.heuristic = true; break; case 'e': // Ed style style = 'e'; break; case 'c': // Context diff style = 'c'; break; case 'u': style = 'u'; break; } } } } boolean reverse = style == 'e'; Diff.Change script = d.diff_2(reverse); if (script == null) System.err.println("No differences"); else { Base p; switch (style) { case 'e': p = new EdPrint(a, b); break; case 'c': p = new ContextPrint(a, b); break; case 'u': p = new UnifiedPrint(a, b); break; default: p = new NormalPrint(a, b); } p.print_header(filea, fileb); p.print_script(script); } }
From source file:com.turbospaces.api.EmbeddedJSpaceRunner.java
/** * launcher method/* ww w . j a v a2s.c o m*/ * * @param args * [1 argument = application context path] * @throws Exception * re-throw execution errors if any */ public static void main(final String... args) throws Exception { JVMUtil.gcOnExit(); String appContextPath = args[0]; if (System.getProperty(Global.IPv4) == null && System.getProperty(Global.IPv6) == null) System.setProperty(Global.IPv4, Boolean.TRUE.toString()); System.setProperty(Global.CUSTOM_LOG_FACTORY, JGroupsCustomLoggerFactory.class.getName()); LOGGER.info("Welcome to turbospaces:version = {}, build date = {}", SpaceUtility.projectVersion(), SpaceUtility.projecBuildTimestamp()); LOGGER.info("{}: launching configuration {}", EmbeddedJSpaceRunner.class.getSimpleName(), appContextPath); AbstractXmlApplicationContext c = appContextPath.startsWith("file") ? new FileSystemXmlApplicationContext(appContextPath) : new ClassPathXmlApplicationContext(appContextPath); c.getBeansOfType(JSpace.class); c.registerShutdownHook(); Collection<SpaceConfiguration> configurations = c.getBeansOfType(SpaceConfiguration.class).values(); for (SpaceConfiguration spaceConfiguration : configurations) spaceConfiguration.joinNetwork(); LOGGER.info("all jspaces joined network, notifying waiting threads..."); synchronized (joinNetworkMonitor) { joinNetworkMonitor.notifyAll(); } while (!Thread.currentThread().isInterrupted()) synchronized (c) { try { c.wait(TimeUnit.SECONDS.toMillis(1)); } catch (InterruptedException e) { LOGGER.info("got interruption signal, terminating jspaces... stack_trace = {}", Throwables.getStackTraceAsString(e)); Thread.currentThread().interrupt(); Util.printThreads(); } } c.destroy(); }
From source file:jetbrains.exodus.env.Reflect.java
public static void main(@NotNull final String[] args) throws Exception { if (args.length == 0) { printUsage();/* w ww . j a va2s .c o m*/ return; } String envPath = null; String envPath2 = null; boolean hasOptions = false; boolean gatherLogStats = false; boolean validateRoots = false; boolean traverse = false; boolean copy = false; boolean traverseAll = false; boolean utilizationInfo = false; final Set<String> files2Clean = new LinkedHashSet<>(); for (final String arg : args) { if (arg.startsWith("-")) { hasOptions = true; if ("-ls".equalsIgnoreCase(arg)) { gatherLogStats = true; } else if ("-r".equalsIgnoreCase(arg)) { validateRoots = true; } else if ("-t".equalsIgnoreCase(arg)) { traverse = true; } else if ("-c".equalsIgnoreCase(arg)) { copy = true; } else if ("-ta".equalsIgnoreCase(arg)) { traverseAll = true; } else if ("-u".equalsIgnoreCase(arg)) { utilizationInfo = true; } else if (arg.toLowerCase().startsWith("-cl")) { files2Clean.add(arg.substring(2)); } else { printUsage(); return; } } else { if (envPath == null) { envPath = arg; } else { envPath2 = arg; break; } } } if (envPath == null || (copy && envPath2 == null)) { printUsage(); return; } System.out.println("Started investigation of " + envPath); final Reflect reflect = new Reflect(new File(envPath)); if (files2Clean.size() > 0) { for (final String file : files2Clean) { reflect.cleanFile(file); } } if (!hasOptions) { reflect.gatherLogStats(); reflect.traverse(); } else { List<DatabaseRoot> roots = null; if (validateRoots || traverseAll) { roots = reflect.roots(); } if (gatherLogStats) { reflect.gatherLogStats(); } if (traverse) { reflect.traverse(); } if (copy) { reflect.copy(new File(envPath2)); } if (utilizationInfo) { reflect.spaceInfoFromUtilization(); } if (traverseAll) { reflect.traverseAll(roots); } } }
From source file:hu.bme.mit.sette.run.Run.java
public static void main(String[] args) { LOG.debug("main() called"); // parse properties Properties prop = new Properties(); InputStream is = null;//from w w w. ja v a2 s . c o m try { is = new FileInputStream(SETTE_PROPERTIES); prop.load(is); } catch (IOException e) { System.err.println("Parsing " + SETTE_PROPERTIES + " has failed"); e.printStackTrace(); System.exit(1); } finally { IOUtils.closeQuietly(is); } String[] basedirs = StringUtils.split(prop.getProperty("basedir"), '|'); String snippetDir = prop.getProperty("snippet-dir"); String snippetProject = prop.getProperty("snippet-project"); String catgPath = prop.getProperty("catg"); String catgVersionFile = prop.getProperty("catg-version-file"); String jPETPath = prop.getProperty("jpet"); String jPETDefaultBuildXml = prop.getProperty("jpet-default-build.xml"); String jPETVersionFile = prop.getProperty("jpet-version-file"); String spfPath = prop.getProperty("spf"); String spfDefaultBuildXml = prop.getProperty("spf-default-build.xml"); String spfVersionFile = prop.getProperty("spf-version-file"); String outputDir = prop.getProperty("output-dir"); Validate.notEmpty(basedirs, "At least one basedir must be specified in " + SETTE_PROPERTIES); Validate.notBlank(snippetDir, "The property snippet-dir must be set in " + SETTE_PROPERTIES); Validate.notBlank(snippetProject, "The property snippet-project must be set in " + SETTE_PROPERTIES); Validate.notBlank(catgPath, "The property catg must be set in " + SETTE_PROPERTIES); Validate.notBlank(jPETPath, "The property jpet must be set in " + SETTE_PROPERTIES); Validate.notBlank(spfPath, "The property spf must be set in " + SETTE_PROPERTIES); Validate.notBlank(outputDir, "The property output-dir must be set in " + SETTE_PROPERTIES); String basedir = null; for (String bd : basedirs) { bd = StringUtils.trimToEmpty(bd); if (bd.startsWith("~")) { // Linux home bd = System.getProperty("user.home") + bd.substring(1); } FileValidator v = new FileValidator(new File(bd)); v.type(FileType.DIRECTORY); if (v.isValid()) { basedir = bd; break; } } if (basedir == null) { System.err.println("basedir = " + Arrays.toString(basedirs)); System.err.println("ERROR: No valid basedir was found, please check " + SETTE_PROPERTIES); System.exit(2); } BASEDIR = new File(basedir); SNIPPET_DIR = new File(basedir, snippetDir); SNIPPET_PROJECT = snippetProject; OUTPUT_DIR = new File(basedir, outputDir); try { String catgVersion = readToolVersion(new File(BASEDIR, catgVersionFile)); if (catgVersion != null) { new CatgTool(new File(BASEDIR, catgPath), catgVersion); } String jPetVersion = readToolVersion(new File(BASEDIR, jPETVersionFile)); if (jPetVersion != null) { new JPetTool(new File(BASEDIR, jPETPath), new File(BASEDIR, jPETDefaultBuildXml), jPetVersion); } String spfVersion = readToolVersion(new File(BASEDIR, spfVersionFile)); if (spfVersion != null) { new SpfTool(new File(BASEDIR, spfPath), new File(BASEDIR, spfDefaultBuildXml), spfVersion); } // TODO stuff stuff(args); } catch (Exception e) { System.err.println(ExceptionUtils.getStackTrace(e)); ValidatorException vex = (ValidatorException) e; for (ValidationException v : vex.getValidator().getAllExceptions()) { v.printStackTrace(); } // System.exit(0); e.printStackTrace(); System.err.println("=========="); e.printStackTrace(); if (e instanceof ValidatorException) { System.err.println("Details:"); System.err.println(((ValidatorException) e).getFullMessage()); } else if (e.getCause() instanceof ValidatorException) { System.err.println("Details:"); System.err.println(((ValidatorException) e.getCause()).getFullMessage()); } } }
From source file:cht.Parser.java
public static void main(String[] args) throws IOException { // TODO get from google drive boolean isUnicode = false; boolean isRemoveInputFileOnComplete = false; int rowNum;//from w w w. j a v a2 s . c om int colNum; Gson gson = new GsonBuilder().setPrettyPrinting().create(); Properties prop = new Properties(); try { prop.load(new FileInputStream("config.txt")); } catch (IOException ex) { ex.printStackTrace(); } String inputFilePath = prop.getProperty("inputFile"); String outputDirectory = prop.getProperty("outputDirectory"); System.out.println(outputDirectory); // optional String unicode = prop.getProperty("unicode"); String removeInputFileOnComplete = prop.getProperty("removeInputFileOnComplete"); inputFilePath = inputFilePath.trim(); outputDirectory = outputDirectory.trim(); if (unicode != null) { isUnicode = Boolean.parseBoolean(unicode.trim()); } if (removeInputFileOnComplete != null) { isRemoveInputFileOnComplete = Boolean.parseBoolean(removeInputFileOnComplete.trim()); } Writer out = null; FileInputStream in = null; final String newLine = System.getProperty("line.separator").toString(); final String separator = File.separator; try { in = new FileInputStream(inputFilePath); Workbook workbook = new XSSFWorkbook(in); Sheet sheet = workbook.getSheetAt(0); rowNum = sheet.getLastRowNum() + 1; colNum = sheet.getRow(0).getPhysicalNumberOfCells(); for (int j = 1; j < colNum; ++j) { String outputFilename = sheet.getRow(0).getCell(j).getStringCellValue(); // guess directory int slash = outputFilename.indexOf('/'); if (slash != -1) { // has directory outputFilename = outputFilename.substring(0, slash) + separator + outputFilename.substring(slash + 1); } String outputPath = FilenameUtils.concat(outputDirectory, outputFilename); System.out.println("--Writing " + outputPath); out = new OutputStreamWriter(new FileOutputStream(outputPath), "UTF-8"); TreeMap<String, Object> map = new TreeMap<String, Object>(); for (int i = 1; i < rowNum; i++) { try { String key = sheet.getRow(i).getCell(0).getStringCellValue(); //String value = ""; Cell tmp = sheet.getRow(i).getCell(j); if (tmp != null) { // not empty string! value = sheet.getRow(i).getCell(j).getStringCellValue(); } if (!key.equals("") && !key.startsWith("#") && !key.startsWith(".")) { value = isUnicode ? StringEscapeUtils.escapeJava(value) : value; int firstdot = key.indexOf("."); String keyName, keyAttribute; if (firstdot > 0) {// a.b.c.d keyName = key.substring(0, firstdot); // a keyAttribute = key.substring(firstdot + 1); // b.c.d TreeMap oldhash = null; Object old = null; if (map.get(keyName) != null) { old = map.get(keyName); if (old instanceof TreeMap == false) { System.out.println("different type of key:" + key); continue; } oldhash = (TreeMap) old; } else { oldhash = new TreeMap(); } int firstdot2 = keyAttribute.indexOf("."); String rootName, childName; if (firstdot2 > 0) {// c, d.f --> d, f rootName = keyAttribute.substring(0, firstdot2); childName = keyAttribute.substring(firstdot2 + 1); } else {// c, d -> d, null rootName = keyAttribute; childName = null; } TreeMap<String, Object> object = myPut(oldhash, rootName, childName); map.put(keyName, object); } else {// c, d -> d, null keyName = key; keyAttribute = null; // simple string mode map.put(key, value); } } } catch (Exception e) { // just ingore empty rows } } String json = gson.toJson(map); // output json out.write(json + newLine); out.close(); } in.close(); System.out.println("\n---Complete!---"); System.out.println("Read input file from " + inputFilePath); System.out.println(colNum - 1 + " output files ate generated at " + outputDirectory); System.out.println(rowNum + " records are generated for each output file."); System.out.println("output file is ecoded as unicode? " + (isUnicode ? "yes" : "no")); if (isRemoveInputFileOnComplete) { File input = new File(inputFilePath); input.deleteOnExit(); System.out.println("Deleted " + inputFilePath); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { in.close(); } } }
From source file:org.wso2.carbon.sample.http.Http.java
public static void main(String args[]) { log.info("Starting WSO2 Http Client"); HttpUtil.setTrustStoreParams();/* w w w . ja va 2s .c o m*/ String url = args[0]; String username = args[1]; String password = args[2]; String sampleNumber = args[3]; String filePath = args[4]; HttpClient httpClient = new SystemDefaultHttpClient(); try { HttpPost method = new HttpPost(url); filePath = HttpUtil.getMessageFilePath(sampleNumber, filePath, url); readMsg(filePath); for (String message : messagesList) { StringEntity entity = new StringEntity(message); log.info("Sending message:"); log.info(message + "\n"); method.setEntity(entity); if (url.startsWith("https")) { processAuthentication(method, username, password); } httpClient.execute(method).getEntity().getContent().close(); } Thread.sleep(500); // Waiting time for the message to be sent } catch (Throwable t) { log.error("Error when sending the messages", t); } }
From source file:Counter.java
/** Main program entry point. */ public static void main(String argv[]) { // is there anything to do? if (argv.length == 0) { printUsage();/*from w ww . ja v a2 s.c o m*/ System.exit(1); } // variables Counter counter = new Counter(); PrintWriter out = new PrintWriter(System.out); ParserWrapper parser = null; int repetition = DEFAULT_REPETITION; boolean namespaces = DEFAULT_NAMESPACES; boolean validation = DEFAULT_VALIDATION; boolean schemaValidation = DEFAULT_SCHEMA_VALIDATION; boolean schemaFullChecking = DEFAULT_SCHEMA_FULL_CHECKING; boolean honourAllSchemaLocations = DEFAULT_HONOUR_ALL_SCHEMA_LOCATIONS; boolean validateAnnotations = DEFAULT_VALIDATE_ANNOTATIONS; boolean dynamicValidation = DEFAULT_DYNAMIC_VALIDATION; boolean xincludeProcessing = DEFAULT_XINCLUDE; boolean xincludeFixupBaseURIs = DEFAULT_XINCLUDE_FIXUP_BASE_URIS; boolean xincludeFixupLanguage = DEFAULT_XINCLUDE_FIXUP_LANGUAGE; // process arguments for (int i = 0; i < argv.length; i++) { String arg = argv[i]; if (arg.startsWith("-")) { String option = arg.substring(1); if (option.equals("p")) { // get parser name if (++i == argv.length) { System.err.println("error: Missing argument to -p option."); } String parserName = argv[i]; // create parser try { parser = (ParserWrapper) Class.forName(parserName).newInstance(); } catch (Exception e) { parser = null; System.err.println("error: Unable to instantiate parser (" + parserName + ")"); } continue; } if (option.equals("x")) { if (++i == argv.length) { System.err.println("error: Missing argument to -x option."); continue; } String number = argv[i]; try { int value = Integer.parseInt(number); if (value < 1) { System.err.println("error: Repetition must be at least 1."); continue; } repetition = value; } catch (NumberFormatException e) { System.err.println("error: invalid number (" + number + ")."); } continue; } if (option.equalsIgnoreCase("n")) { namespaces = option.equals("n"); continue; } if (option.equalsIgnoreCase("v")) { validation = option.equals("v"); continue; } if (option.equalsIgnoreCase("s")) { schemaValidation = option.equals("s"); continue; } if (option.equalsIgnoreCase("f")) { schemaFullChecking = option.equals("f"); continue; } if (option.equalsIgnoreCase("hs")) { honourAllSchemaLocations = option.equals("hs"); continue; } if (option.equalsIgnoreCase("va")) { validateAnnotations = option.equals("va"); continue; } if (option.equalsIgnoreCase("dv")) { dynamicValidation = option.equals("dv"); continue; } if (option.equalsIgnoreCase("xi")) { xincludeProcessing = option.equals("xi"); continue; } if (option.equalsIgnoreCase("xb")) { xincludeFixupBaseURIs = option.equals("xb"); continue; } if (option.equalsIgnoreCase("xl")) { xincludeFixupLanguage = option.equals("xl"); continue; } if (option.equals("h")) { printUsage(); continue; } } // use default parser? if (parser == null) { // create parser try { parser = (ParserWrapper) Class.forName(DEFAULT_PARSER_NAME).newInstance(); } catch (Exception e) { System.err.println("error: Unable to instantiate parser (" + DEFAULT_PARSER_NAME + ")"); continue; } } // set parser features try { parser.setFeature(NAMESPACES_FEATURE_ID, namespaces); } catch (SAXException e) { System.err.println("warning: Parser does not support feature (" + NAMESPACES_FEATURE_ID + ")"); } try { parser.setFeature(VALIDATION_FEATURE_ID, validation); } catch (SAXException e) { System.err.println("warning: Parser does not support feature (" + VALIDATION_FEATURE_ID + ")"); } try { parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, schemaValidation); } catch (SAXException e) { System.err .println("warning: Parser does not support feature (" + SCHEMA_VALIDATION_FEATURE_ID + ")"); } try { parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, schemaFullChecking); } catch (SAXException e) { System.err.println( "warning: Parser does not support feature (" + SCHEMA_FULL_CHECKING_FEATURE_ID + ")"); } try { parser.setFeature(HONOUR_ALL_SCHEMA_LOCATIONS_ID, honourAllSchemaLocations); } catch (SAXException e) { System.err.println( "warning: Parser does not support feature (" + HONOUR_ALL_SCHEMA_LOCATIONS_ID + ")"); } try { parser.setFeature(VALIDATE_ANNOTATIONS_ID, validateAnnotations); } catch (SAXException e) { System.err.println("warning: Parser does not support feature (" + VALIDATE_ANNOTATIONS_ID + ")"); } try { parser.setFeature(DYNAMIC_VALIDATION_FEATURE_ID, dynamicValidation); } catch (SAXException e) { System.err.println( "warning: Parser does not support feature (" + DYNAMIC_VALIDATION_FEATURE_ID + ")"); } try { parser.setFeature(XINCLUDE_FEATURE_ID, xincludeProcessing); } catch (SAXException e) { System.err.println("warning: Parser does not support feature (" + XINCLUDE_FEATURE_ID + ")"); } try { parser.setFeature(XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID, xincludeFixupBaseURIs); } catch (SAXException e) { System.err.println( "warning: Parser does not support feature (" + XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID + ")"); } try { parser.setFeature(XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID, xincludeFixupLanguage); } catch (SAXException e) { System.err.println( "warning: Parser does not support feature (" + XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID + ")"); } // parse file try { long beforeParse = System.currentTimeMillis(); Document document = null; for (int j = 0; j < repetition; j++) { document = parser.parse(arg); } long afterParse = System.currentTimeMillis(); long parse = afterParse - beforeParse; ParserWrapper.DocumentInfo documentInfo = parser.getDocumentInfo(); counter.setDocumentInfo(documentInfo); long beforeTraverse1 = System.currentTimeMillis(); counter.count(document); long afterTraverse1 = System.currentTimeMillis(); long traverse1 = afterTraverse1 - beforeTraverse1; long beforeTraverse2 = System.currentTimeMillis(); counter.count(document); long afterTraverse2 = System.currentTimeMillis(); long traverse2 = afterTraverse2 - beforeTraverse2; counter.printResults(out, arg, parse, traverse1, traverse2, repetition); } catch (SAXParseException e) { // ignore } catch (Exception e) { System.err.println("error: Parse error occurred - " + e.getMessage()); Exception se = e; if (e instanceof SAXException) { se = ((SAXException) e).getException(); } if (se != null) se.printStackTrace(System.err); else e.printStackTrace(System.err); } } }
From source file:com.netthreads.mavenize.Mavenize.java
/** * Main method./*from www . java2 s . c o m*/ * * @param args */ public static void main(String[] args) { if (args.length > 1) { String sourcePath = ""; String targetPath = ""; String projectTypeName = ProjectType.Types.DEFAULT.toString(); String version = PomGenerator.DEFAULT_VERSION; String packaging = PomGenerator.PACKAGE_TYPES[0]; boolean isInput = false; boolean isOutput = false; for (String arg : args) { try { if (arg.startsWith(ARG_INPUT)) { sourcePath = arg.substring(ARG_INPUT.length()); isInput = true; } else if (arg.startsWith(ARG_OUTPUT)) { targetPath = arg.substring(ARG_OUTPUT.length()); isOutput = true; } else if (arg.startsWith(ARG_TYPE)) { projectTypeName = arg.substring(ARG_TYPE.length()); } else if (arg.startsWith(ARG_VERSION)) { version = arg.substring(ARG_VERSION.length()); } else if (arg.startsWith(ARG_PACKAGING)) { packaging = arg.substring(ARG_PACKAGING.length()); } } catch (Exception e) { logger.error("Can't process argument, " + arg + ", " + e.getMessage()); } } // Project type. ProjectType projectType = ProjectTypeFactory.instance().getProjectType(projectTypeName); // Execute conversion. try { if (isInput && isOutput) { if (!sourcePath.equals(targetPath)) { Mavenize mvnGather = new Mavenize(null); mvnGather.process(sourcePath, targetPath, projectType, version, packaging); } else { throw new MavenizeException("Input and output directories cannot be the same."); } } else { throw new MavenizeException("You must specify input and output directories"); } } catch (MavenizeException e) { logger.error("Application error, " + e); } catch (IOException ioe) { logger.error("Application error, " + ioe); } } else { System.out.println(APP_MESSAGE + ARGS_MESSAGE); } }
From source file:DIA_Umpire_Quant.DIA_Umpire_LCMSIDGen.java
/** * @param args the command line arguments *//*from w w w .ja va2 s . c o m*/ public static void main(String[] args) throws FileNotFoundException, IOException, Exception { System.out.println( "================================================================================================="); System.out.println("DIA-Umpire LCMSID geneartor (version: " + UmpireInfo.GetInstance().Version + ")"); if (args.length != 1) { System.out.println( "command format error, the correct format should be: java -jar -Xmx10G DIA_Umpire_LCMSIDGen.jar diaumpire_module.params"); return; } try { ConsoleLogger.SetConsoleLogger(Level.INFO); ConsoleLogger.SetFileLogger(Level.DEBUG, FilenameUtils.getFullPath(args[0]) + "diaumpire_lcmsidgen.log"); } catch (Exception e) { } Logger.getRootLogger().info("Version: " + UmpireInfo.GetInstance().Version); Logger.getRootLogger().info("Parameter file:" + args[0]); BufferedReader reader = new BufferedReader(new FileReader(args[0])); String line = ""; String WorkFolder = ""; int NoCPUs = 2; TandemParam tandemPara = new TandemParam(DBSearchParam.SearchInstrumentType.TOF5600); HashMap<String, File> AssignFiles = new HashMap<>(); //<editor-fold defaultstate="collapsed" desc="Reading parameter file"> while ((line = reader.readLine()) != null) { line = line.trim(); Logger.getRootLogger().info(line); if (!"".equals(line) && !line.startsWith("#")) { //System.out.println(line); if (line.equals("==File list begin")) { do { line = reader.readLine(); line = line.trim(); if (line.equals("==File list end")) { continue; } else if (!"".equals(line)) { File newfile = new File(line); if (newfile.exists()) { AssignFiles.put(newfile.getAbsolutePath(), newfile); } else { Logger.getRootLogger().info("File: " + newfile + " does not exist."); } } } while (!line.equals("==File list end")); } if (line.split("=").length < 2) { continue; } String type = line.split("=")[0].trim(); String value = line.split("=")[1].trim(); switch (type) { case "Path": { WorkFolder = value; break; } case "path": { WorkFolder = value; break; } case "Thread": { NoCPUs = Integer.parseInt(value); break; } case "DecoyPrefix": { if (!"".equals(value)) { tandemPara.DecoyPrefix = value; } break; } case "PeptideFDR": { tandemPara.PepFDR = Float.parseFloat(value); break; } } } } //</editor-fold> //Initialize PTM manager using compomics library PTMManager.GetInstance(); //Generate DIA file list ArrayList<DIAPack> FileList = new ArrayList<>(); File folder = new File(WorkFolder); if (!folder.exists()) { Logger.getRootLogger().info("The path : " + WorkFolder + " cannot be found."); System.exit(1); } for (final File fileEntry : folder.listFiles()) { if (fileEntry.isFile() && (fileEntry.getAbsolutePath().toLowerCase().endsWith(".mzxml") | fileEntry.getAbsolutePath().toLowerCase().endsWith(".mzml")) && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q1.mzxml") && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q2.mzxml") && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) { AssignFiles.put(fileEntry.getAbsolutePath(), fileEntry); } if (fileEntry.isDirectory()) { for (final File fileEntry2 : fileEntry.listFiles()) { if (fileEntry2.isFile() && (fileEntry2.getAbsolutePath().toLowerCase().endsWith(".mzxml") | fileEntry2.getAbsolutePath().toLowerCase().endsWith(".mzml")) && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q1.mzxml") && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q2.mzxml") && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) { AssignFiles.put(fileEntry2.getAbsolutePath(), fileEntry2); } } } } Logger.getRootLogger().info("No. of files assigned :" + AssignFiles.size()); for (File fileEntry : AssignFiles.values()) { Logger.getRootLogger().info(fileEntry.getAbsolutePath()); } //process each DIA file to genearate untargeted identifications for (File fileEntry : AssignFiles.values()) { String mzXMLFile = fileEntry.getAbsolutePath(); if (mzXMLFile.toLowerCase().endsWith(".mzxml") | mzXMLFile.toLowerCase().endsWith(".mzml")) { long time = System.currentTimeMillis(); DIAPack DiaFile = new DIAPack(mzXMLFile, NoCPUs); FileList.add(DiaFile); Logger.getRootLogger().info( "================================================================================================="); Logger.getRootLogger().info("Processing " + mzXMLFile); if (!DiaFile.LoadDIASetting()) { Logger.getRootLogger().info("Loading DIA setting failed, job is incomplete"); System.exit(1); } if (!DiaFile.LoadParams()) { Logger.getRootLogger().info("Loading parameters failed, job is incomplete"); System.exit(1); } Logger.getRootLogger().info("Loading identification results " + mzXMLFile + "...."); DiaFile.ParsePepXML(tandemPara, null); DiaFile.BuildStructure(); if (!DiaFile.MS1FeatureMap.ReadPeakCluster()) { Logger.getRootLogger().info("Loading peak and structure failed, job is incomplete"); System.exit(1); } DiaFile.MS1FeatureMap.ClearMonoisotopicPeakOfCluster(); //Generate mapping between index of precursor feature and pseudo MS/MS scan index DiaFile.GenerateClusterScanNomapping(); //Doing quantification DiaFile.AssignQuant(); DiaFile.ClearStructure(); DiaFile.IDsummary.ReduceMemoryUsage(); time = System.currentTimeMillis() - time; Logger.getRootLogger().info(mzXMLFile + " processed time:" + String.format("%d hour, %d min, %d sec", TimeUnit.MILLISECONDS.toHours(time), TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)), TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time)))); } Logger.getRootLogger().info("Job done"); Logger.getRootLogger().info( "================================================================================================="); } }