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:org.apache.storm.smoketest.AbstractWordCount.java
private List<String> getWordCount() throws Exception { List<String> words = IOUtils.readLines(getClass().getClassLoader().getResourceAsStream("words.txt")); Map<String, Long> wordCountMap = Maps.newHashMap(); for (String word : words) { Long count = wordCountMap.get(word); if (count == null) { count = 0l;//from ww w .j a va 2 s. co m } wordCountMap.put(word, count + 1); } List<String> wordCounts = Lists.newArrayList(); for (Map.Entry<String, Long> entry : wordCountMap.entrySet()) { wordCounts.add(entry.getKey() + "," + entry.getValue()); } return wordCounts; }
From source file:org.apache.storm.spout.FileBasedBatchSpout.java
@Override public void open(Map conf, TopologyContext context) { InputStream is = getClass().getClassLoader().getResourceAsStream(filePath); index = 0;//from w w w .j a v a 2 s . co m try { this.lines = IOUtils.readLines(is); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.apache.storm.verify.VerifyUtils.java
public static void verifyHdfs(String hdfsUrl, String dir, List<String> expectedLines) throws Exception { List<String> lines = new ArrayList<String>(); FileSystem fileSystem = FileSystem.get(new URI(hdfsUrl), new Configuration()); Path path = new Path(dir); assert fileSystem.exists(path); assert fileSystem.isDirectory(path); FileStatus[] fileStatuses = fileSystem.listStatus(path); assert fileStatuses != null; for (FileStatus fileStatus : fileStatuses) { Path filePath = fileStatus.getPath(); InputStreamReader is = new InputStreamReader(fileSystem.open(filePath)); lines.addAll(IOUtils.readLines(is)); }/*from www . j a va 2s . c o m*/ Collections.sort(lines); Collections.sort(expectedLines); assert lines.equals(expectedLines) : "expectedLines = " + expectedLines + " actualines = " + lines; }
From source file:org.apache.streams.facebook.test.FacebookActivityActorSerDeTest.java
@Test public void Tests() throws Exception { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.TRUE); mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); InputStream is = FacebookActivityActorSerDeTest.class.getResourceAsStream("/testpage.json"); Joiner joiner = Joiner.on(" ").skipNulls(); is = new BoundedInputStream(is, 10000); String json;//from w w w . j ava2 s . co m json = joiner.join(IOUtils.readLines(is)); LOGGER.debug(json); Page page = mapper.readValue(json, Page.class); Activity activity = serializer.deserialize(page); LOGGER.debug(mapper.writeValueAsString(activity)); }
From source file:org.apache.streams.facebook.test.FacebookActivitySerDeTest.java
@Test public void Tests() { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.TRUE); mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); InputStream is = FacebookActivitySerDeTest.class.getResourceAsStream("/testpost.json"); Joiner joiner = Joiner.on(" ").skipNulls(); is = new BoundedInputStream(is, 10000); String json;/* w w w . j av a2s. c o m*/ try { json = joiner.join(IOUtils.readLines(is)); LOGGER.debug(json); Post post = mapper.readValue(json, Post.class); Activity activity = serializer.deserialize(post); LOGGER.debug(mapper.writeValueAsString(activity)); } catch (Exception e) { System.out.println(e); e.printStackTrace(); Assert.fail(); } }