com.h3c.util

## Class ResourceUtils

- java.lang.Object
- - com.h3c.util.ResourceUtils

-     public final class ResourceUtils
      extends Object

  A collection of useful utilities revolving around Resource Bundle usage.

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static ResourceBundle` | `getBundledResource(Class<?> c)` This method takes a class and returns a `ResourceBundle` which is loaded from a properties file with the same base name as the class.
    `static ResourceBundle` | `getBundledResource(Class<?> c, String baseName)` This method returns a `ResourceBundle` which is loaded from a properties file with the specified base name from the same package as the specified class.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getBundledResource

          public static ResourceBundle getBundledResource(Class<?> c)

      This method takes a class and returns a `ResourceBundle` which is loaded from a properties file with the same base name as the class. Note that both the class and the properties file(s) need to be in the same jar file.

      For example, supposing the jar file contains:

           com/h3c/util/example/SomeObject.class
           com/h3c/util/example/SomeObject.properties

      Then, to correctly load the resource bundle associated with `SomeObject`, call:

           ResourceBundle res = ResourceUtils.getBundledResource(SomeObject.class);

      Note that no error is thrown if the properties file does not exist. This condition will not become apparent until you try and access a property from the bundle, at which time a `MissingResourceException` will be thrown.
      Parameters:
        `c` - the class
      Returns:
        the associated resource bundle

    - #### getBundledResource

          public static ResourceBundle getBundledResource(Class<?> c,
                                          String baseName)

      This method returns a `ResourceBundle` which is loaded from a properties file with the specified base name from the same package as the specified class. Note that both the class and the properties file(s) need to be in the same jar file.

      For example, supposing the jar file contains:

           com.h3c.nis/util/example/SomeObject.class
           com.h3c.nis/util/example/DisplayStrings.properties

      Then, to correctly load the resource bundle call:

           ResourceBundle res =
               ResourceUtils.getBundledResource(SomeObject.class, "DisplayStrings");

      Note that no error is thrown if the properties file does not exist. This condition will not become apparent until you try and access a property from the bundle, at which time a `MissingResourceException` will be thrown.
      Parameters:
        `c` - the class requesting the bundle
        `baseName` - the base name of the resource bundle
      Returns:
        the associated resource bundle

Copyright © 2014. All Rights Reserved.