public class UTF8ResourceControl
extends java.util.ResourceBundle.Control
Modifier and Type | Field and Description |
---|---|
static UTF8ResourceControl |
INSTANCE |
Modifier and Type | Method and Description |
---|---|
java.util.List<java.lang.String> |
getFormats(java.lang.String baseName)
Returns a
List of String s containing
formats to be used to load resource bundles for the given
baseName . |
java.util.ResourceBundle |
newBundle(java.lang.String baseName,
java.util.Locale locale,
java.lang.String format,
java.lang.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.
|
public static final UTF8ResourceControl INSTANCE
public java.util.List<java.lang.String> getFormats(java.lang.String baseName)
List
of String
s containing
formats to be used to load resource bundles for the given
baseName
. The ResourceBundle.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 one String
. 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.getFormats
in class java.util.ResourceBundle.Control
baseName
- the base name of the resource bundle, a fully qualified class
nameList
of String
s containing
formats for loading resource bundles.java.lang.NullPointerException
- if baseName
is nullResourceBundle.Control.FORMAT_PROPERTIES
public java.util.ResourceBundle newBundle(java.lang.String baseName, java.util.Locale locale, java.lang.String format, java.lang.ClassLoader loader, boolean reload) throws java.io.IOException
null
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 an Error
or
Exception
rather than simply returning
null
.
If the reload
flag is true
, it
indicates that this method is being called because the previously
loaded resource bundle has expired.
This implementation instantiates a
ResourceBundle
as follows.
toBundleName(baseName,
locale)
.format
is "java.properties"
,
toResourceName(bundlename,
"properties")
is called to get the resource name.
If reload
is true
, load.getResource
is called
to get a URL
for creating a URLConnection
. This URLConnection
is used to
disable the
caches of the underlying resource loading layers,
and to get an
InputStream
which is wrapped in a InputStreamReader
set up for UTF-8 encoding.
Otherwise, loader.getResourceAsStream
is called to get an InputStream
which is wrapped in a InputStreamReader
set up for UTF-8 encoding. Then, a PropertyResourceBundle
is constructed with the
Reader
.format
is not "java.properties"
, an
IllegalArgumentException
is thrown.newBundle
in class java.util.ResourceBundle.Control
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
- the ClassLoader
to use to load the bundlereload
- the flag to indicate bundle reloading; true
if reloading an expired resource bundle,
false
otherwisenull
if none could be found.java.lang.NullPointerException
- if bundleName
, locale
,
format
, or loader
is
null
, or if null
is returned by
toBundleName
java.lang.IllegalArgumentException
- if format
is unknown, or if the resource
found for the given parameters contains malformed data.java.lang.ClassCastException
- if the loaded class cannot be cast to ResourceBundle
java.lang.ExceptionInInitializerError
- if the initialization provoked by this method fails.java.lang.SecurityException
- If a security manager is present and creation of new
instances is denied. See Class.newInstance()
for details.java.io.IOException
- if an error occurred when reading resources using
any I/O operations