Reading a file from Custom Java Transformer

Support/help with CloverETL (4.9) and CloverDX (5.0 or newer) implementation problems

pareshjoshi
Posts: 7
Joined: Thu Jan 21, 2016 6:48 pm

Reading a file from Custom Java Transformer

Postby pareshjoshi » Fri Aug 19, 2016 8:37 pm

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,

imriskal
Posts: 398
Joined: Wed Aug 15, 2012 8:18 am

Re: Reading a file from Custom Java Transformer

Postby imriskal » Mon Aug 22, 2016 1:24 pm

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")
---
Lubos Imriska
CloverCARE Support
CloverDX

Visit us online at http://www.cloverdx.com

pareshjoshi
Posts: 7
Joined: Thu Jan 21, 2016 6:48 pm

Re: Reading a file from Custom Java Transformer

Postby pareshjoshi » Tue Aug 23, 2016 5:50 pm

Great thank you!