This is probably a very basic question so please bear with me.
What is the best way to provide a .txt file to be read by a Java class in a OSGi bundle in CQ 5.5?
I have been able to read a file called "test.txt" that I put in a structure like this /src/resources/<any-sub-folder>/test.txt from my java class at /src/main/java/com/test/mytest/Test.java using the bundle's getResource and getEntry calls but I was not able to use the context.getDataFile. How is this getDataFile method call to be used?
And what if I want to read the file located in another bundle, is it possible? or can I add the file to some repository and then access it - but I am not clear how to do this.
And I would also like to know what is the best practise if I need to provide a large data set in a flat file to be read by a Java class in CQ5.
Please provide detailed steps or point me to a how to guide or other helpful resources as I am a novice.
Thank you in advance for your time and help.
As you can read in the OSGi Core specification (section 4.5.2), the getDataFile() method is to read/write a file in the bundle's private persistent area. It cannot be used to read files contained in the bundle. The issue Sham mentions refers to a version of Felix which is not used in CQ.
The methods you mentioned (getResource and getEntry) are appropriate for reading files contained in a bundle.
Reading a file from the repository is done using the JCR API. You can see a blueprint for how to do this by looking at the readFile method in http://svn.apache.org/repos/asf/jackrabbit/tags/2.4.0/jackrabbit-jcr-commons/src/main/java /org/apache/jackrabbit/commons/JcrUtils.java. Unfortunately, this method is not currently usable as it was declared incorrectly (should be a static method, but is an instance method).