Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

Nifi + Groovy + Apache POI for excel in outputStream

avatar
Reader

Hi everybody,

i'm new to Nifi, and i try to understand how the in/out streams works in groovy.

 

I've created one processor to generate flowfile, one to run a groovy script and a third one to putfile.

 

I've tried many many things but for now my groovy script (not working) look like this:

 

 

 

 

import org.apache.poi.ss.usermodel.*
import org.apache.poi.hssf.usermodel.*
import org.apache.poi.xssf.usermodel.*
import org.apache.poi.ss.util.*
import org.apache.poi.ss.usermodel.*
import org.apache.poi.hssf.extractor.*
import java.nio.charset.*
import java.io.*

def flowFile = session.get()

if(!flowFile) return

flowFile = session.write(flowFile, {inputStream, outputStream ->
    try {

FileOutputStream out = new FileOutputStream("workbook.xls");
outputStream.write(out);
out.close();
//is not working.

// def record = "toto"
// outputStream.write(record.getBytes(StandardCharsets.UTF_8))
//is working and giving me a txt file with toto in it.

    } catch(e) {
     log.error("Error during processing", e)
     session.transfer(flowFile, REL_FAILURE)
    }
} as StreamCallback)

session.transfer(flowFile, REL_SUCCESS)

 

 

 

 
the error i get is : 
errors2.png
It says to me that the ProcessSession.write(FlowFile) has not been closed.
 
When i do outpustream.write of a string, it works, but with a excel file it doesn't work
At this point i really don't know what i'm missing.
 
My modules are well imported and class path had been setup.
 
I looked all over the internet but there is no ressource about writing an excel file in the output stream of nifi.
I 'm open to any other way to treat this problem.
Thanks!
1 REPLY 1

avatar
Contributor

Hi @ollie_  did you find a solution ?