-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathread_update_content.py
30 lines (25 loc) · 1.09 KB
/
read_update_content.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
###############################################################################
# Write content to an outgoing flow file using a callback
# modified from "https://community.hortonworks.com/articles/75545/executescript-cookbook-part-2.html"
#
# This script will read and overwirte content. In this example,
# the input content will not be used for output.
#
# output:
# !dlroW olleH
###############################################################################
from org.apache.commons.io import IOUtils
from java.nio.charset import StandardCharsets
from org.apache.nifi.processor.io import StreamCallback
# Define a subclass of StreamCallback for use in session.write()
class PyStreamCallback(StreamCallback):
def __init__(self):
pass
def process(self, inputStream, outputStream):
text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
outputStream.write(bytearray('Hello World!'[::-1].encode('utf-8')))
# end class
flowFile = session.get()
if(flowFile != None):
flowFile = session.write(flowFile, PyStreamCallback())
session.transfer(flowFile, REL_SUCCESS)