Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
kb:apache_nifi [2018/05/06 13:25] – [Create Processor] yehuda | kb:apache_nifi [2018/05/06 13:57] – [Create Processor] yehuda | ||
---|---|---|---|
Line 67: | Line 67: | ||
| | ||
pass | pass | ||
+ | </ | ||
+ | |||
+ | <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, | ||
+ | text = IOUtils.toString(inputStream, | ||
+ | # outputStream.write(bytearray(' | ||
+ | # | ||
+ | | ||
+ | def getItems(self): | ||
+ | return [{" | ||
+ | |||
+ | |||
+ | class PyOutputStreamCallback(OutputStreamCallback): | ||
+ | def __init__(self): | ||
+ | pass | ||
+ | def process(self, | ||
+ | outputStream.write(bytearray(' | ||
+ | | ||
+ | flowFile = session.get() | ||
+ | if (flowFile != None): | ||
+ | try: | ||
+ | | ||
+ | isCB = PyInputStreamCallback() | ||
+ | session.read(flowFile, | ||
+ | | ||
+ | for itm in isCB.getItems(): | ||
+ | itm_ff = session.create(flowFile) | ||
+ | | ||
+ | outCB = PyOutputStreamCallback() | ||
+ | outCB.setItem(itm) | ||
+ | | ||
+ | itm_ff = session.write(itm_ff, | ||
+ | session.transfer(itm_ff, | ||
+ | | ||
+ | except: | ||
+ | session.transfer(flowFile, | ||
</ | </ |