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.WindowsPreferencesand 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 longHKEY_CURRENT_USERRegistry entries subordinate to this key define the preferences of the current user.private static java.lang.StringHKEY_EQstatic longHKEY_LOCAL_MACHINERegistry 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 intKEY_READprivate static java.lang.reflect.MethodREG_CLOSE_KEYWrapper for Windows registry API RegCloseKey(long) Returnsintprivate static java.lang.reflect.MethodREG_ENUM_KEY_EXWrapper for RegEnumKeyEx(long, int, int) Returnsbyte[]private static java.lang.reflect.MethodREG_ENUM_VALUEWrapper for Windows registry API RegEnumValue(long, int, int) Returnsbyte[]private static java.lang.reflect.MethodREG_OPEN_KEYWrapper for Windows registry API RegOpenKey(long, byte[], int) Returnslong[]private static java.lang.reflect.MethodREG_QUERY_INFO_KEYWrapper for RegQueryInfoKey(long) Returnslong[]private static java.lang.reflect.MethodREG_QUERY_VALUE_EXWrapper for Windows registry API RegQueryValueEx(long, byte[]) Returnsbyte[]private static longREG_SUCCESSprivate static java.util.prefs.PreferencesSYSTEM_ROOTprivate static java.lang.Class<? extends java.util.prefs.Preferences>USER_CLASSprivate static java.util.prefs.PreferencesUSER_ROOT
-
Constructor Summary
Constructors Modifier Constructor Description privateWinRegistry()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.reflect.MethodgetDeclaredMethod(java.lang.String name, java.lang.Class<?>... parameterTypes)private static longgetNumber(java.lang.Object array, int index)static java.lang.StringreadString(long hkey, java.lang.String key, java.lang.String valueName)Read a value from key and value nameprivate static java.lang.StringreadString(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.IllegalAccessExceptionjava.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.IllegalAccessExceptionjava.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.IllegalAccessExceptionjava.lang.reflect.InvocationTargetException
-
toCstr
private static byte[] toCstr(java.lang.String str)
-
-