List of usage examples for java.lang System lineSeparator
String lineSeparator
To view the source code for java.lang System lineSeparator.
Click Source Link
From source file:Main.java
public static void main(String[] args) throws Exception { System.out.println(System.lineSeparator() + "This is from java2s.com"); }
From source file:Main.java
public static void main(String... args) throws IOException { URL url = new URL("http://java2s.com"); InputStream is = url.openStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); StringBuffer sb = new StringBuffer(); String line;/*www . j a va2 s . c om*/ while ((line = br.readLine()) != null) sb.append(line + System.lineSeparator()); br.close(); System.out.print(sb.toString()); }
From source file:com.hp.mqm.atrf.Main.java
public static void main(String[] args) { long start = System.currentTimeMillis(); setUncaughtExceptionHandler();/*from www . ja v a 2 s . com*/ CliParser cliParser = new CliParser(); cliParser.handleHelpAndVersionOptions(args); configureLog4J(); logger.info(System.lineSeparator() + System.lineSeparator()); logger.info("************************************************************************************"); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.getDefault()); DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.getDefault()); logger.info((String.format("Starting HPE ALM Test Result Collection Tool %s %s", dateFormatter.format(new Date()), timeFormatter.format(new Date())))); logger.info("************************************************************************************"); FetchConfiguration configuration = cliParser.parse(args); ConfigurationUtilities.setConfiguration(configuration); App app = new App(configuration); app.start(); long end = System.currentTimeMillis(); logger.info(String.format("Finished creating tests and test results on ALM Octane in %s seconds", (end - start) / 1000)); logger.info(System.lineSeparator()); }
From source file:nl.knaw.meertens.isocat2ccr.Main.java
public static void main(String[] args) { String registry = "https://openskos.meertens.knaw.nl/ccr"; Charset encoding = Charset.defaultCharset(); String newline = System.lineSeparator(); Boolean saveMap = false;// w w w. ja v a 2s . com File mFile = null; File iFile = null; // check command line OptionParser parser = new OptionParser("me:l:?*"); OptionSet options = parser.parse(args); if (options.has("r")) { registry = (String) options.valueOf("r"); } if (options.has("m")) { saveMap = true; } if (options.has("e")) { encoding = Charset.forName((String) options.valueOf("e")); } if (options.has("l")) { String eol = (String) options.valueOf("l"); newline = ""; for (int i = 0; i < eol.length(); i++) { char c = eol.charAt(i); switch (c) { case 'r': newline += "\r"; break; case 'n': newline += "\n"; break; default: System.err.println("FTL: compose the new line separator by 'r' and 'n' characters!"); showHelp(); System.exit(1); } } } if (options.has("?")) { showHelp(); System.exit(0); } List arg = options.nonOptionArguments(); if (arg.size() != 2) { System.err.println("FTL: expected one map <FILE> and one input <FILE> as arguments!"); showHelp(); System.exit(1); } mFile = new File((String) arg.get(0)); iFile = new File((String) arg.get(1)); List<String> replace = new Vector<String>(); String buffer = ""; try { BufferedReader mIn = new BufferedReader(new InputStreamReader(new FileInputStream(mFile))); String line = null; while ((line = mIn.readLine()) != null) { String[] split = line.trim().split(","); String id = split[0]; String pid = split[1]; String handle = null; if (split.length > 2) handle = split[2]; // No handle yet, do a lookup in the CCR if (handle == null || handle.trim().equals("")) { URL url = new URL(registry + "/api/find-concepts/?q=uri:*C-" + id + "_*"); //System.err.println("INF: URL["+url+"]"); XdmNode resp = SaxonUtils.buildDocument(new StreamSource(url.toString())); SaxonUtils.declareXPathNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); SaxonUtils.declareXPathNamespace("skos", "http://www.w3.org/2004/02/skos/core#"); XdmValue set = SaxonUtils.evaluateXPath(resp, "/rdf:RDF/rdf:Description[rdf:type/@rdf:resource='http://www.w3.org/2004/02/skos/core#Concept']/@rdf:about") .evaluate(); if (set.size() == 0) { System.err.println("WRN: no CCR match found for id[" + id + "] pid[" + pid + "]!"); } else if (set.size() > 1) { System.err.println("ERR: multiple CCR matches found for id[" + id + "] pid[" + pid + "]!"); System.err.println("ERR: will use the first concept[" + set.itemAt(0) + "]"); continue; } else handle = set.itemAt(0).getStringValue(); } if (handle != null) { replace.add(pid); replace.add(handle); System.err.println("DBG: [" + id + "] " + pid + " -> " + handle); } if (saveMap) buffer += "" + id + "," + pid + (handle != null ? "," + handle : "") + System.getProperty("line.separator"); } mIn.close(); if (saveMap) { FileUtils.writeStringToFile(mFile, buffer, encoding); System.err.println("INF: saved mapping file[" + mFile.getAbsolutePath() + "]"); } } catch (Exception e) { System.err.println("FTL: map FILE[" + mFile.getAbsolutePath() + "] couldn't be processed!"); System.err.println("FTL: " + e.getMessage()); System.exit(1); } try { BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(iFile))); String line = null; while ((line = in.readLine()) != null) { if (line.contains("http") && line.contains("isocat")) { for (int i = 0; i < replace.size(); i++) { line = line.replaceAll(Pattern.quote(replace.get(i)), replace.get(++i)); } } System.out.print(line); System.out.print(newline); } } catch (Exception e) { System.err.println("FTL: input FILE[" + iFile.getAbsolutePath() + "] couldn't be read!"); System.err.println("FTL: " + e.getMessage()); System.exit(1); } }
From source file:net.cyllene.hackerrank.downloader.HackerrankDownloader.java
public static void main(String[] args) { // Parse arguments and set up the defaults DownloaderSettings.cmd = parseArguments(args); if (DownloaderSettings.cmd.hasOption("help")) { printHelp();/*from www .jav a2s.co m*/ System.exit(0); } if (DownloaderSettings.cmd.hasOption("verbose")) { DownloaderSettings.beVerbose = true; } /** * Output directory logic: * 1) if directory exists, ask for -f option to overwrite, quit with message * 2) if -f flag is set, check if user has access to a parent directory * 3) if no access, quit with error * 4) if everything is OK, remember the path */ String sDesiredPath = DownloaderSettings.outputDir; if (DownloaderSettings.cmd.hasOption("directory")) { sDesiredPath = DownloaderSettings.cmd.getOptionValue("d", DownloaderSettings.outputDir); } if (DownloaderSettings.beVerbose) { System.out.println("Checking output dir: " + sDesiredPath); } Path desiredPath = Paths.get(sDesiredPath); if (Files.exists(desiredPath) && Files.isDirectory(desiredPath)) { if (!DownloaderSettings.cmd.hasOption("f")) { System.out.println("I wouldn't like to overwrite existing directory: " + sDesiredPath + ", set the --force flag if you are sure. May lead to data loss, be careful."); System.exit(0); } else { System.out.println( "WARNING!" + System.lineSeparator() + "--force flag is set. Overwriting directory: " + sDesiredPath + System.lineSeparator() + "WARNING!"); } } if ((Files.exists(desiredPath) && !Files.isWritable(desiredPath)) || !Files.isWritable(desiredPath.getParent())) { System.err .println("Fatal error: " + sDesiredPath + " cannot be created or modified. Check permissions."); // TODO: use Exceptions instead of system.exit System.exit(1); } DownloaderSettings.outputDir = sDesiredPath; Integer limit = DownloaderSettings.ITEMS_TO_DOWNLOAD; if (DownloaderSettings.cmd.hasOption("limit")) { try { limit = ((Number) DownloaderSettings.cmd.getParsedOptionValue("l")).intValue(); } catch (ParseException e) { System.out.println("Incorrect limit: " + e.getMessage() + System.lineSeparator() + "Using default value: " + limit); } } Integer offset = DownloaderSettings.ITEMS_TO_SKIP; if (DownloaderSettings.cmd.hasOption("offset")) { try { offset = ((Number) DownloaderSettings.cmd.getParsedOptionValue("o")).intValue(); } catch (ParseException e) { System.out.println("Incorrect offset: " + e.getMessage() + " Using default value: " + offset); } } DownloaderCore dc = DownloaderCore.INSTANCE; List<HRChallenge> challenges = new LinkedList<>(); // Download everything first Map<String, List<Integer>> structure = null; try { structure = dc.getStructure(offset, limit); } catch (IOException e) { System.err.println("Fatal Error: could not get data structure."); e.printStackTrace(); System.exit(1); } challengesLoop: for (Map.Entry<String, List<Integer>> entry : structure.entrySet()) { String challengeSlug = entry.getKey(); HRChallenge currentChallenge = null; try { currentChallenge = dc.getChallengeDetails(challengeSlug); } catch (IOException e) { System.err.println("Error: could not get challenge info for: " + challengeSlug); if (DownloaderSettings.beVerbose) { e.printStackTrace(); } continue challengesLoop; } submissionsLoop: for (Integer submissionId : entry.getValue()) { HRSubmission submission = null; try { submission = dc.getSubmissionDetails(submissionId); } catch (IOException e) { System.err.println("Error: could not get submission info for: " + submissionId); if (DownloaderSettings.beVerbose) { e.printStackTrace(); } continue submissionsLoop; } // TODO: probably should move filtering logic elsewhere(getStructure, maybe) if (submission.getStatus().equalsIgnoreCase("Accepted")) { currentChallenge.getSubmissions().add(submission); } } challenges.add(currentChallenge); } // Now dump all data to disk try { for (HRChallenge currentChallenge : challenges) { if (currentChallenge.getSubmissions().isEmpty()) continue; final String sChallengePath = DownloaderSettings.outputDir + "/" + currentChallenge.getSlug(); final String sSolutionPath = sChallengePath + "/accepted_solutions"; final String sDescriptionPath = sChallengePath + "/problem_description"; Files.createDirectories(Paths.get(sDescriptionPath)); Files.createDirectories(Paths.get(sSolutionPath)); // FIXME: this should be done the other way String plainBody = currentChallenge.getDescriptions().get(0).getBody(); String sFname; if (!plainBody.equals("null")) { sFname = sDescriptionPath + "/english.txt"; if (DownloaderSettings.beVerbose) { System.out.println("Writing to: " + sFname); } Files.write(Paths.get(sFname), plainBody.getBytes(StandardCharsets.UTF_8.name())); } String htmlBody = currentChallenge.getDescriptions().get(0).getBodyHTML(); String temporaryHtmlTemplate = "<html></body>" + htmlBody + "</body></html>"; sFname = sDescriptionPath + "/english.html"; if (DownloaderSettings.beVerbose) { System.out.println("Writing to: " + sFname); } Files.write(Paths.get(sFname), temporaryHtmlTemplate.getBytes(StandardCharsets.UTF_8.name())); for (HRSubmission submission : currentChallenge.getSubmissions()) { sFname = String.format("%s/%d.%s", sSolutionPath, submission.getId(), submission.getLanguage()); if (DownloaderSettings.beVerbose) { System.out.println("Writing to: " + sFname); } Files.write(Paths.get(sFname), submission.getSourceCode().getBytes(StandardCharsets.UTF_8.name())); } } } catch (IOException e) { System.err.println("Fatal Error: couldn't dump data to disk."); System.exit(1); } }
From source file:com.datastax.sparql.ConsoleCompiler.java
public static void main(final String[] args) throws IOException { //args = "/examples/modern1.sparql"; final Options options = new Options(); options.addOption("f", "file", true, "a file that contains a SPARQL query"); options.addOption("g", "graph", true, "the graph that's used to execute the query [classic|modern|crew|kryo file]"); // TODO: add an OLAP option (perhaps: "--olap spark"?) final CommandLineParser parser = new DefaultParser(); final CommandLine commandLine; try {/*from w w w .j a v a2 s. c o m*/ commandLine = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); printHelp(1); return; } final InputStream inputStream = commandLine.hasOption("file") ? new FileInputStream(commandLine.getOptionValue("file")) : System.in; final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); final StringBuilder queryBuilder = new StringBuilder(); if (!reader.ready()) { printHelp(1); } String line; while (null != (line = reader.readLine())) { queryBuilder.append(System.lineSeparator()).append(line); } final String queryString = queryBuilder.toString(); final Graph graph; if (commandLine.hasOption("graph")) { switch (commandLine.getOptionValue("graph").toLowerCase()) { case "classic": graph = TinkerFactory.createClassic(); break; case "modern": graph = TinkerFactory.createModern(); System.out.println("Modern Graph Created"); break; case "crew": graph = TinkerFactory.createTheCrew(); break; default: graph = TinkerGraph.open(); System.out.println("Graph Created"); long startTime = System.nanoTime(); graph.io(IoCore.gryo()).readGraph(commandLine.getOptionValue("graph")); long endTime = System.nanoTime(); System.out.println("Time taken to load graph from kyro file: " + (endTime - startTime) / 1000000 + " mili seconds"); break; } } else { graph = TinkerFactory.createModern(); } final Traversal<Vertex, ?> traversal = SparqlToGremlinCompiler.convertToGremlinTraversal(graph, queryString); printWithHeadline("SPARQL Query", queryString); printWithHeadline("Traversal (prior execution)", traversal); Bytecode traversalByteCode = traversal.asAdmin().getBytecode(); //JavaTranslator.of(graph.traversal()).translate(traversalByteCode); System.out.println("the Byte Code : " + traversalByteCode.toString()); printWithHeadline("Result", String.join(System.lineSeparator(), JavaTranslator.of(graph.traversal()) .translate(traversalByteCode).toStream().map(Object::toString).collect(Collectors.toList()))); printWithHeadline("Traversal (after execution)", traversal); }
From source file:AndroidUninstallStock.java
@SuppressWarnings("static-access") public static void main(String[] args) { try {// w w w. j av a2s .c o m String lang = Locale.getDefault().getLanguage(); GnuParser cmdparser = new GnuParser(); Options cmdopts = new Options(); for (String fld : Arrays.asList("shortOpts", "longOpts", "optionGroups")) { // hack for printOptions java.lang.reflect.Field fieldopt = cmdopts.getClass().getDeclaredField(fld); fieldopt.setAccessible(true); fieldopt.set(cmdopts, new LinkedHashMap<>()); } cmdopts.addOption("h", "help", false, "Help"); cmdopts.addOption("t", "test", false, "Show only report"); cmdopts.addOption(OptionBuilder.withLongOpt("adb").withArgName("file").hasArg() .withDescription("Path to ADB from Android SDK").create("a")); cmdopts.addOption(OptionBuilder.withLongOpt("dev").withArgName("device").hasArg() .withDescription("Select device (\"adb devices\")").create("d")); cmdopts.addOption(null, "restore", false, "If packages have not yet removed and are disabled, " + "you can activate them again"); cmdopts.addOption(null, "google", false, "Delete packages are in the Google section"); cmdopts.addOption(null, "unapk", false, "Delete /system/app/ *.apk *.odex *.dex" + System.lineSeparator() + "(It is required to repeat command execution)"); cmdopts.addOption(null, "unlib", false, "Delete /system/lib/[libs in apk]"); //cmdopts.addOption(null, "unfrw", false, "Delete /system/framework/ (special list)"); cmdopts.addOption(null, "scanlibs", false, "(Dangerous!) Include all the libraries of selected packages." + " Use with --unlib"); cmdopts.addOptionGroup(new OptionGroup() { { addOption(OptionBuilder.withLongOpt("genfile").withArgName("file").hasArg().isRequired() .withDescription("Create file with list packages").create()); addOption(OptionBuilder.withLongOpt("lang").withArgName("ISO 639").hasArg().create()); } }); cmdopts.getOption("lang").setDescription( "See hl= in Google URL (default: " + lang + ") " + "for description from Google Play Market"); CommandLine cmd = cmdparser.parse(cmdopts, args); if (args.length == 0 || cmd.hasOption("help")) { PrintWriter console = new PrintWriter(System.out); HelpFormatter cmdhelp = new HelpFormatter(); cmdhelp.setOptionComparator(new Comparator<Option>() { @Override public int compare(Option o1, Option o2) { return 0; } }); console.println("WARNING: Before use make a backup with ClockworkMod Recovery!"); console.println(); console.println("AndroidUninstallStock [options] [AndroidListSoft.xml]"); cmdhelp.printOptions(console, 80, cmdopts, 3, 2); console.flush(); return; } String adb = cmd.getOptionValue("adb", "adb"); try { run(adb, "start-server"); } catch (IOException e) { System.out.println("Error: Not found ADB! Use -a or --adb"); return; } final boolean NotTest = !cmd.hasOption("test"); String deverror = getDeviceStatus(adb, cmd.getOptionValue("dev")); if (!deverror.isEmpty()) { System.out.println(deverror); return; } System.out.println("Getting list packages:"); LinkedHashMap<String, String> apklist = new LinkedHashMap<String, String>(); for (String ln : run(adb, "-s", lastdevice, "shell", "pm list packages -s -f")) { // "pm list packages" give list sorted by packages ;) String pckg = ln.substring("package:".length()); String pckgname = ln.substring(ln.lastIndexOf('=') + 1); pckg = pckg.substring(0, pckg.length() - pckgname.length() - 1); if (!pckgname.equals("android") && !pckgname.equals("com.android.vending")/*Google Play Market*/) { apklist.put(pckg, pckgname); } } for (String ln : run(adb, "-s", lastdevice, "shell", "ls /system/app/")) { String path = "/system/app/" + ln.replace(".odex", ".apk").replace(".dex", ".apk"); if (!apklist.containsKey(path)) { apklist.put(path, ""); } } apklist.remove("/system/app/mcRegistry"); for (Map.Entry<String, String> info : sortByValues(apklist).entrySet()) { System.out.println(info.getValue() + " = " + info.getKey()); } String genfile = cmd.getOptionValue("genfile"); if (genfile != null) { Path genpath = Paths.get(genfile); try (BufferedWriter gen = Files.newBufferedWriter(genpath, StandardCharsets.UTF_8, new StandardOpenOption[] { StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE })) { if (cmd.getOptionValue("lang") != null) { lang = cmd.getOptionValue("lang"); } LinkedHashSet<String> listsystem = new LinkedHashSet<String>() { { add("com.android"); add("com.google.android"); //add("com.sec.android.app"); add("com.monotype.android"); add("eu.chainfire.supersu"); } }; // \r\n for Windows Notepad gen.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); gen.write("<!-- & raplace with & or use <![CDATA[ ]]> -->\r\n"); gen.write("<AndroidUninstallStock>\r\n\r\n"); gen.write("<Normal>\r\n"); System.out.println(); System.out.println("\tNormal:"); writeInfo(gen, apklist, lang, listsystem, true); gen.write("\t<apk name=\"Exclude Google and etc\">\r\n"); for (String exc : listsystem) { gen.write("\t\t<exclude global=\"true\" in=\"package\" pattern=\"" + exc + "\" />\r\n"); } gen.write("\t</apk>\r\n"); gen.write("</Normal>\r\n\r\n"); gen.write("<Google>\r\n"); System.out.println(); System.out.println("\tGoogle:"); writeInfo(gen, apklist, lang, listsystem, false); gen.write("</Google>\r\n\r\n"); gen.write("</AndroidUninstallStock>\r\n"); System.out.println("File " + genpath.toAbsolutePath() + " created."); } return; } String[] FileName = cmd.getArgs(); if (!(FileName.length > 0 && Files.isReadable(Paths.get(FileName[0])))) { System.out.println("Error: File " + FileName[0] + " not found!"); return; } DocumentBuilderFactory xmlfactory = getXmlDocFactory(); // DocumentBuilder.setErrorHandler() for print errors Document xml = xmlfactory.newDocumentBuilder().parse(new File(FileName[0])); LinkedList<AusInfo> Normal = new LinkedList<AusInfo>(); LinkedList<AusInfo> Google = new LinkedList<AusInfo>(); NodeList ndaus = xml.getElementsByTagName("AndroidUninstallStock").item(0).getChildNodes(); for (int ndausx = 0, ndausc = ndaus.getLength(); ndausx < ndausc; ndausx++) { Node ndnow = ndaus.item(ndausx); NodeList nd = ndnow.getChildNodes(); String ndname = ndnow.getNodeName(); for (int ndx = 0, ndc = nd.getLength(); ndx < ndc; ndx++) { if (!nd.item(ndx).getNodeName().equalsIgnoreCase("apk")) { continue; } if (ndname.equalsIgnoreCase("Normal")) { Normal.add(getApkInfo(nd.item(ndx))); } else if (ndname.equalsIgnoreCase("Google")) { Google.add(getApkInfo(nd.item(ndx))); } } } // FIXME This part must be repeated until the "pm uninstall" will not issue "Failure" on all packages. // Now requires a restart. System.out.println(); System.out.println("Include and Exclude packages (Normal):"); LinkedHashMap<String, String> apkNormal = getApkFromPattern(apklist, Normal, false); System.out.println(); System.out.println("Global Exclude packages (Normal):"); apkNormal = getApkFromPattern(apkNormal, Normal, true); System.out.println(); System.out.println("Final list packages (Normal):"); for (Map.Entry<String, String> info : sortByValues(apkNormal).entrySet()) { System.out.println(info.getValue() + " = " + info.getKey()); } LinkedHashMap<String, String> apkGoogle = new LinkedHashMap<String, String>(); if (cmd.hasOption("google")) { System.out.println(); System.out.println("Include and Exclude packages (Google):"); apkGoogle = getApkFromPattern(apklist, Google, false); System.out.println(); System.out.println("Global Exclude packages (Google):"); apkGoogle = getApkFromPattern(apkGoogle, Google, true); System.out.println(); System.out.println("Final list packages (Google):"); for (Map.Entry<String, String> info : sortByValues(apkGoogle).entrySet()) { System.out.println(info.getValue() + " = " + info.getKey()); } } if (NotTest) { if (!hasRoot(adb)) { System.out.println("No Root"); System.out.println(); System.out.println("FINISH :)"); return; } } if (cmd.hasOption("restore")) { System.out.println(); System.out.println("Enable (Restore) packages (Normal):"); damage(adb, "pm enable ", NotTest, apkNormal, 2); if (cmd.hasOption("google")) { System.out.println(); System.out.println("Enable (Restore) packages (Google):"); damage(adb, "pm enable ", NotTest, apkGoogle, 2); } System.out.println(); System.out.println("FINISH :)"); return; } else { System.out.println(); System.out.println("Disable packages (Normal):"); damage(adb, "pm disable ", NotTest, apkNormal, 2); if (cmd.hasOption("google")) { System.out.println(); System.out.println("Disable packages (Google):"); damage(adb, "pm disable ", NotTest, apkGoogle, 2); } } if (!cmd.hasOption("unapk") && !cmd.hasOption("unlib")) { System.out.println(); System.out.println("FINISH :)"); return; } // Reboot now not needed /*if (NotTest) { reboot(adb, "-s", lastdevice, "reboot"); if (!hasRoot(adb)) { System.out.println("No Root"); System.out.println(); System.out.println("FINISH :)"); return; } }*/ if (cmd.hasOption("unlib")) { // "find" not found System.out.println(); System.out.println("Getting list libraries:"); LinkedList<String> liblist = new LinkedList<String>(); liblist.addAll(run(adb, "-s", lastdevice, "shell", "ls -l /system/lib/")); String dircur = "/system/lib/"; for (int x = 0; x < liblist.size(); x++) { if (liblist.get(x).startsWith("scan:")) { dircur = liblist.get(x).substring("scan:".length()); liblist.remove(x); x--; } else if (liblist.get(x).startsWith("d")) { String dir = liblist.get(x).substring(liblist.get(x).lastIndexOf(':') + 4) + "/"; liblist.remove(x); x--; liblist.add("scan:/system/lib/" + dir); liblist.addAll(run(adb, "-s", lastdevice, "shell", "ls -l /system/lib/" + dir)); continue; } liblist.set(x, dircur + liblist.get(x).substring(liblist.get(x).lastIndexOf(':') + 4)); System.out.println(liblist.get(x)); } final boolean scanlibs = cmd.hasOption("scanlibs"); LinkedHashMap<String, String> libNormal = getLibFromPatternInclude(adb, liblist, apkNormal, Normal, "Normal", scanlibs); libNormal = getLibFromPatternGlobalExclude(libNormal, Normal, "Normal"); System.out.println(); System.out.println("Final list libraries (Normal):"); for (Map.Entry<String, String> info : sortByValues(libNormal).entrySet()) { System.out.println(info.getKey() + " = " + info.getValue()); } LinkedHashMap<String, String> libGoogle = new LinkedHashMap<String, String>(); if (cmd.hasOption("google")) { libGoogle = getLibFromPatternInclude(adb, liblist, apkGoogle, Google, "Google", scanlibs); libGoogle = getLibFromPatternGlobalExclude(libGoogle, Google, "Google"); System.out.println(); System.out.println("Final list libraries (Google):"); for (Map.Entry<String, String> info : sortByValues(libGoogle).entrySet()) { System.out.println(info.getKey() + " = " + info.getValue()); } } LinkedHashMap<String, String> apkExclude = new LinkedHashMap<String, String>(apklist); for (String key : apkNormal.keySet()) { apkExclude.remove(key); } for (String key : apkGoogle.keySet()) { apkExclude.remove(key); } System.out.println(); System.out.println("Include libraries from Exclude packages:"); LinkedHashMap<String, String> libExclude = getLibFromPackage(adb, liblist, apkExclude); System.out.println(); System.out.println("Enclude libraries from Exclude packages (Normal):"); for (Map.Entry<String, String> info : sortByValues(libNormal).entrySet()) { if (libExclude.containsKey(info.getKey())) { System.out.println("exclude: " + info.getKey() + " = " + libExclude.get(info.getKey())); libNormal.remove(info.getKey()); } } System.out.println(); System.out.println("Enclude libraries from Exclude packages (Google):"); for (Map.Entry<String, String> info : sortByValues(libGoogle).entrySet()) { if (libExclude.containsKey(info.getKey())) { System.out.println("exclude: " + info.getKey() + " = " + libExclude.get(info.getKey())); libGoogle.remove(info.getKey()); } } System.out.println(); System.out.println("Delete libraries (Normal):"); damage(adb, "rm ", NotTest, libNormal, 1); if (cmd.hasOption("google")) { System.out.println(); System.out.println("Delete libraries (Google):"); damage(adb, "rm ", NotTest, libGoogle, 1); } } if (cmd.hasOption("unapk")) { System.out.println(); System.out.println("Cleaning data packages (Normal):"); damage(adb, "pm clear ", NotTest, apkNormal, 2); if (cmd.hasOption("google")) { System.out.println(); System.out.println("Cleaning data packages (Google):"); damage(adb, "pm clear ", NotTest, apkGoogle, 2); } System.out.println(); System.out.println("Uninstall packages (Normal):"); damage(adb, "pm uninstall ", NotTest, apkNormal, 2); if (cmd.hasOption("google")) { System.out.println(); System.out.println("Uninstall packages (Google):"); damage(adb, "pm uninstall ", NotTest, apkGoogle, 2); } } if (cmd.hasOption("unapk")) { System.out.println(); System.out.println("Delete packages (Normal):"); LinkedHashMap<String, String> dexNormal = new LinkedHashMap<String, String>(); for (Map.Entry<String, String> apk : apkNormal.entrySet()) { dexNormal.put(apk.getKey(), apk.getValue()); dexNormal.put(apk.getKey().replace(".apk", ".dex"), apk.getValue()); dexNormal.put(apk.getKey().replace(".apk", ".odex"), apk.getValue()); } damage(adb, "rm ", NotTest, dexNormal, 1); if (cmd.hasOption("google")) { System.out.println(); System.out.println("Delete packages (Google):"); LinkedHashMap<String, String> dexGoogle = new LinkedHashMap<String, String>(); for (Map.Entry<String, String> apk : apkGoogle.entrySet()) { dexGoogle.put(apk.getKey(), apk.getValue()); dexGoogle.put(apk.getKey().replace(".apk", ".dex"), apk.getValue()); dexGoogle.put(apk.getKey().replace(".apk", ".odex"), apk.getValue()); } damage(adb, "rm ", NotTest, dexGoogle, 1); } } if (NotTest) { run(adb, "-s", lastdevice, "reboot"); } System.out.println(); System.out.println("FINISH :)"); } catch (SAXException e) { System.out.println("Error parsing list: " + e); } catch (Throwable e) { e.printStackTrace(); } }
From source file:com.verizon.Main.java
public static void main(String[] args) throws Exception { String warehouseLocation = "file:" + System.getProperty("user.dir") + "spark-warehouse"; SparkSession spark = SparkSession.builder().appName("Verizon").config("spark.master", "local[2]") .config("spark.sql.warehouse.dir", warehouseLocation).enableHiveSupport().getOrCreate(); Configuration configuration = new Configuration(); configuration.addResource(new Path(System.getProperty("HADOOP_INSTALL") + "/conf/core-site.xml")); configuration.addResource(new Path(System.getProperty("HADOOP_INSTALL") + "/conf/hdfs-site.xml")); configuration.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName()); configuration.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName()); FileSystem hdfs = FileSystem.get(new URI("hdfs://localhost:9000"), configuration); SQLContext context = new SQLContext(spark); String schemaString = " Device,Title,ReviewText,SubmissionTime,UserNickname"; //spark.read().textFile(schemaString) Dataset<Row> df = spark.read().csv("hdfs://localhost:9000/data.csv"); //df.show();/*from ww w . j a va 2 s . c o m*/ //#df.printSchema(); df = df.select("_c2"); Path file = new Path("hdfs://localhost:9000/tempFile.txt"); if (hdfs.exists(file)) { hdfs.delete(file, true); } df.write().csv("hdfs://localhost:9000/tempFile.txt"); JavaRDD<String> lines = spark.read().textFile("hdfs://localhost:9000/tempFile.txt").javaRDD(); JavaRDD<String> words = lines.flatMap(new FlatMapFunction<String, String>() { @Override public Iterator<String> call(String s) { return Arrays.asList(SPACE.split(s)).iterator(); } }); JavaPairRDD<String, Integer> ones = words.mapToPair(new PairFunction<String, String, Integer>() { @Override public Tuple2<String, Integer> call(String s) { s = s.replaceAll("[^a-zA-Z0-9]+", ""); s = s.toLowerCase().trim(); return new Tuple2<>(s, 1); } }); JavaPairRDD<String, Integer> counts = ones.reduceByKey(new Function2<Integer, Integer, Integer>() { @Override public Integer call(Integer i1, Integer i2) { return i1 + i2; } }); JavaPairRDD<Integer, String> frequencies = counts .mapToPair(new PairFunction<Tuple2<String, Integer>, Integer, String>() { @Override public Tuple2<Integer, String> call(Tuple2<String, Integer> s) { return new Tuple2<Integer, String>(s._2, s._1); } }); frequencies = frequencies.sortByKey(false); JavaPairRDD<String, Integer> result = frequencies .mapToPair(new PairFunction<Tuple2<Integer, String>, String, Integer>() { @Override public Tuple2<String, Integer> call(Tuple2<Integer, String> s) throws Exception { return new Tuple2<String, Integer>(s._2, s._1); } }); //JavaPairRDD<Integer,String> sortedByFreq = sort(frequencies, "descending"); file = new Path("hdfs://localhost:9000/allresult.csv"); if (hdfs.exists(file)) { hdfs.delete(file, true); } //FileUtils.deleteDirectory(new File("allresult.csv")); result.saveAsTextFile("hdfs://localhost:9000/allresult.csv"); List<Tuple2<String, Integer>> output = result.take(250); ExportToHive hiveExport = new ExportToHive(); String rows = ""; for (Tuple2<String, Integer> tuple : output) { String date = new Date().toString(); String keyword = tuple._1(); Integer count = tuple._2(); //System.out.println( keyword+ "," +count); rows += date + "," + "Samsung Galaxy s7," + keyword + "," + count + System.lineSeparator(); } //System.out.println(rows); /* file = new Path("hdfs://localhost:9000/result.csv"); if ( hdfs.exists( file )) { hdfs.delete( file, true ); } OutputStream os = hdfs.create(file); BufferedWriter br = new BufferedWriter( new OutputStreamWriter( os, "UTF-8" ) ); br.write(rows); br.close(); */ hdfs.close(); FileUtils.deleteQuietly(new File("result.csv")); FileUtils.writeStringToFile(new File("result.csv"), rows); hiveExport.writeToHive(spark); ExportDataToServer exportServer = new ExportDataToServer(); exportServer.sendDataToRESTService(rows); spark.stop(); }
From source file:edu.usc.qufd.Main.java
/** * The main method.// w w w . ja va2s .c o m * * @param args the arguments * @throws IOException Signals that an I/O exception has occurred. */ public static void main(String[] args) throws IOException { if (parseInputs(args) == false) { System.exit(-1); //The input files do not exist } /* * Parsing inputs: fabric & qasm file */ PrintWriter outputFile; RandomAccessFile raf = null; String latencyPlaceHolder; if (RuntimeConfig.OUTPUT_TO_FILE) { latencyPlaceHolder = "Total Latency: " + Long.MAX_VALUE + " us" + System.lineSeparator(); raf = new RandomAccessFile(outputFileAddr, "rws"); //removing the old values in the file raf.setLength(0); //writing a place holder for the total latency raf.writeBytes(latencyPlaceHolder); raf.close(); outputFile = new PrintWriter(new BufferedWriter(new FileWriter(outputFileAddr, true)), true); } else { //writing to stdout outputFile = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true); } /* parsing the input*/ layout = LayoutParser.parse(pmdFileAddr); qasm = QASMParser.QASMParser(qasmFileAddr, layout); long totalLatency = qufd(outputFile); if (RuntimeConfig.OUTPUT_TO_FILE) { outputFile.close(); //Over writing the place holder with the actual latency String latencyActual = "Total Latency: " + totalLatency + " " + layout.getTimeUnit(); latencyActual = StringUtils.rightPad(latencyActual, latencyPlaceHolder.length() - System.lineSeparator().length()); raf = new RandomAccessFile(outputFileAddr, "rws"); //Writing to the top of a file raf.seek(0); //writing the actual total latency in the at the top of the output file raf.writeBytes(latencyActual + System.lineSeparator()); raf.close(); } else { outputFile.flush(); System.out.println("Total Latency: " + totalLatency + " " + layout.getTimeUnit()); } if (RuntimeConfig.VERBOSE) { System.out.println("Done."); } outputFile.close(); }
From source file:DataCrawler.OpenAIRE.XMLGenerator.java
public static void main(String[] args) { String text = ""; try {// w ww . j ava2 s . com if (args.length < 4) { System.out.println("<command> template_file csv_file output_dir log_file [start_id]"); } // InputStream fis = new FileInputStream("E:/Downloads/result-r-00000"); InputStream fis = new FileInputStream(args[1]); BufferedReader br = new BufferedReader(new InputStreamReader(fis, Charset.forName("UTF-8"))); // String content = new String(Files.readAllBytes(Paths.get("publications_template.xml"))); String content = new String(Files.readAllBytes(Paths.get(args[0]))); Document doc = Jsoup.parse(content, "UTF-8", Parser.xmlParser()); // String outputDirectory = "G:/"; String outputDirectory = args[2]; // PrintWriter logWriter = new PrintWriter(new FileOutputStream("publication.log",false)); PrintWriter logWriter = new PrintWriter(new FileOutputStream(args[3], false)); Element objectId = null, title = null, publisher = null, dateofacceptance = null, bestlicense = null, resulttype = null, originalId = null, originalId2 = null; boolean start = true; // String startID = "dedup_wf_001::207a098867b64f3b5af505fa3aeecd24"; String startID = ""; if (args.length >= 5) { start = false; startID = args[4]; } String previousText = ""; while ((text = br.readLine()) != null) { /* For publications: 0. dri:objIdentifier context 9. title context 12. publisher context 18. dateofacceptance 19. bestlicense @classname 21. resulttype @classname 26. originalId context (Notice that the prefix is null and will use space to separate two different "originalId") */ if (!previousText.isEmpty()) { text = previousText + text; start = true; previousText = ""; } String[] items = text.split("!"); for (int i = 0; i < items.length; ++i) { items[i] = StringUtils.strip(items[i], "#"); } if (objectId == null) objectId = doc.getElementsByTag("dri:objIdentifier").first(); objectId.text(items[0]); if (!start && items[0].equals(startID)) { start = true; } if (title == null) title = doc.getElementsByTag("title").first(); title.text(items[9]); if (publisher == null) publisher = doc.getElementsByTag("publisher").first(); if (items.length < 12) { previousText = text; continue; } publisher.text(items[12]); if (dateofacceptance == null) dateofacceptance = doc.getElementsByTag("dateofacceptance").first(); dateofacceptance.text(items[18]); if (bestlicense == null) bestlicense = doc.getElementsByTag("bestlicense").first(); bestlicense.attr("classname", items[19]); if (resulttype == null) resulttype = doc.getElementsByTag("resulttype").first(); resulttype.attr("classname", items[21]); if (originalId == null || originalId2 == null) { Elements elements = doc.getElementsByTag("originalId"); String[] context = items[26].split(" "); if (elements.size() > 0) { if (elements.size() >= 1) { originalId = elements.get(0); if (context.length >= 1) { int indexOfnull = context[0].trim().indexOf("null"); String value = ""; if (indexOfnull != -1) { if (context[0].trim().length() >= (indexOfnull + 5)) value = context[0].trim().substring(indexOfnull + 5); } else { value = context[0].trim(); } originalId.text(value); } } if (elements.size() >= 2) { originalId2 = elements.get(1); if (context.length >= 2) { int indexOfnull = context[1].trim().indexOf("null"); String value = ""; if (indexOfnull != -1) { if (context[1].trim().length() >= (indexOfnull + 5)) value = context[1].trim().substring(indexOfnull + 5); } else { value = context[1].trim(); } originalId2.text(value); } } } } else { String[] context = items[26].split(" "); if (context.length >= 1) { int indexOfnull = context[0].trim().indexOf("null"); String value = ""; if (indexOfnull != -1) { if (context[0].trim().length() >= (indexOfnull + 5)) value = context[0].trim().substring(indexOfnull + 5); } else { value = context[0].trim(); } originalId.text(value); } if (context.length >= 2) { int indexOfnull = context[1].trim().indexOf("null"); String value = ""; if (indexOfnull != -1) { if (context[1].trim().length() >= (indexOfnull + 5)) value = context[1].trim().substring(indexOfnull + 5); } else { value = context[1].trim(); } originalId2.text(value); } } if (start) { String filePath = outputDirectory + items[0].replace(":", "#") + ".xml"; PrintWriter writer = new PrintWriter(new FileOutputStream(filePath, false)); logWriter.write(filePath + " > Start" + System.lineSeparator()); writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + System.lineSeparator()); writer.write(doc.getElementsByTag("response").first().toString()); writer.close(); logWriter.write(filePath + " > OK" + System.lineSeparator()); logWriter.flush(); } } logWriter.close(); } catch (Exception e) { e.printStackTrace(); } }