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:fi.aluesarjat.prototype.DataService.java
@SuppressWarnings("unchecked") public void loadData(DataServiceMode mode) throws IOException { logger.info("adding namespaces"); String dimensionNs = baseURI + ScovoDatasetHandler.DIMENSION_NS; Map<String, String> namespaces = new HashMap<String, String>(Namespaces.DEFAULT); namespaces.put(GEO.NS, "geo"); namespaces.put(SCV.NS, "scv"); namespaces.put(META.NS, "meta"); namespaces.put(DC.NS, "dc"); namespaces.put(DCTERMS.NS, "dcterms"); namespaces.put(STAT.NS, "stat"); namespaces.put(SKOS.NS, "skos"); namespaces.put(dimensionNs, "dimension"); namespaces.put(baseURI + ScovoDatasetHandler.DATASET_CONTEXT_BASE, "dataset"); namespaceHandler.addNamespaces(namespaces); logger.info("initializing data"); if (datasets == null) { // datasets = IOUtils.readLines(getStream("/data/datasets")); if (datasetsList.startsWith("classpath:")) { datasets = IOUtils.readLines(getStream(datasetsList.substring("classpath:".length()))); } else {//from w w w .jav a2 s.com InputStream in = new URL(datasetsList).openStream(); datasets = IOUtils.readLines(in); in.close(); } } if (mode == DataServiceMode.PARALLEL) { for (String d : datasets) { final String datasetDef = d.trim(); Thread thread = new Thread() { @Override public void run() { importData(datasetDef, forceReload); } }; thread.setDaemon(true); thread.start(); } } else if (mode == DataServiceMode.THREADED) { Thread thread = new Thread() { @Override public void run() { for (String d : datasets) { importData(d.trim(), forceReload); } } }; thread.setDaemon(true); thread.start(); } else { for (String d : datasets) { importData(d.trim(), forceReload); } } }
From source file:com.splunk.shuttl.archiver.bucketsize.BucketSizeIO.java
private List<String> getLinesFromInputStream(InputStream inputStream) { try {//from w ww. j a va2 s . c o m return IOUtils.readLines(inputStream); } catch (IOException e) { throw new RuntimeException(e); // TODO: Test this, so it's documented that // this is expected // behaviour. } }
From source file:com.khs.test.jdbc.datasource.DSInitializer.java
private void doExecuteScript(final Resource scriptResource) { if (scriptResource == null || !scriptResource.exists()) return;// w w w. ja va2s . c o m TransactionTemplate transactionTemplate = new TransactionTemplate( new DataSourceTransactionManager(dataSource)); transactionTemplate.execute(new TransactionCallback() { @SuppressWarnings("unchecked") public Object doInTransaction(TransactionStatus status) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String[] scripts; try { scripts = StringUtils.delimitedListToStringArray( stripComments(IOUtils.readLines(scriptResource.getInputStream())), ";"); } catch (IOException e) { throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e); } for (int i = 0; i < scripts.length; i++) { String script = scripts[i].trim(); if (StringUtils.hasText(script)) { try { jdbcTemplate.execute(script); } catch (DataAccessException e) { if (ignoreFailedDrop && script.toLowerCase().startsWith("drop")) { logger.debug("DROP script failed (ignoring): " + script); } else { throw e; } } } } return null; } }); }
From source file:com.impala.paga.all.QueryBanks.java
/** * /*from www .j a v a 2 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 remiturlss = ""; 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+"; // These represent parameters received over the network String 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); referenceNumber = root.getAsJsonObject().get("referenceNumber").getAsString(); remiturlss = root.getAsJsonObject().get("remiturlss").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="",destinationBankUUID="", destinationBankAccountNumber= "", recipientPhoneNumber = "" , credentials = "";*/ // check for the presence of all required parameters if (StringUtils.isBlank(referenceNumber)) { 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 + 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(); /*{ referenceNumber": "", "amount": "", "currency": "", "destinationBankUUID": "","destinationBankAccountNumber": "", "recipientPhoneNumber": ""} */ toPaga.put("referenceNumber", referenceNumber); //toVitesse.put("source","IMPALAPAY"); 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 roots = new JsonParser().parse(responseobject); //exctract a specific json element from the object(status_code) //exctract a specific json element from the object(status_code) int switchresponse = roots.getAsJsonObject().get("responseCode").getAsInt(); expected.put("am_referenceid", ""); expected.put("am_timestamp", ""); expected.put("status_code", switchresponse + ""); expected.put("banks", responseobject.toString()); ; String jsonResult = g.toJson(expected); return jsonResult; }
From source file:com.xpn.xwiki.internal.merge.MergeUtils.java
/** * @param str the multilines text/*from ww w . j a v a2s.c o m*/ * @return the lines */ private static List<String> toLines(String str) { try { return IOUtils.readLines(new StringReader(str)); } catch (IOException e) { // Should never happen return null; } }
From source file:au.org.ala.bhl.WordLists.java
private static HashSet<String> loadWordList(String resourcePath) { HashSet<String> set = new HashSet<String>(); InputStream is = TaxonGrab.class.getResourceAsStream(resourcePath); try {//from ww w .j a v a2 s .c o m @SuppressWarnings("unchecked") List<String> lines = IOUtils.readLines(is); for (String line : lines) { StringBuilder word = new StringBuilder(); StringBuilder wordAlt = new StringBuilder(); for (int i = 0; i < line.length(); ++i) { char ch = line.charAt(i); char chAlt = substitute(ch); if (Character.isLetter(chAlt)) { wordAlt.append(chAlt); if (chAlt > 127) { System.err.println(String.format("Non ascii letter: %s", ch)); } } if (Character.isLetter(ch)) { word.append(ch); } } set.add(word.toString().toLowerCase()); if (!wordAlt.toString().equals(word.toString())) { set.add(wordAlt.toString()); } } } catch (IOException e) { e.printStackTrace(); } return set; }
From source file:gobblin.data.management.copy.recovery.RecoveryHelperTest.java
@Test public void testPersistFile() throws Exception { String content = "contents"; File stagingDir = Files.createTempDir(); stagingDir.deleteOnExit();/*from ww w. j a v a 2 s .c o m*/ File file = new File(stagingDir, "file"); OutputStream os = new FileOutputStream(file); IOUtils.write(content, os); os.close(); Assert.assertEquals(stagingDir.listFiles().length, 1); State state = new State(); state.setProp(RecoveryHelper.PERSIST_DIR_KEY, this.tmpDir.getAbsolutePath()); state.setProp(ConfigurationKeys.DATA_PUBLISHER_FINAL_DIR, "/publisher"); File recoveryDir = new File(RecoveryHelper.getPersistDir(state).get().toUri().getPath()); FileSystem fs = FileSystem.getLocal(new Configuration()); CopyableFile copyableFile = CopyableFile.builder(fs, new FileStatus(0, false, 0, 0, 0, new Path("/file")), new Path("/dataset"), CopyConfiguration.builder(fs, state.getProperties()) .preserve(PreserveAttributes.fromMnemonicString("")).build()) .build(); CopySource.setWorkUnitGuid(state, Guid.fromHasGuid(copyableFile)); RecoveryHelper recoveryHelper = new RecoveryHelper(FileSystem.getLocal(new Configuration()), state); recoveryHelper.persistFile(state, copyableFile, new Path(file.getAbsolutePath())); Assert.assertEquals(stagingDir.listFiles().length, 0); Assert.assertEquals(recoveryDir.listFiles().length, 1); File fileInRecovery = recoveryDir.listFiles()[0]; Assert.assertEquals(IOUtils.readLines(new FileInputStream(fileInRecovery)).get(0), content); Optional<FileStatus> fileToRecover = recoveryHelper.findPersistedFile(state, copyableFile, Predicates.<FileStatus>alwaysTrue()); Assert.assertTrue(fileToRecover.isPresent()); Assert.assertEquals(fileToRecover.get().getPath().toUri().getPath(), fileInRecovery.getAbsolutePath()); fileToRecover = recoveryHelper.findPersistedFile(state, copyableFile, Predicates.<FileStatus>alwaysFalse()); Assert.assertFalse(fileToRecover.isPresent()); }
From source file:com.impala.paga.all.BankRouteRemit1.java
/** * //from w ww.ja 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/depositToBank"; String hashkey = "372e9b1c62ef47db83c566cf2db033cb4e1b847e12ec435997971ebd7ab8121cbd8458176374480eae7d4cb55f722f4ab328207b461f423a85a9bbad8850ce66"; String principal = "02A10715-0E53-4A8C-982E-2B7BFC7CF550"; String credentials = "QE3@u=jd*2b+"; // These represent parameters received over the network String referenceNumber = "", amount = "", currency = "", destinationBankUUID = "", destinationBankAccountNumber = "", recipientPhoneNumber = ""; // 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(); currency = root.getAsJsonObject().get("currency").getAsString(); destinationBankAccountNumber = root.getAsJsonObject().get("destinationBankAccountNumber").getAsString(); destinationBankUUID = root.getAsJsonObject().get("destinationBankUUID").getAsString(); recipientPhoneNumber = root.getAsJsonObject().get("recipientPhoneNumber").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="",destinationBankUUID="", destinationBankAccountNumber= "", recipientPhoneNumber = "" , credentials = "";*/ // check for the presence of all required parameters if (StringUtils.isBlank(referenceNumber) || StringUtils.isBlank(amount) || StringUtils.isBlank(currency) || StringUtils.isBlank(destinationBankUUID) || StringUtils.isBlank(destinationBankAccountNumber) || StringUtils.isBlank(recipientPhoneNumber)) { 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 + destinationBankUUID + destinationBankAccountNumber + 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(); Double intamount = Double.parseDouble(amount); /*{ referenceNumber": "", "amount": "", "currency": "", "destinationBankUUID": "","destinationBankAccountNumber": "", "recipientPhoneNumber": ""} */ toPaga.put("referenceNumber", referenceNumber); toPaga.put("amount", amount); toPaga.put("currency", currency); toPaga.put("destinationBankUUID", destinationBankUUID); toPaga.put("destinationBankAccountNumber", destinationBankAccountNumber); toPaga.put("recipientPhoneNumber", recipientPhoneNumber); //toVitesse.put("source","IMPALAPAY"); 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); //exctract a specific json element from the object(status_code) String statusdescription = roots.getAsJsonObject().get("message").getAsString(); //add String success = "S001"; if (responseCode == 0) { 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", responseCode + ""); expected.put("status_code", "00029"); expected.put("status_description", statusdescription); String jsonResult = g.toJson(expected); return jsonResult; }
From source file:com.impala.paga.all.QueryMobileOperators.java
/** * /* ww 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 = ""; Properties prop = new Properties(); String hashkey = prop.getProperty("hashkey"); String principal = prop.getProperty("principal"); String credentials = prop.getProperty("credentials"); String remiturlss = ""; // String hashkey ="372e9b1c62ef47db83c566cf2db033cb4e1b847e12ec435997971ebd7ab8121cbd8458176374480eae7d4cb55f722f4ab328207b461f423a85a9bbad8850ce66"; // String principal="02A10715-0E53-4A8C-982E-2B7BFC7CF550"; // String credentials ="QE3@u=jd*2b+"; // These represent parameters received over the network String 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); remiturlss = root.getAsJsonObject().get("remiturlss").getAsString(); referenceNumber = root.getAsJsonObject().get("referenceNumber").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="",destinationBankUUID="", destinationBankAccountNumber= "", recipientPhoneNumber = "" , credentials = "";*/ // check for the presence of all required parameters if (StringUtils.isBlank(referenceNumber)) { 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 + 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(); /*{ referenceNumber": "", "amount": "", "currency": "", "destinationBankUUID": "","destinationBankAccountNumber": "", "recipientPhoneNumber": ""} */ toPaga.put("referenceNumber", referenceNumber); //toVitesse.put("source","IMPALAPAY"); 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 roots = new JsonParser().parse(responseobject); //exctract a specific json element from the object(status_code) int switchresponse = roots.getAsJsonObject().get("responseCode").getAsInt(); //exctract a specific json element from the object(status_code) String statusdescription = roots.getAsJsonObject().get("message").getAsString(); expected.put("am_referenceid", ""); expected.put("am_timestamp", ""); expected.put("status_code", switchresponse + ""); expected.put("status_description", statusdescription); String jsonResult = g.toJson(expected); return jsonResult; }
From source file:io.fabric8.support.impl.SupportServiceImpl.java
@Override public String getVersion() { if (version != null) { return version; }// w w w . j a v a 2s . com String candidate = ""; String strFile = System.getProperty("karaf.base") + "/fabric/import/fabric/profiles/default.profile/io.fabric8.version.properties".replaceAll("/", System.getProperty("file.separator")); List<String> strings = null; try { strings = IOUtils.readLines(new FileReader(strFile)); } catch (IOException e) { LOGGER.warn("Unable to determine Fuse version. Cannot read file [{}]", strFile); } for (String str : strings) { if (str.startsWith("fuse")) { candidate = str; break; } } if (candidate.contains("=")) { String[] arr = candidate.split("="); if (arr.length > 1) { candidate = arr[1]; Pattern p = Pattern.compile("\\s*([0-9.]+).*"); Matcher m = p.matcher(candidate); if (m.matches()) { candidate = m.group(1); if (candidate.endsWith(".")) { candidate = candidate.substring(0, candidate.length() - 1); } } } } version = candidate; return version; }