Package org.ka2ddo.util
Class UTF8ResourceControl
java.lang.Object
java.util.ResourceBundle.Control
org.ka2ddo.util.UTF8ResourceControl
This Control loads PropertyResourceBundles using a UTF-8 locale Reader to
read the properties file.
- Author:
- Andrew Pavlin, KA2DDO
-
Field Summary
Fields inherited from class java.util.ResourceBundle.Control
FORMAT_CLASS, FORMAT_DEFAULT, FORMAT_PROPERTIES, TTL_DONT_CACHE, TTL_NO_EXPIRATION_CONTROL
-
Method Summary
Modifier and TypeMethodDescriptiongetFormats
(String baseName) Returns aList
ofString
s containing formats to be used to load resource bundles for the givenbaseName
.newBundle
(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) Instantiates a resource bundle for the given bundle name of the given format and locale, using the given class loader if necessary.Methods inherited from class java.util.ResourceBundle.Control
getCandidateLocales, getControl, getFallbackLocale, getNoFallbackControl, getTimeToLive, needsReload, toBundleName, toResourceName
-
Field Details
-
INSTANCE
-
-
Method Details
-
getFormats
Returns aList
ofString
s containing formats to be used to load resource bundles for the givenbaseName
. TheResourceBundle.getBundle
factory method tries to load resource bundles with formats in the order specified by the list. The list returned by this method must have at least oneString
. The predefined formats are"java.class"
for class-based resource bundles and"java.properties"
for properties-based ones. Strings starting with"java."
are reserved for future extensions and must not be used by application-defined formats.- Overrides:
getFormats
in classResourceBundle.Control
- Parameters:
baseName
- the base name of the resource bundle, a fully qualified class name- Returns:
- a
List
ofString
s containing formats for loading resource bundles. - Throws:
NullPointerException
- ifbaseName
is null- See Also:
-
newBundle
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IOException Instantiates a resource bundle for the given bundle name of the given format and locale, using the given class loader if necessary. This method returnsnull
if there is no resource bundle available for the given parameters. If a resource bundle can't be instantiated due to an unexpected error, the error must be reported by throwing anError
orException
rather than simply returningnull
.If the
reload
flag istrue
, it indicates that this method is being called because the previously loaded resource bundle has expired.This implementation instantiates a
ResourceBundle
as follows.- The bundle name is obtained by calling
toBundleName(baseName, locale)
. - If
format
is"java.properties"
,toResourceName(bundlename, "properties")
is called to get the resource name. Ifreload
istrue
,load.getResource
is called to get aURL
for creating aURLConnection
. ThisURLConnection
is used to disable the caches of the underlying resource loading layers, and to get anInputStream
which is wrapped in a InputStreamReader set up for UTF-8 encoding. Otherwise,loader.getResourceAsStream
is called to get anInputStream
which is wrapped in a InputStreamReader set up for UTF-8 encoding. Then, aPropertyResourceBundle
is constructed with theReader
. - If
format
is not"java.properties"
, anIllegalArgumentException
is thrown.
- Overrides:
newBundle
in classResourceBundle.Control
- Parameters:
baseName
- the base bundle name of the resource bundle, a fully qualified class namelocale
- the locale for which the resource bundle should be instantiatedformat
- the resource bundle format to be loadedloader
- theClassLoader
to use to load the bundlereload
- the flag to indicate bundle reloading;true
if reloading an expired resource bundle,false
otherwise- Returns:
- the resource bundle instance,
or
null
if none could be found. - Throws:
NullPointerException
- ifbundleName
,locale
,format
, orloader
isnull
, or ifnull
is returned bytoBundleName
IllegalArgumentException
- ifformat
is unknown, or if the resource found for the given parameters contains malformed data.ClassCastException
- if the loaded class cannot be cast toResourceBundle
ExceptionInInitializerError
- if the initialization provoked by this method fails.SecurityException
- If a security manager is present and creation of new instances is denied. SeeClass.newInstance()
for details.IOException
- if an error occurred when reading resources using any I/O operations
- The bundle name is obtained by calling
-