• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getClass().getResourceAsStream()

 
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to validate xsd file. This file includes few other xsds. So for validating the root xsd I need all the other 4 xsds that are imported or included in it. I am using LSResourceResolver to get all these schema files (Xsds). But my issue is If I use FileInputStream like below
The code works for one module. But I get FileNotFound error if I run other classes that use this code.


Hence I wanted to use getClass().resourceAsStream(""); But with this method I can just load a file.Is there a way to load the entire folder where all my xsds are visible?

thanks
Trupti
 
Ranch Hand
Posts: 270
15
Android Angular Framework Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have not worked with XML/XSD for some time. That being said, I think the key might be your resolver. It may be you could substitute in a custom resource resolver, that can ensure those files are found when they are needed. That's probably what I would do, were I to try solving this. I hope that helps.
 
Ranch Hand
Posts: 171
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at this code

https://github.com/vermaanuragmaxima/wscreator/blob/adf0b5bab5f0a7768d4fd80ce72718c0aa36e1d5/src/main/java/com/maximaconsulting/webservices/WebServicesScanner.java

it searches for Types having a particular annotation. You can use the same way to find your resources.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're using code which returns an InputStream, then think about it... is it possible for an InputStream to read from a folder?

Clearly not. But there's a getResource() method which returns a URL. So you could perhaps get a URL which points to a folder, except that getResource() looks for a resource, which translates to some kind of a file. So that won't work either.

Why don't you just include a resource which is an ordinary text file containing a list of the XSDs you want to read? Then you could read each of those as a resource.
 
L Foster
Ranch Hand
Posts: 270
15
Android Angular Framework Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah! I'm catching up with you now. I think what you've said is that you ARE implementing the custom resolver. And your implementation is not quite where you would like it to be.

If you implement your interface, you can hand your implementation a mapping file of some kind (as part of its configuration), rather like @Paul has suggested. There is even a well known concept for this. That would get you everything, but you would need to define your resource strings just so, and if you added things later, you would need to change that file.

The concept is "catalog". Xerces defines it in this URL https://xerces.apache.org/xerces2-j/faq-xcatalogs.html . Sorry, I have not done this for a while.

Other hints that could help, are "getResource()" returning a URL. I think the URL returned will be a "file:" URL. Then, if you must open a file, you may be able to get the URL and parse the true file location out of that. It might be, for example, everything after protocol://.

Good luck.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic