2017-10-04 121 views
0

我想flowfile其中是XML组件和更新tagvalue之一,我做这里面的自定义nifi处理器的代码,我有这样的代码:文件未发现异常

flowFile = session.putAttribute(flowFile,"filename",file.getName() + ".xml"); 
       InputSource inputSource = new InputSource((InputStream) flowFile); 
       DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); 
       DocumentBuilder builder = builderFactory.newDocumentBuilder(); 
       Document xmlDocument = builder.parse(inputSource); 
       XPath xPath = XPathFactory.newInstance().newXPath(); 
       NodeList myNodeList = (NodeList) xPath.compile("//runAs/text()") 
         .evaluate(flowFile, XPathConstants.NODESET); 
       myNodeList.item(0).setNodeValue("false"); 

但trows文件未发现异常异常,我应该改变什么使这段代码工作ps我不能使用流文件的路径

回答

3

nifi流文件不是InputStream。

所以代码(InputStream) flowFile是错误的

,如果你想获得流量文件作为输入流的内容,你可以使用session.read方法是这样的:

InputStream ffStream = session.read(flowFile); 
...do something with stream 
ffStream.close(); 
+0

你没有在你的代码除如何从流文件中获取流。 (我在回答中提到) – daggett

+0

我不能关闭fstream后所有这些操作我的意思是:DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); Document xmlDocument = builder.parse(inputSource); XPath xPath = XPathFactory.newInstance()。newXPath(); NodeList myNodeList =(NodeList)xPath.compile(“// runAs/text()”) .evaluate(flowFile,XPathConstants.NODESET); myNodeList.item(0).setNodeValue(“false”); –

+0

你可以在流解析后关闭流:'builder.parse(inputSource)' – daggett