-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathsimple_write_content.py
25 lines (23 loc) · 989 Bytes
/
simple_write_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
###############################################################################
# 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 only write content, not read input content
#
# output:
# Hello World!
###############################################################################
from org.apache.commons.io import IOUtils
from java.nio.charset import StandardCharsets
from org.apache.nifi.processor.io import OutputStreamCallback
# Define a subclass of OutputStreamCallback for use in session.write()
class PyOutputStreamCallback(OutputStreamCallback):
def __init__(self):
pass
def process(self, outputStream):
outputStream.write(bytearray('Hello World!'.encode('utf-8')))
# end class
flowFile = session.get()
if(flowFile != None):
flowFile = session.write(flowFile, PyOutputStreamCallback())
session.transfer(flowFile, REL_SUCCESS)