Class UTF8Properties
- All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>
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:
-
Field Summary
Fields inherited from class Properties
defaults -
Constructor Summary
ConstructorsConstructorDescriptionUTF8Properties(File file) UTF8Properties(File file, Reporter reporter) UTF8Properties(File file, Reporter reporter, String[] syntaxHeaders) UTF8Properties(File file, String[] syntaxHeaders) -
Method Summary
Modifier and TypeMethodDescriptiongetProvenance(String key) Get the provenance of the given key if setvoidvoidvoidload(File file, Reporter reporter, Collection<String> syntaxHeaders) voidload(InputStream in) voidload(InputStream in, File file, Reporter reporter) voidload(InputStream in, File file, Reporter reporter, String[] syntaxHeaders) voidload(InputStream in, File file, Reporter reporter, Collection<String> syntaxHeaders) voidvoidvoidvoidvoidload(String source, File file, Reporter reporter, Collection<String> syntaxHeaders, String provenance) voidload(Properties properties, boolean overwriteIfPresent) Load the properties from a properties.voidreplaceAll(String pattern, String replacement) Replace a string in all the values.replaceHere(File file) Replace the string "${.}" in all the values with the path of the specified file.setProperty(String key, String value, String provenance) voidsetProvenance(String provenance) Set the provenance on all current keyssetProvenance(String key, String provenance) Set the provenance of the given keyvoidvoidstore(OutputStream out) voidstore(OutputStream out, String msg) voidMethods inherited from class 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, putIfAbsent, rehash, remove, replace, replace, replaceAll, save, setProperty, size, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
Constructor Details
-
UTF8Properties
-
UTF8Properties
-
UTF8Properties
-
UTF8Properties
-
UTF8Properties
-
UTF8Properties
public UTF8Properties()
-
-
Method Details
-
load
public void load(InputStream in, File file, Reporter reporter, String[] syntaxHeaders) throws IOException - Throws:
IOException
-
load
public void load(InputStream in, File file, Reporter reporter, Collection<String> syntaxHeaders) throws IOException - Throws:
IOException
-
load
- Throws:
IOException
-
load
- Throws:
IOException
-
load
public void load(String source, File file, Reporter reporter, String[] syntaxHeaders) throws IOException - Throws:
IOException
-
load
public void load(String source, File file, Reporter reporter, Collection<String> syntaxHeaders) throws IOException - Throws:
IOException
-
load
public void load(String source, File file, Reporter reporter, Collection<String> syntaxHeaders, String provenance) throws IOException - Throws:
IOException
-
load
-
load
-
load
-
load
- Overrides:
loadin classProperties- Throws:
IOException
-
load
- Overrides:
loadin classProperties- Throws:
IOException
-
store
- Overrides:
storein classProperties- Throws:
IOException
-
store
- Overrides:
storein classProperties- Throws:
IOException
-
store
- Throws:
IOException
-
store
- Throws:
IOException
-
replaceAll
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.
-
replaceHere
Replace the string "${.}" in all the values with the path of the specified file.- Returns:
- A new UTF8Properties with the replacement.
-
setProperty
-
remove
-
getProvenance
-
setProvenance
Set the provenance of the given key- Parameters:
key- the keyprovenance- the provenance, maybe null to remove
-
load
Load the properties from a properties. If the properties is a UTF8Properties, we also copy the provenance.- Parameters:
properties- the propertiesoverwriteIfPresent- overwrite an exissting value in this properties
-
putAll
-
setProvenance
Set the provenance on all current keys- Parameters:
provenance-
-