Class Locale


  • public final class Locale
    extends Object
    This utility class permits a easier use of localized strings. Locale provides a means to retreive messages in the default language. Use this to construct messages displayed for end users.

    Locale takes a string from a properties resource, then inserts the parameter strings into the extracted strings at the appropriate places. The pattern matching is proceeded with LocaleMessageFormat formatter. Note that '' may represent a single quote in strings (see LocaleMessageFormat for details).

    Since:
    6.4
    Version:
    17.0 2020-01-04 14:41:35
    Author:
    Stéphane GALLAND, $Author: lamotte$
    Maven Group Id:
    org.arakhne.afc.core
    Maven Artifact Id:
    vmutils
    • Method Detail

      • getPriorizedDecodingCharsets

        public static Charset[] getPriorizedDecodingCharsets()
        Replies the charsets for decoding that must be used prior to the installed charsets.
        Returns:
        the priorized decoding charsets.
      • setPriorizedDecodingCharsets

        public static void setPriorizedDecodingCharsets​(Charset[] charsets)
        Change the charsets for decoding that must be used prior to the installed charsets.
        Parameters:
        charsets - the priorized decoding charsets.
      • getStringWithDefaultFrom

        @Pure
        public static String getStringWithDefaultFrom​(String resourcePath,
                                                      String key,
                                                      String defaultValue,
                                                      Object... params)
        Replies the text that corresponds to the specified resource.

        The resourcePath argument should be a fully qualified class name. However, for compatibility with earlier versions, Sun's Java SE Runtime Environments do not verify this, and so it is possible to access PropertyResourceBundles by specifying a path name (using "/") instead of a fully qualified class name (using ".").

        Parameters:
        resourcePath - is the name (path) of the resource file, a fully qualified class name
        key - is the name of the resource into the specified file
        defaultValue - is the default value to replies if the resource does not contain the specified key.
        params - is the the list of parameters which will replaces the #1, #2... into the string.
        Returns:
        the text that corresponds to the specified resource
      • getStringWithDefaultFrom

        @Pure
        public static String getStringWithDefaultFrom​(ClassLoader classLoader,
                                                      String resourcePath,
                                                      String key,
                                                      String defaultValue,
                                                      Object... params)
        Replies the text that corresponds to the specified resource.

        The resourcePath argument should be a fully qualified class name. However, for compatibility with earlier versions, Sun's Java SE Runtime Environments do not verify this, and so it is possible to access PropertyResourceBundles by specifying a path name (using "/") instead of a fully qualified class name (using ".").

        Parameters:
        classLoader - is the class loader to use, a fully qualified class name
        resourcePath - is the name (path) of the resource file
        key - is the name of the resource into the specified file
        defaultValue - is the default value to replies if the resource does not contain the specified key.
        params - is the the list of parameters which will replaces the #1, #2... into the string.
        Returns:
        the text that corresponds to the specified resource
      • getStringFrom

        @Pure
        public static String getStringFrom​(String resourcePath,
                                           String key,
                                           Object... params)
        Replies the text that corresponds to the specified resource.

        The resourcePath argument should be a fully qualified class name. However, for compatibility with earlier versions, Sun's Java SE Runtime Environments do not verify this, and so it is possible to access PropertyResourceBundles by specifying a path name (using "/") instead of a fully qualified class name (using ".").

        Parameters:
        resourcePath - is the name (path) of the resource file, a fully qualified class name
        key - is the name of the resource into the specified file
        params - is the the list of parameters which will replaces the #1, #2... into the string.
        Returns:
        the text that corresponds to the specified resource
      • getStringFrom

        @Pure
        public static String getStringFrom​(ClassLoader classLoader,
                                           String resourcePath,
                                           String key,
                                           Object... params)
        Replies the text that corresponds to the specified resource.

        The resourcePath argument should be a fully qualified class name. However, for compatibility with earlier versions, Sun's Java SE Runtime Environments do not verify this, and so it is possible to access PropertyResourceBundles by specifying a path name (using "/") instead of a fully qualified class name (using ".").

        Parameters:
        classLoader - is the classLoader to use.
        resourcePath - is the name (path) of the resource file, a fully qualified class name
        key - is the name of the resource into the specified file
        params - is the the list of parameters which will replaces the #1, #2... into the string.
        Returns:
        the text that corresponds to the specified resource
      • getString

        @Pure
        public static String getString​(Class<?> resource,
                                       String key,
                                       Object... params)
        Replies the text that corresponds to the specified resource.
        Parameters:
        resource - is the name of the resource file
        key - is the name of the resource into the specified file
        params - is the the list of parameters which will replaces the #1, #2... into the string.
        Returns:
        the text that corresponds to the specified resource
      • getString

        @Pure
        public static String getString​(ClassLoader classLoader,
                                       Class<?> resource,
                                       String key,
                                       Object... params)
        Replies the text that corresponds to the specified resource.
        Parameters:
        classLoader - is the class loader to use.
        resource - is the name of the resource file
        key - is the name of the resource into the specified file
        params - is the the list of parameters which will replaces the #1, #2... into the string.
        Returns:
        the text that corresponds to the specified resource
      • getString

        public static String getString​(String key,
                                       Object... params)
        Replies the text that corresponds to the specified resource.

        This function assumes the classname of the caller as the resource provider.

        Parameters:
        key - is the name of the resource into the specified file
        params - is the the list of parameters which will replaces the #1, #2... into the string.
        Returns:
        the text that corresponds to the specified resource
      • getString

        @Pure
        public static String getString​(ClassLoader classLoader,
                                       String key,
                                       Object... params)
        Replies the text that corresponds to the specified resource.

        This function assumes the classname of the caller as the resource provider.

        Parameters:
        classLoader - is the classLoader to use.
        key - is the name of the resource into the specified file
        params - is the the list of parameters which will replaces the #1, #2... into the string.
        Returns:
        the text that corresponds to the specified resource
      • getStringWithDefault

        @Pure
        public static String getStringWithDefault​(Class<?> resource,
                                                  String key,
                                                  String defaultValue,
                                                  Object... params)
        Replies the text that corresponds to the specified resource.
        Parameters:
        resource - is the name of the resource file
        key - is the name of the resource into the specified file
        defaultValue - is the default value to replies if the resource does not contain the specified key.
        params - is the the list of parameters which will replaces the #1, #2... into the string.
        Returns:
        the text that corresponds to the specified resource
      • getStringWithDefault

        @Pure
        public static String getStringWithDefault​(ClassLoader classLoader,
                                                  Class<?> resource,
                                                  String key,
                                                  String defaultValue,
                                                  Object... params)
        Replies the text that corresponds to the specified resource.
        Parameters:
        classLoader - is the class loader to use.
        resource - is the name of the resource file
        key - is the name of the resource into the specified file
        defaultValue - is the default value to replies if the resource does not contain the specified key.
        params - is the the list of parameters which will replaces the #1, #2... into the string.
        Returns:
        the text that corresponds to the specified resource
      • getStringWithDefault

        @Pure
        public static String getStringWithDefault​(String key,
                                                  String defaultValue,
                                                  Object... params)
        Replies the text that corresponds to the specified resource.
        Parameters:
        key - is the name of the resource into the specified file
        defaultValue - is the default value to replies if the resource does not contain the specified key.
        params - is the the list of parameters which will replaces the #1, #2... into the string.
        Returns:
        the text that corresponds to the specified resource
      • getStringWithDefault

        @Pure
        public static String getStringWithDefault​(ClassLoader classLoader,
                                                  String key,
                                                  String defaultValue,
                                                  Object... params)
        Replies the text that corresponds to the specified resource.
        Parameters:
        classLoader - is the class loader to use.
        key - is the name of the resource into the specified file
        defaultValue - is the default value to replies if the resource does not contain the specified key.
        params - is the the list of parameters which will replaces the #1, #2... into the string.
        Returns:
        the text that corresponds to the specified resource
      • decodeString

        @Pure
        public static String decodeString​(byte[] bytes)
        Decode the specified array of bytes according to a charset selection. This function tries to decode a string from the given byte array with the following charsets (in preferred order):

        The IBM437 charset was added to support several specific files (Dbase files) generated from a GIS.

        Parameters:
        bytes - is the array of bytes to decode.
        Returns:
        the decoded string with the appropriate charset set.
      • decodeString

        public static String decodeString​(InputStream stream)
                                   throws IOException
        Decode the bytes from the specified input stream according to a charset selection. This function tries to decode a string from the given byte array with the following charsets (in preferred order):

        The IBM437 charset was added to support several specific files (Dbase files) generated from a GIS.

        Parameters:
        stream - is the stream to decode.
        Returns:
        the decoded string with the appropriate charset set.
        Throws:
        IOException - when the stream cannot be read.
      • decodeString

        public static boolean decodeString​(InputStream stream,
                                           List<String> lineArray)
                                    throws IOException
        Decode the bytes from the specified input stream according to a charset selection. This function tries to decode a string from the given byte array with the following charsets (in preferred order):

        The IBM437 charset was added to support several specific files (Dbase files) generated from a GIS.

        This function read the input stream line by line.

        Parameters:
        stream - is the stream to decode.
        lineArray - is the array of lines to fill
        Returns:
        true is the decoding was successful, otherwhise false
        Throws:
        IOException - when the stream cannot be read.