Class UTF8Properties

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,​java.lang.Object>

    public class UTF8Properties
    extends java.util.Properties
    Properties were by default read as ISO-8859-1 characters. However, in the last 10 years most builds use UTF-8. Since this is in general a global setting, it is very awkward to use ISO-8859-1. In general, it is not often a problem since most of Java is written with the basic ASCII encoding. However, we want to do this right. So in bnd we generally use this UTF-8 Properties class. This class always writes UTF-8. However, it will try to read UTF-8 first. If this fails, it will try ISO-8859-1, and the last attempt is the platform default.

    This class can (and probably should) be used anywhere a Properties class is used.

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.List<java.lang.ThreadLocal<java.nio.charset.CharsetDecoder>> decoders  
      private static java.util.regex.Pattern HERE_PATTERN  
      private static long serialVersionUID  
      • Fields inherited from class java.util.Properties

        defaults
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.String decode​(byte[] buffer)  
      private static java.util.Collection<java.lang.String> fromArray​(java.lang.String[] array)  
      void load​(java.io.File file, Reporter reporter)  
      void load​(java.io.File file, Reporter reporter, java.lang.String[] syntaxHeaders)  
      void load​(java.io.File file, Reporter reporter, java.util.Collection<java.lang.String> syntaxHeaders)  
      void load​(java.io.InputStream in)  
      void load​(java.io.InputStream in, java.io.File file, Reporter reporter)  
      void load​(java.io.InputStream in, java.io.File file, Reporter reporter, java.lang.String[] syntaxHeaders)  
      void load​(java.io.InputStream in, java.io.File file, Reporter reporter, java.util.Collection<java.lang.String> syntaxHeaders)  
      void load​(java.io.Reader r)  
      void load​(java.lang.String source, java.io.File file, Reporter reporter)  
      void load​(java.lang.String source, java.io.File file, Reporter reporter, java.lang.String[] syntaxHeaders)  
      void load​(java.lang.String source, java.io.File file, Reporter reporter, java.util.Collection<java.lang.String> syntaxHeaders)  
      UTF8Properties replaceAll​(java.lang.String pattern, java.lang.String replacement)
      Replace a string in all the values.
      private UTF8Properties replaceAll​(java.util.regex.Pattern regex, java.lang.String replacement)  
      UTF8Properties replaceHere​(java.io.File file)
      Replace the string "${.}" in all the values with the path of the specified file.
      void store​(java.io.File out)  
      void store​(java.io.OutputStream out)  
      void store​(java.io.OutputStream out, java.lang.String msg)  
      void store​(java.io.Writer out, java.lang.String msg)  
      • Methods inherited from class java.util.Properties

        clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, getProperty, getProperty, hashCode, isEmpty, keys, keySet, list, list, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, setProperty, size, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • decoders

        private static final java.util.List<java.lang.ThreadLocal<java.nio.charset.CharsetDecoder>> decoders
      • HERE_PATTERN

        private static final java.util.regex.Pattern HERE_PATTERN
    • Constructor Detail

      • UTF8Properties

        public UTF8Properties​(java.util.Properties p)
      • UTF8Properties

        public UTF8Properties​(java.io.File file,
                              java.lang.String[] syntaxHeaders)
                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • UTF8Properties

        public UTF8Properties​(java.io.File file)
                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • UTF8Properties

        public UTF8Properties​(java.io.File file,
                              Reporter reporter,
                              java.lang.String[] syntaxHeaders)
                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • UTF8Properties

        public UTF8Properties​(java.io.File file,
                              Reporter reporter)
                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • UTF8Properties

        public UTF8Properties()
    • Method Detail

      • fromArray

        private static java.util.Collection<java.lang.String> fromArray​(java.lang.String[] array)
      • load

        public void load​(java.io.InputStream in,
                         java.io.File file,
                         Reporter reporter,
                         java.lang.String[] syntaxHeaders)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • load

        public void load​(java.io.InputStream in,
                         java.io.File file,
                         Reporter reporter,
                         java.util.Collection<java.lang.String> syntaxHeaders)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • load

        public void load​(java.io.InputStream in,
                         java.io.File file,
                         Reporter reporter)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • load

        public void load​(java.lang.String source,
                         java.io.File file,
                         Reporter reporter)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • load

        public void load​(java.lang.String source,
                         java.io.File file,
                         Reporter reporter,
                         java.lang.String[] syntaxHeaders)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • load

        public void load​(java.lang.String source,
                         java.io.File file,
                         Reporter reporter,
                         java.util.Collection<java.lang.String> syntaxHeaders)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • load

        public void load​(java.io.File file,
                         Reporter reporter,
                         java.lang.String[] syntaxHeaders)
                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • load

        public void load​(java.io.File file,
                         Reporter reporter,
                         java.util.Collection<java.lang.String> syntaxHeaders)
                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • load

        public void load​(java.io.File file,
                         Reporter reporter)
                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • load

        public void load​(java.io.InputStream in)
                  throws java.io.IOException
        Overrides:
        load in class java.util.Properties
        Throws:
        java.io.IOException
      • load

        public void load​(java.io.Reader r)
                  throws java.io.IOException
        Overrides:
        load in class java.util.Properties
        Throws:
        java.io.IOException
      • decode

        private java.lang.String decode​(byte[] buffer)
      • store

        public void store​(java.io.OutputStream out,
                          java.lang.String msg)
                   throws java.io.IOException
        Overrides:
        store in class java.util.Properties
        Throws:
        java.io.IOException
      • store

        public void store​(java.io.Writer out,
                          java.lang.String msg)
                   throws java.io.IOException
        Overrides:
        store in class java.util.Properties
        Throws:
        java.io.IOException
      • store

        public void store​(java.io.File out)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • store

        public void store​(java.io.OutputStream out)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • replaceAll

        public UTF8Properties replaceAll​(java.lang.String pattern,
                                         java.lang.String replacement)
        Replace a string in all the values. This can be used to preassign variables that change. For example, the base directory ${.} for a loaded properties.
        Returns:
        A new UTF8Properties with the replacement.
      • replaceAll

        private UTF8Properties replaceAll​(java.util.regex.Pattern regex,
                                          java.lang.String replacement)
      • replaceHere

        public UTF8Properties replaceHere​(java.io.File file)
        Replace the string "${.}" in all the values with the path of the specified file.
        Returns:
        A new UTF8Properties with the replacement.