title: How to check if a Java ResourceBundle is loadable, without loading it?
body: <p>I would like to check the existence of a ResourceBundle without actually loading it.</p>
  
  <p>Typically, I'm using Guice, and at initialization time, I want to check the existence, while at execution time, I want to load it. If the bundle doesn't exist, I want an early report of the inexistence of the RB.</p>
  
  <p>If it was possible to get the ResourceBundle.Control instance used for a specific ResourceBundle, I would have no problem getting the basic information to build the actual resource name (using toBundleName() and toResourceName()), but it is not the case at that level.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Ok, I found the way to do it. I'll create a ResourceBundle.Control that is extensible (using a custome addFormat(String, Class)) to store all the bundle formats, then use another method of my own to check all possible file names for a specific locale (using Class.getResource as indicated here below).</p>
  
  <p>Coding speaking:</p>
  
  <pre><code>class MyControl extends ResourceBundle.Control {
    private Map&lt;String,Class&lt;? extends ResourceBundle&gt;&gt; formats = new LinkedHashMap();
    public void addFormat(String format,Class&lt;? extends ResourceBundle&gt; rbType) {
      formats.put(format, rbType);
    }
    public boolean resourceBundleExists(ClassLoader loader, String baseName, Locale locale) {
      for (String format: formats.keySet()) {
        // for (loop on locale hierarchy) {
          if (loader.getResource(toResourceName(toBundleName(baseName, locale), format)) != null) {
            return true;
          }
        // }
      }
      return false;
    }
  }
  </code></pre>