ClassLoader's getResourceAsStream is caching the InputStream object

Karthik Guru

Ranch Hand

Posts: 1209

posted 15 years ago

hi all, am using tomcat4.0 I have a utility class which checks whether the xml stylesheets have changed and reloads it if that is the case. This is a utility class and hence does not have access to the ServletContext. so instead i use the ClassLoader which loads this class and call getResourceAsStream method on it. I have a second servlet which triggers the update method on this utility class(which reads the stream back) The utility class is a singleton. So all the servlets share the same instance of the utility class. I tried printing the content of the changed xsl stylesheet files and still i find that the content as read from the InputStream has not changed. I dont know where it has cached the earlier stylesheet file I checked the work directories and still not able to figure out how the eariler xsl got cached. I do NOT use the browser to render my xml file. It is generated on the server. I would appreciate any kind of help.

Karthik Guru

Ranch Hand

Posts: 1209

posted 15 years ago

The commented part of the code is'nt working as expected. I mean using getResourceAsStream() method was'nt reflecting the changes to the file it was reading. It was repeatedly getting me the eariler version of the file (when the tomcat engine starts) But then i used getResource() which returns a URL and then openStream() returns an Inputstream and that seemed to work just fine.(it was picking up the changes)