2017-10-04 117 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