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:ita.parthenope.twitternlp.semantic.CloudOfWords.java
static private List<String> getWordNames() throws IOException { return IOUtils.readLines(getInputStream(getInputFile())); }
From source file:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java
@Test public void testCreateAndRunScriptWithFakeKeplerThatSucceedsWithNoEmailSet() throws Exception { assumeTrue(SystemUtils.IS_OS_UNIX);//from w w w. j a v a 2s . c o m File baseDirectory = Folder.newFolder(); File tempDirectory = new File(baseDirectory + File.separator + "subdir"); File outputsDir = new File(tempDirectory + File.separator + Constants.OUTPUTS_DIR_NAME); assertTrue(outputsDir.mkdirs()); JobEmailNotificationData emailNotifyData = createJobEmailNotificationData(); File stderrFile = new File(outputsDir.getAbsolutePath() + File.separator + "stderr"); assertTrue(stderrFile.createNewFile()); JobBinaries jb = new JobBinaries(); jb.setKeplerScript(getAndCheckForTrueBinaryFile().getAbsolutePath()); jb.setRegisterUpdateJar("register.jar"); jb.setJavaCommand("/bin/echo"); jb.setRetryCount(1); JobCmdScriptCreatorImpl scriptCreator = new JobCmdScriptCreatorImpl("/workflowsdir", jb, emailNotifyData); Job j = new Job(); Workflow w = new Workflow(); w.setId(new Long(5)); j.setWorkflow(w); String jobCmd = scriptCreator.create(tempDirectory.getAbsolutePath(), j, new Long(2345)); assertTrue(jobCmd != null); assertTrue( jobCmd.equals(outputsDir.getAbsolutePath() + File.separator + JobCmdScriptCreatorImpl.JOB_CMD_SH)); File checkCmdFile = new File(jobCmd); assertTrue(checkCmdFile.canExecute()); RunCommandLineProcessImpl rclpi = new RunCommandLineProcessImpl(); rclpi.setWorkingDirectory(tempDirectory.getAbsolutePath()); String result = rclpi.runCommandLineProcess(jobCmd); String logFile = baseDirectory.getAbsoluteFile() + File.separator + "job...log"; File checkLogFile = new File(logFile); assertTrue(logFile + " and we ran " + jobCmd, checkLogFile.exists()); List<String> lines = IOUtils.readLines(new FileReader(logFile)); for (String line : lines) { if (line.startsWith("exitcode: ")) { assertTrue(line, line.equals("exitcode: 0")); } } String updateFile = tempDirectory.getAbsoluteFile() + File.separator + "updateworkspacefile.out"; lines = IOUtils.readLines(new FileReader(updateFile)); for (String line : lines) { if (line.startsWith("-jar")) { assertTrue(line, line.startsWith( "-jar register.jar --updatepath 2345 --path " + outputsDir.getAbsolutePath() + " --size ")); assertTrue(line, line.endsWith(" --workspacefilefailed false")); } } }
From source file:com.streamsets.pipeline.kafka.common.SdcKafkaTestUtil.java
public List<KeyedMessage<String, String>> produceXmlMessages(String topic, String partition) throws IOException { List<String> stringList = IOUtils .readLines(KafkaTestUtil.class.getClassLoader().getResourceAsStream("testKafkaTarget.xml")); StringBuilder sb = new StringBuilder(); for (String s : stringList) { sb.append(s);// w w w . j a va2 s. c om } String xmlString = sb.toString(); List<KeyedMessage<String, String>> messages = new ArrayList<>(); for (int i = 0; i < 10; i++) { messages.add(new KeyedMessage<>(topic, partition, xmlString)); } return messages; }
From source file:com.headwire.aem.tooling.intellij.communication.ImportRepositoryContentManager.java
private void parseIgnoreFiles(IFolder folder, String path) throws IOException, CoreException { // TODO - the parsing should be extracted IResource vltIgnore = folder.findMember(".vltignore"); if (vltIgnore != null && vltIgnore instanceof IFile) { logger.trace("Found ignore file at {0}", vltIgnore.getFullPath()); InputStream contents = ((IFile) vltIgnore).getContents(); try {/*from w ww . j a va 2 s.com*/ List<String> ignoreLines = IOUtils.readLines(contents); for (String ignoreLine : ignoreLines) { logger.trace("Registering ignore rule {0}:{1}", path, ignoreLine); ignoredResources.registerRegExpIgnoreRule(path, ignoreLine); } } finally { IOUtils.closeQuietly(contents); } } }
From source file:com.github.wakhub.monodict.activity.FlashcardActivity.java
@Background void importCardsFrom(String jsonPath) { activityHelper.showProgressDialog(R.string.message_in_processing); String json;/* ww w .j av a2 s . c o m*/ try { FileInputStream inputStream = new FileInputStream(jsonPath); json = TextUtils.join("", IOUtils.readLines(inputStream)); } catch (FileNotFoundException e) { activityHelper.showError(e); activityHelper.hideProgressDialog(); return; } catch (IOException e) { activityHelper.showError(e); activityHelper.hideProgressDialog(); return; } JsonArray cards; try { JsonElement jsonElement = new JsonParser().parse(json); JsonObject object = jsonElement.getAsJsonObject(); cards = object.getAsJsonArray(JSON_KEY_CARDS); } catch (JsonIOException e) { activityHelper.showError(e); activityHelper.hideProgressDialog(); return; } for (JsonElement element : cards) { JsonObject cardData = element.getAsJsonObject(); Card card = new Card(cardData); try { databaseHelper.createCard(card); } catch (SQLException e) { activityHelper.showError(e); activityHelper.hideProgressDialog(); return; } } activityHelper.hideProgressDialog(); activityHelper.showToast(R.string.message_success); loadContents(); }
From source file:com.splunk.shuttl.archiver.filesystem.HadoopFileSystemArchiveTest.java
public void openFile_existingFileOnHadoop_inputStreamToFile() throws FileNotFoundException, IOException { File fileWithRandomContent = createFileWithRandomContent(); List<String> expectedContent = IOUtils.readLines(new FileInputStream(fileWithRandomContent)); hadoopFileSystemPutter.putFile(fileWithRandomContent); Path pathToFile = hadoopFileSystemPutter.getPathForFile(fileWithRandomContent); InputStream openFile = hadoopFileSystemArchive.openFile(pathToFile.toUri()); List<String> actualContent = IOUtils.readLines(openFile); assertEquals(expectedContent, actualContent); }
From source file:bmsi.util.UnaryPredicate.java
/** * Read a text file into an array of String. This provides basic diff * functionality. A more advanced diff utility will use specialized objects * to represent the text lines, with options to, for example, convert * sequences of whitespace to a single space for comparison purposes. *//* w w w. j ava 2s .co m*/ static String[] slurp(String file) throws IOException { InputStream in = new FileInputStream(file); try { @SuppressWarnings("unchecked") List<String> lines = IOUtils.readLines(in); return lines.toArray(new String[lines.size()]); } finally { IOUtils.closeQuietly(in); } }
From source file:com.streamsets.pipeline.kafka.common.KafkaTestUtil.java
public static List<KeyedMessage<String, String>> produceXmlMessages(String topic, String partition) throws IOException { List<String> stringList = IOUtils .readLines(KafkaTestUtil.class.getClassLoader().getResourceAsStream("testKafkaTarget.xml")); StringBuilder sb = new StringBuilder(); for (String s : stringList) { sb.append(s);//from ww w. j a v a 2 s .c o m } String xmlString = sb.toString(); List<KeyedMessage<String, String>> messages = new ArrayList<>(); for (int i = 0; i < 10; i++) { messages.add(new KeyedMessage<>(topic, partition, xmlString)); } return messages; }
From source file:com.doculibre.constellio.services.AutocompleteServicesImpl.java
private static List<String> getBlacklist() { List<String> blacklist = new ArrayList<String>(); try {//w w w.j a va2s .c om byte[] blackListConfig = SolrServicesImpl.readPlainConfigInCloud("autocomplete-blacklist.txt"); if (blackListConfig != null && blackListConfig.length > 0) { blacklist.addAll(IOUtils.readLines(new ByteArrayInputStream(blackListConfig))); Collections.sort(blacklist); } } catch (Exception e) { throw new RuntimeException(e); } return blacklist; }
From source file:manchester.synbiochem.datacapture.SeekConnector.java
private String getAuthToken() throws IOException { HttpURLConnection c = connect("/data_files/new"); c.connect();//from w w w . j a v a 2s. co m // We're parsing HTML with regexps! Watch out, Tony the Pony! Pattern p = compile("<meta\\s+content=\"(.+?)\"\\s+name=\"csrf-token\"\\s*/>"); try (InputStream is = c.getInputStream()) { for (String s : IOUtils.readLines(is)) { Matcher m = p.matcher(s); if (m.find()) return m.group(1); } } throw new IOException("no authenticity token found"); }