[ 
https://issues.apache.org/jira/browse/NIFI-7016?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Dmitry Lukyanov updated NIFI-7016:
----------------------------------
    Description: 
Currently the following methods implemented but they differ from groovy flavor.
All those methods should return the object returned by Closure and 
streams/readers/writers must be closed after closure finished.
Check any of this methods in groovy:
http://docs.groovy-lang.org/latest/html/groovy-jdk/java/io/File.html#withOutputStream(groovy.lang.Closure)

The idea of usage like this:
{code:java}
def jsonData = flowFile.withReader("UTF-8"){ new JsonSlurper().parse(it) }
{code}

methods to be fixed according to groovy behavior:

{code:java}
Object withInputStream(Closure closure)
// Creates a new InputStream for this file and passes it into the closure.
// Input stream must be closed after closure finished
// Returns value returned by closure

Object  withOutputStream(Closure closure)
// Creates a new OutputStream for this file and passes it into the closure. 
// OutputStream must be closed after closure finished. 
// Returns value returned by closure 

Object  withReader(String charset, Closure closure)
// Creates a new BufferedReader for this file using the specified charset and 
then passes it into the closure, ensuring the reader is closed after the 
closure returns. 
// Returns value returned by closure 

Object  withWriter(String charset, Closure closure)
// Creates a new BufferedWriter for this file, passes it to the closure, and 
ensures the stream is flushed and closed after the closure returns. 
// Returns value returned by closure 
{code}


  was:
Currently the following methods implemented but they differ from groovy flavor.
All those methods should return the object returned by Closure and 
streams/readers/writers must be closed after closure finished.
Check of this kind of methods - they all returns the value returned by closure.

The idea of usage like this:
{code:java}
def jsonData = flowFile.withReader("UTF-8"){ new JsonSlurper().parse(it) }
{code}

methods to be fixed according to groovy behavior:

{code:java}
Object withInputStream(Closure closure)
// Creates a new InputStream for this file and passes it into the closure.
// Input stream must be closed after closure finished
// Returns value returned by closure

Object  withOutputStream(Closure closure)
// Creates a new OutputStream for this file and passes it into the closure. 
// OutputStream must be closed after closure finished. 
// Returns value returned by closure 

Object  withReader(String charset, Closure closure)
// Creates a new BufferedReader for this file using the specified charset and 
then passes it into the closure, ensuring the reader is closed after the 
closure returns. 
// Returns value returned by closure 

Object  withWriter(String charset, Closure closure)
// Creates a new BufferedWriter for this file, passes it to the closure, and 
ensures the stream is flushed and closed after the closure returns. 
// Returns value returned by closure 
{code}



> Make groovy File functions available for FlowFile to simplify scripting 
> [modified]
> ----------------------------------------------------------------------------------
>
>                 Key: NIFI-7016
>                 URL: https://issues.apache.org/jira/browse/NIFI-7016
>             Project: Apache NiFi
>          Issue Type: New Feature
>            Reporter: Dmitry Lukyanov
>            Assignee: Matt Burgess
>            Priority: Minor
>             Fix For: 1.10.0
>
>
> Currently the following methods implemented but they differ from groovy 
> flavor.
> All those methods should return the object returned by Closure and 
> streams/readers/writers must be closed after closure finished.
> Check any of this methods in groovy:
> http://docs.groovy-lang.org/latest/html/groovy-jdk/java/io/File.html#withOutputStream(groovy.lang.Closure)
> The idea of usage like this:
> {code:java}
> def jsonData = flowFile.withReader("UTF-8"){ new JsonSlurper().parse(it) }
> {code}
> methods to be fixed according to groovy behavior:
> {code:java}
> Object withInputStream(Closure closure)
> // Creates a new InputStream for this file and passes it into the closure.
> // Input stream must be closed after closure finished
> // Returns value returned by closure
> Object        withOutputStream(Closure closure)
> // Creates a new OutputStream for this file and passes it into the closure. 
> // OutputStream must be closed after closure finished. 
> // Returns value returned by closure 
> Object        withReader(String charset, Closure closure)
> // Creates a new BufferedReader for this file using the specified charset and 
> then passes it into the closure, ensuring the reader is closed after the 
> closure returns. 
> // Returns value returned by closure 
> Object        withWriter(String charset, Closure closure)
> // Creates a new BufferedWriter for this file, passes it to the closure, and 
> ensures the stream is flushed and closed after the closure returns. 
> // Returns value returned by closure 
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to