Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
kb:apache_nifi [2018/05/06 13:25] – [Create Processor] yehudakb:apache_nifi [2018/05/06 13:57] – [Create Processor] yehuda
Line 67: Line 67:
                  
     pass     pass
 +</code>
 +
 +<code python>
 +from org.apache.commons.io import IOUtils
 +from java.nio.charset import StandardCharsets
 +from org.apache.nifi.processor.io import StreamCallback
 +
 +class PyStreamCallback(InputStreamCallback):
 +    def __init__(self):
 +        pass
 +    
 +    def process(self, inputStream):
 +        text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
 +        # outputStream.write(bytearray('Hello World!'[::-1].encode('utf-8')))
 +        #     outputStream.write(bytearray('Hello World!'.encode('utf-8')))
 +        
 +    def getItems(self):
 +        return [{"a":"b"}]
 +
 +
 +class PyOutputStreamCallback(OutputStreamCallback):
 +  def __init__(self):
 +        pass
 +  def process(self, outputStream):
 +    outputStream.write(bytearray('Hello World!'.encode('utf-8')))
 +    
 +flowFile = session.get() 
 +if (flowFile != None):
 +    try:
 +        
 +        isCB = PyInputStreamCallback()
 +        session.read(flowFile, isCB)
 +        
 +        for itm in isCB.getItems():
 +            itm_ff = session.create(flowFile)
 +            
 +            outCB = PyOutputStreamCallback()
 +            outCB.setItem(itm)
 +            
 +            itm_ff = session.write(itm_ff, outCB)
 +            session.transfer(itm_ff, REL_SUCCESS)
 +        
 +    except:
 +        session.transfer(flowFile, REL_FAILURE)
 </code> </code>
kb/apache_nifi.txt · Last modified: 2022/01/03 16:03 by 127.0.0.1
Back to top
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0