Package org.openstreetmap.josm.tools
Class WinRegistry
- java.lang.Object
-
- org.openstreetmap.josm.tools.WinRegistry
-
public final class WinRegistry extends java.lang.Object
Utility class to access Window registry (read access only). As the implementation relies on internal JDK classjava.util.prefs.WindowsPreferences
and its native JNI methodJava_java_util_prefs_WindowsPreferences_WindowsRegQueryValueEx
, only String values (REG_SZ) are supported. Adapted from StackOverflow.- Since:
- 12217
-
-
Field Summary
Fields Modifier and Type Field Description static long
HKEY_CURRENT_USER
Registry entries subordinate to this key define the preferences of the current user.private static java.lang.String
HKEY_EQ
static long
HKEY_LOCAL_MACHINE
Registry entries subordinate to this key define the physical state of the computer, including data about the bus type, system memory, and installed hardware and software.private static int
KEY_READ
private static java.lang.reflect.Method
REG_CLOSE_KEY
Wrapper for Windows registry API RegCloseKey(long) Returnsint
private static java.lang.reflect.Method
REG_ENUM_KEY_EX
Wrapper for RegEnumKeyEx(long, int, int) Returnsbyte[]
private static java.lang.reflect.Method
REG_ENUM_VALUE
Wrapper for Windows registry API RegEnumValue(long, int, int) Returnsbyte[]
private static java.lang.reflect.Method
REG_OPEN_KEY
Wrapper for Windows registry API RegOpenKey(long, byte[], int) Returnslong[]
private static java.lang.reflect.Method
REG_QUERY_INFO_KEY
Wrapper for RegQueryInfoKey(long) Returnslong[]
private static java.lang.reflect.Method
REG_QUERY_VALUE_EX
Wrapper for Windows registry API RegQueryValueEx(long, byte[]) Returnsbyte[]
private static long
REG_SUCCESS
private static java.util.prefs.Preferences
SYSTEM_ROOT
private static java.lang.Class<? extends java.util.prefs.Preferences>
USER_CLASS
private static java.util.prefs.Preferences
USER_ROOT
-
Constructor Summary
Constructors Modifier Constructor Description private
WinRegistry()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.reflect.Method
getDeclaredMethod(java.lang.String name, java.lang.Class<?>... parameterTypes)
private static long
getNumber(java.lang.Object array, int index)
static java.lang.String
readString(long hkey, java.lang.String key, java.lang.String valueName)
Read a value from key and value nameprivate static java.lang.String
readString(java.util.prefs.Preferences root, long hkey, java.lang.String key, java.lang.String value)
static java.util.List<java.lang.String>
readStringSubKeys(long hkey, java.lang.String key)
Read the value name(s) from a given keyprivate static java.util.List<java.lang.String>
readStringSubKeys(java.util.prefs.Preferences root, long hkey, java.lang.String key)
static java.util.Map<java.lang.String,java.lang.String>
readStringValues(long hkey, java.lang.String key)
Read value(s) and value name(s) form given keyprivate static java.util.Map<java.lang.String,java.lang.String>
readStringValues(java.util.prefs.Preferences root, long hkey, java.lang.String key)
private static byte[]
toCstr(java.lang.String str)
-
-
-
Field Detail
-
HKEY_CURRENT_USER
public static final long HKEY_CURRENT_USER
Registry entries subordinate to this key define the preferences of the current user. These preferences include the settings of environment variables, data about program groups, colors, printers, network connections, and application preferences. See Predefined Keys- See Also:
- Constant Field Values
-
HKEY_LOCAL_MACHINE
public static final long HKEY_LOCAL_MACHINE
Registry entries subordinate to this key define the physical state of the computer, including data about the bus type, system memory, and installed hardware and software. It contains subkeys that hold current configuration data, including Plug and Play information (the Enum branch, which includes a complete list of all hardware that has ever been on the system), network logon preferences, network security information, software-related information (such as server names and the location of the server), and other system information. See Predefined Keys- See Also:
- Constant Field Values
-
REG_SUCCESS
private static final long REG_SUCCESS
- See Also:
- Constant Field Values
-
KEY_READ
private static final int KEY_READ
- See Also:
- Constant Field Values
-
USER_ROOT
private static final java.util.prefs.Preferences USER_ROOT
-
SYSTEM_ROOT
private static final java.util.prefs.Preferences SYSTEM_ROOT
-
USER_CLASS
private static final java.lang.Class<? extends java.util.prefs.Preferences> USER_CLASS
-
HKEY_EQ
private static final java.lang.String HKEY_EQ
- See Also:
- Constant Field Values
-
REG_OPEN_KEY
private static final java.lang.reflect.Method REG_OPEN_KEY
Wrapper for Windows registry API RegOpenKey(long, byte[], int) Returnslong[]
-
REG_CLOSE_KEY
private static final java.lang.reflect.Method REG_CLOSE_KEY
Wrapper for Windows registry API RegCloseKey(long) Returnsint
-
REG_QUERY_VALUE_EX
private static final java.lang.reflect.Method REG_QUERY_VALUE_EX
Wrapper for Windows registry API RegQueryValueEx(long, byte[]) Returnsbyte[]
-
REG_ENUM_VALUE
private static final java.lang.reflect.Method REG_ENUM_VALUE
Wrapper for Windows registry API RegEnumValue(long, int, int) Returnsbyte[]
-
REG_QUERY_INFO_KEY
private static final java.lang.reflect.Method REG_QUERY_INFO_KEY
Wrapper for RegQueryInfoKey(long) Returnslong[]
-
REG_ENUM_KEY_EX
private static final java.lang.reflect.Method REG_ENUM_KEY_EX
Wrapper for RegEnumKeyEx(long, int, int) Returnsbyte[]
-
-
Constructor Detail
-
WinRegistry
private WinRegistry()
-
-
Method Detail
-
getDeclaredMethod
private static java.lang.reflect.Method getDeclaredMethod(java.lang.String name, java.lang.Class<?>... parameterTypes)
-
readString
public static java.lang.String readString(long hkey, java.lang.String key, java.lang.String valueName) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Read a value from key and value name- Parameters:
hkey
- HKEY_CURRENT_USER/HKEY_LOCAL_MACHINEkey
- key namevalueName
- value name- Returns:
- the value
- Throws:
java.lang.IllegalArgumentException
- if hkey not HKEY_CURRENT_USER/HKEY_LOCAL_MACHINEjava.lang.IllegalAccessException
- if Java language access control is enforced and the underlying method is inaccessiblejava.lang.reflect.InvocationTargetException
- if the underlying method throws an exception- Since:
- 19100 (method definition)
-
readStringValues
public static java.util.Map<java.lang.String,java.lang.String> readStringValues(long hkey, java.lang.String key) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Read value(s) and value name(s) form given key- Parameters:
hkey
- HKEY_CURRENT_USER/HKEY_LOCAL_MACHINEkey
- key name- Returns:
- the value name(s) plus the value(s)
- Throws:
java.lang.IllegalArgumentException
- if hkey not HKEY_CURRENT_USER/HKEY_LOCAL_MACHINEjava.lang.IllegalAccessException
- if Java language access control is enforced and the underlying method is inaccessiblejava.lang.reflect.InvocationTargetException
- if the underlying method throws an exception
-
readStringSubKeys
public static java.util.List<java.lang.String> readStringSubKeys(long hkey, java.lang.String key) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Read the value name(s) from a given key- Parameters:
hkey
- HKEY_CURRENT_USER/HKEY_LOCAL_MACHINEkey
- key name- Returns:
- the value name(s)
- Throws:
java.lang.IllegalArgumentException
- if hkey not HKEY_CURRENT_USER/HKEY_LOCAL_MACHINEjava.lang.IllegalAccessException
- if Java language access control is enforced and the underlying method is inaccessiblejava.lang.reflect.InvocationTargetException
- if the underlying method throws an exception
-
getNumber
private static long getNumber(java.lang.Object array, int index)
-
readString
private static java.lang.String readString(java.util.prefs.Preferences root, long hkey, java.lang.String key, java.lang.String value) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
- Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
readStringValues
private static java.util.Map<java.lang.String,java.lang.String> readStringValues(java.util.prefs.Preferences root, long hkey, java.lang.String key) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
- Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
readStringSubKeys
private static java.util.List<java.lang.String> readStringSubKeys(java.util.prefs.Preferences root, long hkey, java.lang.String key) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
- Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
toCstr
private static byte[] toCstr(java.lang.String str)
-
-