分享

重写InputFormat实现数据自定义格式的解析(附代码分析)

已有(6)人评论

跳转到指定楼层
问津少年 发表于 2015-3-19 21:47:52
第一个里面一直有段代码贴不进去,虽然它不是需要调用的代码,但这里还是贴上,以免以后疑惑。这段代码是对字符串式的xml进行解析,是我测试用的,可以不用管。然后整个环境是基于Hadoop2.x的,有些API有改变,请注意
  1. * @param xmlString
  2.          * @param conf
  3.          * @return conf
  4.          * @throws IOException
  5.          * @throws DocumentException
  6.          */
  7.         public static Configuration getXmlParse(String xmlString, Configuration conf)
  8.                         throws IOException, DocumentException {
  9.                 // use dom4j to parse String to xml,then parse the xml
  10.                 Document doc = DocumentHelper.parseText(xmlString);
  11.                 Element root = doc.getRootElement();
  12.                 String messageNum = "";
  13.                 String messageLength = "";
  14.                 for (Iterator j = root.elementIterator("property"); j.hasNext();) {
  15.                         Element property = (Element) j.next();
  16.                         if (property.element("name").getText().equals("messageNum")) {
  17.                                 messageNum = property.element("value").getText();
  18.                         } else {
  19.                                 messageLength = property.element("value").getText();
  20.                         }
  21.                         conf.set(messageNum, messageLength);
  22.                 }
  23.                 return conf;
  24.         }
  25. }
复制代码
回复

使用道具 举报

jixianqiuxue 发表于 2015-3-19 23:28:42
学习了,很不错
回复

使用道具 举报

wangzhenqiang 发表于 2015-5-26 15:20:57
回复

使用道具 举报

Kevin517 发表于 2016-11-12 15:23:28
楼主你好,
如果我要使用 在 HDFS上 .doc/ .pdf 的文件该如何操作呢???
回复

使用道具 举报

问津少年 发表于 2016-11-17 08:47:08
Kevin517 发表于 2016-11-12 15:23
楼主你好,
如果我要使用 在 HDFS上 .doc/ .pdf 的文件该如何操作呢???

可以使用Apache Tika
回复

使用道具 举报

Kevin517 发表于 2016-11-18 19:40:55

谢谢,找到了个相关的帖子。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条