Recent Updates

I have a Dell XPS 17 L702X laptop which is a Core i7 and supposed to be fast. I upgraded it to have 16 GB RAM. Still, the pain point was Disk I/O lag caused by HDD which came pre-installed. I decided to go for a swap of existing HDD with the fast Samsung 850 Evo 500 GB SSD as C: Drive and kept second HDD D: Drive the same. The results are there to see ! The below 2 screenshots before and after the upgrade tell their story. Windows Start is snappier and apps are snappier too ! Now I am pleased !

This post illustrates a way to read any file (say a properties file, XML File, XSLT File, or image file ) as an InputStream object when the file needs to exist outside of an Application Context. Say you have an application accessible via a URL http://localhost:8080/MyApp, whose context is /MyApp.

Typically, there will be a WAR file responsible for this context /MyApp (say MyApp.war). Now if you want to access a file which is outside this context, In Glassfish app server there is a docroot folder where your domain is. This docroot folder serves as alternate root for documents.

Just create a folder, say, “data” under the docroot folder of your Glassfish domain.

Place your properties, image, or XML file there, say, myFile.xml.

In your web application, this will be accessible as URL

http://localhost:8080/data/myFile.xml (you can check this direct “GET” URL in browser when web app is running)

And we have the myFile.xml as InputStream object from within the web application.
The added benefit of obtaining this file as InputStream object is that any subsequent changes to this file are dynamically picked up (on the fly) on next call which would not be same as reading a file using getResourceAsStream() which is more of static in nature and may require AppServer restart.