List of usage examples for org.apache.commons.io IOUtils readLines
public static List readLines(Reader input) throws IOException
Reader
as a list of Strings, one entry per line. From source file:com.slemarchand.sqlqueryscripting.scripting.sqlquery.SQLQueryExecutor.java
private Map _getHints(String sqlQuery) throws ScriptingException { Properties props = new Properties(); try {/*www. j a va 2 s . c o m*/ List<String> lines = IOUtils.readLines(new StringReader(sqlQuery)); StringBuilder hintsStr = new StringBuilder(); for (String l : lines) { l = l.trim(); if (l.startsWith("--")) { hintsStr.append(l.substring(2).trim() + LINE_SEPARATOR); } } props.load(new StringReader(hintsStr.toString())); } catch (IOException e) { throw new ScriptingException(e); } return props; }
From source file:com.evolveum.midpoint.model.intest.TestNotifications.java
@Override protected void addSystemConfigurationObject(OperationResult initResult) throws IOException, CommonException, EncryptionException { List<String> configLines = IOUtils.readLines(new FileReader(SYSTEM_CONFIGURATION_FILE)); String configString = StringUtils.join(configLines, '\n'); int port = startHttpServer(); configString = configString.replaceAll("\\$\\$port\\$\\$", Integer.toString(port)); repoAddObject(prismContext.parseObject(configString), initResult); }
From source file:com.synaptix.sonar.plugins.gitlab.CommitFacade.java
private static void processPatch(Set<Integer> patchLocationMapping, String patch) throws IOException { int currentLine = -1; for (String line : IOUtils.readLines(new StringReader(patch))) { if (line.startsWith("@")) { // http://en.wikipedia.org/wiki/Diff_utility#Unified_format Matcher matcher = Pattern .compile("@@\\p{Space}-[0-9]+(?:,[0-9]+)?\\p{Space}\\+([0-9]+)(?:,[0-9]+)?\\p{Space}@@.*") .matcher(line);//from w ww . j ava 2 s. c o m if (!matcher.matches()) { throw new IllegalStateException( "Unable to parse patch line " + line + "\nFull patch: \n" + patch); } currentLine = Integer.parseInt(matcher.group(1)); } else if (line.startsWith("-")) { // Skip removed lines } else if (line.startsWith("+") || line.startsWith(" ")) { // Count added and unmodified lines patchLocationMapping.add(currentLine); currentLine++; } else if (line.startsWith("\\")) { // I'm only aware of \ No newline at end of file // Ignore } } }
From source file:de.tudarmstadt.ukp.dkpro.keyphrases.wikipediafilter.filter.DictionaryFilter.java
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); // Set default paths. This cannot be done in the annotation because we cannot call // methods there. if (paths == null || paths.size() == 0) { paths = new HashSet<String>(); paths.add(Keyphrase.class.getName()); }/*from w w w . ja va 2 s. com*/ try { dictionarySets = new HashMap<String, Set<String>>(); for (String articleFileName : dictionaryFileNames) { String fileLocale = "*"; // Check if a locale is defined for the file if (articleFileName.startsWith("[")) { fileLocale = articleFileName.substring(1, articleFileName.indexOf(']')); articleFileName = articleFileName.substring(articleFileName.indexOf(']') + 1); } // Fetch the set for the specified locale Set<String> set = dictionarySets.get(fileLocale); if (set == null) { set = new HashSet<String>(); dictionarySets.put(fileLocale, set); } // Load the set URL source = resolveLocation(articleFileName, this, context); for (String line : IOUtils.readLines(source.openStream())) { set.add(lowercase ? line.toLowerCase(new Locale(fileLocale)) : line); } context.getLogger().log(INFO, "Loaded dicionary for locale [" + fileLocale + "] from [" + source + "]"); } } catch (IOException e1) { throw new ResourceInitializationException(e1); } }
From source file:com.impala.paga.all.RouteRemit.java
/** * /*from w w w.j a v a 2 s . co m*/ * @param request * @return * @throws IOException */ private String moneytransfer(HttpServletRequest request) throws IOException, JSONException, NoSuchAlgorithmException { // joined json string Account account = null; String join = ""; JsonElement root = null, roots = null; JsonObject root2 = null, creditrequest = null; Properties prop = new Properties(); String hashkey = prop.getProperty("hashkey"); String principal = prop.getProperty("principal"); String credentials = prop.getProperty("credentials"); //String hashkey ="372e9b1c62ef47db83c566cf2db033cb4e1b847e12ec435997971ebd7ab8121cbd8458176374480eae7d4cb55f722f4ab328207b461f423a85a9bbad8850ce66"; //String principal="02A10715-0E53-4A8C-982E-2B7BFC7CF550"; //String credentials ="QE3@u=jd*2b+"; String apiusername = "", apipassword = "", username = "", transactioinid = "", sourcecountrycode = "", recipientcurrencycode = "", recipientcountrycode = "", sourcemsisdn = "", recipientmobile = "", sendername = "", amountstring = "", remiturlss = "", responseobject = "", statuscode = "", statusdescription = "", referencenumber = ""; // Get all parameters, the keys of the parameters are specified List<String> lines = IOUtils.readLines(request.getReader()); // used to format/join incoming JSon string join = StringUtils.join(lines.toArray(), ""); // ############################################################################################### // instantiate the JSon // Note // The = sign is encoded to \u003d. Hence you need to use // disableHtmlEscaping(). // ############################################################################################### Gson g = new GsonBuilder().disableHtmlEscaping().create(); // Gson g = new Gson(); Map<String, String> expected = new HashMap<>(); try { // parse the JSon string root = new JsonParser().parse(join); apiusername = root.getAsJsonObject().get("username").getAsString(); apipassword = root.getAsJsonObject().get("password").getAsString(); username = root.getAsJsonObject().get("sendingIMT").getAsString(); transactioinid = root.getAsJsonObject().get("transaction_id").getAsString(); sourcecountrycode = root.getAsJsonObject().get("sourcecountrycode").getAsString(); recipientcurrencycode = root.getAsJsonObject().get("recipientcurrencycode").getAsString(); recipientcountrycode = root.getAsJsonObject().get("recipientcountrycode").getAsString(); sendername = root.getAsJsonObject().get("Sender_Name").getAsString(); amountstring = root.getAsJsonObject().get("amount").getAsString(); remiturlss = root.getAsJsonObject().get("url").getAsString(); sourcemsisdn = root.getAsJsonObject().get("source_msisdn").getAsString(); recipientmobile = root.getAsJsonObject().get("beneficiary_msisdn").getAsString(); root2 = root.getAsJsonObject(); } catch (Exception e) { expected.put("command_status", APIConstants.COMMANDSTATUS_INVALID_PARAMETERS); String jsonResult = g.toJson(expected); return jsonResult; } // check for the presence of all required parameters if (StringUtils.isBlank(apiusername) || StringUtils.isBlank(apipassword) || StringUtils.isBlank(username) || StringUtils.isBlank(transactioinid) || StringUtils.isBlank(sourcecountrycode) || StringUtils.isBlank(recipientcurrencycode) || StringUtils.isBlank(sendername) || StringUtils.isBlank(amountstring) || StringUtils.isBlank(remiturlss) || StringUtils.isBlank(recipientcountrycode)) { expected.put("status_code", "server error"); expected.put("status_description", "missing parameters"); String jsonResult = g.toJson(expected); return jsonResult; } if (root2.has("vendor_uniquefields")) { } // Retrieve the account details Element element; if ((element = accountsCache.get(username)) != null) { account = (Account) element.getObjectValue(); } // Secure against strange servers making request(future upgrade should // lock on IP) if (account == null) { expected.put("status_code", "server error"); expected.put("status_description", "unauthorised user"); String jsonResult = g.toJson(expected); return jsonResult; } MessageDigest md = null; String saltedToken = transactioinid + amountstring + recipientmobile + hashkey; md = MessageDigest.getInstance("SHA-512"); md.update(saltedToken.getBytes()); byte byteData[] = md.digest(); //convert the byte to hex format method 1 StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } System.out.println("Hex format : " + sb.toString()); String hash = sb.toString(); int intamount = Integer.parseInt(amountstring); toPaga.put("referenceNumber", transactioinid); toPaga.put("amount", amountstring); toPaga.put("destinationAccount", recipientmobile); System.out.println(toPaga.toString()); //assign the remit url from properties.config CLIENT_URL = remiturlss; //principal = "" , credentials = "", hash = "" PostWithIgnoreSSLPaga = new PostWithIgnoreSSLPaga(CLIENT_URL, toPaga.toString(), principal, credentials, hash); //capture the switch respoinse. responseobject = PostWithIgnoreSSLPaga.doPost(); System.out.println(responseobject); //pass the returned json string JsonElement roots1 = new JsonParser().parse(responseobject); int responseCode = roots1.getAsJsonObject().get("responseCode").getAsInt(); String switchresponse = Integer.toString(responseCode); //add String success = "S001"; if (responseCode == 0) { //exctract a specific json element from the object(status_code) statusdescription = roots1.getAsJsonObject().get("message").getAsString(); expected.put("am_referenceid", transactioinid); expected.put("am_timestamp", success); expected.put("status_code", "S001"); expected.put("status_description", statusdescription); String jsonResult = g.toJson(expected); return jsonResult; } expected.put("am_referenceid", ""); expected.put("am_timestamp", ""); expected.put("status_code", ""); expected.put("status_description", ""); String jsonResult = g.toJson(expected); return jsonResult; }
From source file:com.firewallid.classification.TrainingData.java
public void upload(JavaSparkContext jsc) throws IOException { int partitions = conf.getInt(PARTITIONS, 48); String docDelimiter = StringEscapeUtils.unescapeJava(conf.get(DOC_DELIMITER)); /* load training data */ List<String> resource = IOUtils .readLines(getClass().getClassLoader().getResourceAsStream(conf.get(TRAININGDATA_RESOURCE))); Broadcast<List<String>> broadcastRes = jsc.broadcast(resource); JavaPairRDD<String, Tuple2<String, String>> doc = jsc.parallelize(broadcastRes.value()) .persist(StorageLevel.MEMORY_AND_DISK_SER_2()).repartition(partitions) .filter(line -> line.split(docDelimiter).length >= 2) .mapToPair(line -> new Tuple2<>(line.split(docDelimiter)[0], new Tuple2<>(line.split(docDelimiter)[1], line.split(docDelimiter)[2]))); /* save *//*ww w . j a v a 2 s .com*/ save(doc); }
From source file:lyonlancer5.karasu.util.ModFileUtils.java
public void initialize() { LOGGER.info("Initializing mod utilities"); //MARKER: Load configuration (VERY early stage) Configuration config = new Configuration(new File(Constants.MAIN_DIR, "config.properties")); try {/*from w w w. j ava2 s . c om*/ config.load(); doHashCheck = config .get("General", "Perform Integrity Check", true, "Performs an integrity check of this mod's files to preserve " + "integrity. The checks performed are MD5 and SHA-1 " + "hash comparisons") .getBoolean(); doUpdateCheck = config.get("General", "Do Update Checks", true, "Checks for updates by querying the main repository for " + "information regarding new releases.") .getBoolean(); checkForPreReleases = config .get("General", "Include Pre-release Versions", false, "Checks for pre-release builds along with the stable release checks. This " + "option does not enable checking for development/snapshot builds. " + "This option is ignored if performing update checks are disabled.") .getBoolean(); } catch (Exception e) { Constants.LOGGER.warn("Mod configuration failed", e); } finally { config.save(); } //MARKER: Now write settings for the YAML reader try { if (!yamlConfig.exists()) { yamlConfig.createNewFile(); try { download("https://raw.githubusercontent.com/Lyonlancer5/Project-Karasu/master/jyaml.yml", yamlConfig); } catch (Exception e) { try { InputStream in = LL5_Karasu.class.getResourceAsStream("/assets/ll5_karasu/jyaml.yml"); PrintWriter writer = new PrintWriter(yamlConfig); for (String s : IOUtils.readLines(in)) writer.print(s); writer.flush(); writer.close(); } catch (Exception e1) { PrintWriter writer = new PrintWriter(yamlConfig); writer.println("minimalOutput: false"); writer.println("# Indentation per line would only be two spaces"); writer.println("indentAmount: \" \""); writer.println("suppressWarnings: false"); writer.println("encoding: \"UTF-8\""); writer.println("transfers:"); writer.println(" keymap: java.util.HashMap"); writer.flush(); writer.close(); } } LOGGER.info("Created default YAML parser configuration"); } } catch (Exception e) { return; } //MARKER: Then grab a copy of the hash files try { if (remoteHashes.exists()) { remoteHashes.delete(); } remoteHashes.getParentFile().mkdirs(); remoteHashes.createNewFile(); remoteHashes.deleteOnExit(); download("https://raw.githubusercontent.com/Lyonlancer5/Project-Karasu/master/hash.yml", remoteHashes); LOGGER.info("Retrieved remote hash cache"); } catch (Exception e) { return; } hasInitialized = true; }
From source file:com.impala.paga.all.RouteRemit1.java
/** * /* w w w. j a v a2 s . c o m*/ * @param request * @return * @throws IOException */ private String moneytransfer(HttpServletRequest request) throws IOException, JSONException, NoSuchAlgorithmException { // joined json string String join = ""; JsonElement root = null; JsonElement root2 = null; JsonElement root3 = null; String responseobject = ""; String remiturl = "https://www.mypaga.com/paga-webservices/business-rest/secured/moneyTransfer"; String hashkey = "372e9b1c62ef47db83c566cf2db033cb4e1b847e12ec435997971ebd7ab8121cbd8458176374480eae7d4cb55f722f4ab328207b461f423a85a9bbad8850ce66"; String principal = "02A10715-0E53-4A8C-982E-2B7BFC7CF550"; String credentials = "QE3@u=jd*2b+"; /*String referenceNumber = "", amount = "",currency="",destinationAccount="", destinationBank= "", senderPrincipal = "", senderCrendetials = "", transferReference = "", sourceOfFunds = "", sendWithdrawalCode = "" , minRecipientKYCLevel = "", holdingPeriod = "", principal = "" , credentials = "", hash = ""; */ // These represent parameters received over the network String referenceNumber = "", amount = "", currency = "", destinationAccount = "", destinationBank = "", senderPrincipal = "", senderCrendetials = "", transferReference = "", sourceOfFunds = "", sendWithdrawalCode = "", minRecipientKYCLevel = "", holdingPeriod = ""; // Get all parameters, the keys of the parameters are specified List<String> lines = IOUtils.readLines(request.getReader()); // used to format/join incoming JSon string join = StringUtils.join(lines.toArray(), ""); //############################################################################### // instantiate the JSon //Note //The = sign is encoded to \u003d. Hence you need to use disableHtmlEscaping(). //############################################################################### Gson g = new GsonBuilder().disableHtmlEscaping().create(); //Gson g = new Gson(); Map<String, String> expected = new HashMap<>(); try { // parse the JSon string root = new JsonParser().parse(join); referenceNumber = root.getAsJsonObject().get("referenceNumber").getAsString(); amount = root.getAsJsonObject().get("amount").getAsString(); destinationAccount = root.getAsJsonObject().get("destinationAccount").getAsString(); } catch (Exception e) { expected.put("command_status", "COMMANDSTATUS_INVALID_PARAMETERS"); String jsonResult = g.toJson(expected); System.out.println(e); return jsonResult; } /*String referenceNumber = "", amount = "",currency="",destinationAccount="", destinationBank= "", senderPrincipal = "", senderCrendetials = "", transferReference = "", sourceOfFunds = "", sendWithdrawalCode = "" , minRecipientKYCLevel = "", holdingPeriod = "", principal = "" , credentials = "", hash = ""; */ // check for the presence of all required parameters if (StringUtils.isBlank(referenceNumber) || StringUtils.isBlank(amount) || StringUtils.isBlank(destinationAccount)) { expected.put("am_referenceid", referenceNumber); expected.put("am_timestamp", "tombwa"); expected.put("status_code", statuscode); expected.put("status_description", Statusdescription); String jsonResult = g.toJson(expected); return jsonResult; } MessageDigest md = null; String saltedToken = referenceNumber + amount + destinationAccount + hashkey; md = MessageDigest.getInstance("SHA-512"); md.update(saltedToken.getBytes()); byte byteData[] = md.digest(); //convert the byte to hex format method 1 StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } System.out.println("Hex format : " + sb.toString()); String hash = sb.toString(); int intamount = Integer.parseInt(amount); toPaga.put("referenceNumber", referenceNumber); toPaga.put("amount", amount); toPaga.put("destinationAccount", destinationAccount); System.out.println(toPaga.toString()); //assign the remit url from properties.config CLIENT_URL = remiturl; //principal = "" , credentials = "", hash = "" PostWithIgnoreSSLPaga = new PostWithIgnoreSSLPaga(CLIENT_URL, toPaga.toString(), principal, credentials, hash); //capture the switch respoinse. responseobject = PostWithIgnoreSSLPaga.doPost(); System.out.println(responseobject); //pass the returned json string JsonElement roots = new JsonParser().parse(responseobject); int responseCode = roots.getAsJsonObject().get("responseCode").getAsInt(); String switchresponse = Integer.toString(responseCode); //add String success = "S001"; if (responseCode == 0) { //exctract a specific json element from the object(status_code) String statusdescription = roots.getAsJsonObject().get("message").getAsString(); expected.put("am_referenceid", referenceNumber); expected.put("am_timestamp", success); expected.put("status_code", "S001"); expected.put("status_description", statusdescription); String jsonResult = g.toJson(expected); return jsonResult; } expected.put("am_referenceid", ""); expected.put("am_timestamp", ""); expected.put("status_code", ""); expected.put("status_description", ""); String jsonResult = g.toJson(expected); return jsonResult; }
From source file:com.widen.valet.importer.ImportZone.java
private List<ZoneUpdateAction> createZoneUpdateActions(Zone zone) throws IOException { List<String> lines = IOUtils.readLines(new FileInputStream(importFile)); boolean foundZoneRecords = false; List<ZoneUpdateAction> actions = new ArrayList<ZoneUpdateAction>(); for (String l : lines) { if (!foundZoneRecords) { if (StringUtils.contains(l, "; Zone records")) { foundZoneRecords = true; }//w ww.ja v a 2s . co m continue; } if (StringUtils.isNotBlank(l) && !l.startsWith(";")) { log.debug("processing line: {}", l); List<ZoneUpdateAction> actionForRecord = parseRecord(l, zone.name, actions); actions.addAll(actionForRecord); } } return actions; }
From source file:com.logsniffer.reader.grok.GrokTest.java
@Test public void testBasePatternSet() throws GrokException, IOException { GroksRegistry r = new GroksRegistry(); r.registerPatternBlocks(Collections.singletonMap("base", IOUtils.readLines(getClass().getResourceAsStream("/grok-patterns/base")).toArray(new String[0]))); String sysLogLine = "Nov 1 21:14:23 <1.3> localhost kernel: pid 84558 (expect), uid 30206: exited on signal 3"; Grok syslogGrok = Grok.compile(r,//from w ww .ja v a 2s . c o m "%{SYSLOGBASE} pid %{NUMBER:pid} \\(%{WORD:program2}\\), uid %{NUMBER:uid}: exited on signal %{NUMBER:signal}"); GrokMatcher m = syslogGrok.matcher(sysLogLine); assertEquals(true, m.matches()); assertEquals("Nov 1 21:14:23", m.group("timestamp")); assertEquals("1", m.group("facility")); assertEquals("3", m.group("priority")); assertEquals("localhost", m.group("logsource")); assertEquals("kernel", m.group("program")); assertEquals("expect", m.group("program2")); assertEquals("30206", m.group("uid")); assertEquals("3", m.group("signal")); assertEquals("84558", m.group("pid")); }