GeezerVison is showing docs.oracle.com — ResourceBundle.Control (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
compact1, compact2, compact3
java.util
Class ResourceBundle.Control
-
-
Field Summary
Fields
| Modifier and Type |
Field |
Description |
static List<String> |
FORMAT_CLASS |
The class-only format List containing
"java.class".
|
static List<String> |
FORMAT_DEFAULT |
The default format List, which contains the strings
"java.class" and "java.properties", in
this order.
|
static List<String> |
FORMAT_PROPERTIES |
The properties-only format List containing
"java.properties".
|
static long |
TTL_DONT_CACHE |
The time-to-live constant for not caching loaded resource bundle
instances.
|
static long |
TTL_NO_EXPIRATION_CONTROL |
The time-to-live constant for disabling the expiration control
for loaded resource bundle instances in the cache.
|
-
Constructor Summary
Constructors
| Modifier |
Constructor |
Description |
protected |
Control() |
Sole constructor.
|
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods
| Modifier and Type |
Method |
Description |
List<Locale> |
getCandidateLocales(String baseName,
Locale locale) |
Returns a List of Locales as candidate
locales for baseName and locale.
|
static ResourceBundle.Control |
getControl(List<String> formats) |
Returns a ResourceBundle.Control in which the getFormats method returns the specified
formats.
|
Locale |
getFallbackLocale(String baseName,
Locale locale) |
Returns a Locale to be used as a fallback locale for
further resource bundle searches by the
ResourceBundle.getBundle factory method.
|
List<String> |
getFormats(String baseName) |
Returns a List of Strings containing
formats to be used to load resource bundles for the given
baseName.
|
static ResourceBundle.Control |
getNoFallbackControl(List<String> formats) |
Returns a ResourceBundle.Control in which the getFormats method returns the specified
formats and the getFallbackLocale
method returns null.
|
long |
getTimeToLive(String baseName,
Locale locale) |
Returns the time-to-live (TTL) value for resource bundles that
are loaded under this
ResourceBundle.Control.
|
boolean |
needsReload(String baseName,
Locale locale,
String format,
ClassLoader loader,
ResourceBundle bundle,
long loadTime) |
Determines if the expired bundle in the cache needs
to be reloaded based on the loading time given by
loadTime or some other criteria.
|
ResourceBundle |
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.
|
String |
toBundleName(String baseName,
Locale locale) |
Converts the given baseName and locale
to the bundle name.
|
String |
toResourceName(String bundleName,
String suffix) |
Converts the given bundleName to the form required
by the ClassLoader.getResource
method by replacing all occurrences of '.' in
bundleName with '/' and appending a
'.' and the given file suffix.
|
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
newBundle
public ResourceBundle newBundle(String baseName,
Locale locale,
String format,
ClassLoader loader,
boolean reload)
throws IllegalAccessException,
InstantiationException,
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 returns 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.
The default implementation instantiates a
ResourceBundle as follows.
- The bundle name is obtained by calling
toBundleName(baseName,
locale).
- If
format is "java.class", the
Class specified by the bundle name is loaded by calling
ClassLoader.loadClass(String). Then, a
ResourceBundle is instantiated by calling Class.newInstance(). Note that the reload flag is
ignored for loading class-based resource bundles in this default
implementation.
- If
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.
Otherwise, loader.getResourceAsStream is called to get an InputStream. Then, a PropertyResourceBundle is constructed with the
InputStream.
- If
format is neither "java.class"
nor "java.properties", an
IllegalArgumentException is thrown.
- Parameters:
baseName - the base bundle name of the resource bundle, a fully
qualified class name
locale - the locale for which the resource bundle should be
instantiated
format - the resource bundle format to be loaded
loader - the ClassLoader to use to load the bundle
reload - 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 - if bundleName, locale,
format, or loader is
null, or if null is returned by
toBundleName
IllegalArgumentException - if format is unknown, or if the resource
found for the given parameters contains malformed data.
ClassCastException - if the loaded class cannot be cast to ResourceBundle
IllegalAccessException - if the class or its nullary constructor is not
accessible.
InstantiationException - if the instantiation of a class fails for some other
reason.
ExceptionInInitializerError - if the initialization provoked by this method fails.
SecurityException - If a security manager is present and creation of new
instances is denied. See Class.newInstance()
for details.
IOException - if an error occurred when reading resources using
any I/O operations
-
needsReload
public boolean needsReload(String baseName,
Locale locale,
String format,
ClassLoader loader,
ResourceBundle bundle,
long loadTime)
Determines if the expired bundle in the cache needs
to be reloaded based on the loading time given by
loadTime or some other criteria. The method returns
true if reloading is required; false
otherwise. loadTime is a millisecond offset since
the Calendar
Epoch.
The calling ResourceBundle.getBundle factory method
calls this method on the ResourceBundle.Control
instance used for its current invocation, not on the instance
used in the invocation that originally loaded the resource
bundle.
The default implementation compares loadTime and
the last modified time of the source data of the resource
bundle. If it's determined that the source data has been modified
since loadTime, true is
returned. Otherwise, false is returned. This
implementation assumes that the given format is the
same string as its file suffix if it's not one of the default
formats, "java.class" or
"java.properties".
- Parameters:
baseName - the base bundle name of the resource bundle, a
fully qualified class name
locale - the locale for which the resource bundle
should be instantiated
format - the resource bundle format to be loaded
loader - the ClassLoader to use to load the bundle
bundle - the resource bundle instance that has been expired
in the cache
loadTime - the time when bundle was loaded and put
in the cache
- Returns:
true if the expired bundle needs to be
reloaded; false otherwise.
- Throws:
NullPointerException - if baseName, locale,
format, loader, or
bundle is null
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|