Page 1 of 1

Reading a file from Custom Java Transformer

Posted: Fri Aug 19, 2016 8:37 pm
by pareshjoshi
Hi,
I want to read a JSON file that is "data-in" folder from a custom java transformer class. I can load the file using absolute path but can someone please let me know know to read the file via relative path? I am not able to figure out the context from class is being executed. Since the project will be executed on server (once I am done development) so need the ability to read from a relative path of the project.
Thanks,

Re: Reading a file from Custom Java Transformer

Posted: Mon Aug 22, 2016 1:24 pm
by imriskal
First, I recommend using CustomJavaReader instead of CustomJavaTransformer. Examples in the reader component are tailor made for various reading scenarios.

In CustomJavaReader, you can use this simple syntax:

Code: Select all

InputStream in = getInputStream("data-in/myFile.txt")

If you want to use a parameter value in the file path, this is the way:

Code: Select all

InputStream in = getInputStream(getGraph().getGraphParameters().getGraphParameter("DATAIN_DIR").getValueResolved(RefResFlag.REGULAR)+"/myFile.txt")

Re: Reading a file from Custom Java Transformer

Posted: Tue Aug 23, 2016 5:50 pm
by pareshjoshi
Great thank you!