Class RegistryKey.Handle
- All Implemented Interfaces:
AutoCloseable
- Enclosing class:
RegistryKey
RegistryKey itself. However, it reuses the same link to the
Windows registry instead of creating a new one every time. That makes it more efficient if multiple operations on the same registry key are
needed. Handle instances should be closed when they are no longer needed to release the link to the Windows registry.
Note that the way the handle is created may limit the available operations. For instance, if RegistryKey.HandleOption.MANAGE_VALUES isn't given,
trying to set or delete registry values will lead to RegistryAccessDeniedExceptions.
- Author:
- Rob Spoor
-
Method Summary
Modifier and TypeMethodDescriptionReturns attributes for the registry key from which this handle was retrieved.abstract voidclose()Closes this registry handle.voiddeleteValue(String name) Deletes a registry value.booleandeleteValueIfExists(String name) Deletes a registry value if it exists.findDWordValue(String name) Tries to return a registry value as a DWORD.findQWordValue(String name) Tries to return a registry value as a QWORD.findStringValue(String name) Tries to return a registry value as a string.<V extends RegistryValue>
Optional<V> Tries to return a registry value.intgetDWordValue(String name) Returns a registry value as a DWORD.longgetQWordValue(String name) Returns a registry value as a QWORD.getStringValue(String name) Returns a registry value as a string.<V extends RegistryValue>
VReturns a registry value.Returns the instant when the registry key from which this handle was retrieved was last written to.voidsetValue(SettableRegistryValue value) Sets a registry value.subKeys()Returns all direct sub keys of the registry key from which this handle was retrieved.values()Returns all values of the registry key from which this handle was retrieved.values(RegistryValue.Filter filter) Returns all values of the registry key from which this handle was retrieved.
-
Method Details
-
lastWriteTime
Returns the instant when the registry key from which this handle was retrieved was last written to.- Returns:
- The instant when the registry key from which this handle was retrieved was last written to.
- Since:
- 1.1
-
attributes
Returns attributes for the registry key from which this handle was retrieved.- Returns:
- Attributes for the registry key from which this handle was retrieved.
- Since:
- 1.1
-
subKeys
Returns all direct sub keys of the registry key from which this handle was retrieved. This stream is valid until this handle is closed, and does not need to be closed afterwards.Note that nothing can be said about the order of sub keys in the stream. It's also unspecified what happens if sub keys are removed while consuming the stream.
- Returns:
- A stream with all direct sub keys of the registry key from which this handle was retrieved.
- Throws:
InvalidRegistryHandleException- If this handle is no longer valid.NoSuchRegistryKeyException- If the registry key from which this handle was retrieved no longerexists.RegistryException- If the sub keys cannot be queried for another reason.
-
values
Returns all values of the registry key from which this handle was retrieved. This stream is valid until this handle is closed, and does not need to be closed afterwards.Note that nothing can be said about the order of values in the stream. It's also unspecified what happens if values are removed while consuming the stream.
- Returns:
- A stream with all values of the registry key from which this handle was retrieved.
- Throws:
InvalidRegistryHandleException- If this handle is no longer valid.NoSuchRegistryKeyException- If the registry key from which this handle was retrieved no longerexists.RegistryException- If the values cannot be queried for another reason.
-
values
Returns all values of the registry key from which this handle was retrieved. This stream is valid until this handle is closed, and does not need to be closed afterwards.While filtering can be done on a stream returned by
values(), this method allows limited filtering before any objects are even created for registry values. This offers a small performance gain.Note that nothing can be said about the order of values in the stream. It's also unspecified what happens if values are removed while consuming the stream.
- Parameters:
filter- A filter that can be used to limit which registry values are returned.- Returns:
- A stream with all values of the registry key from which this handle was retrieved.
- Throws:
InvalidRegistryHandleException- If this handle is no longer valid.NoSuchRegistryKeyException- If the registry key from which this handle was retrieved no longerexists.RegistryException- If the values cannot be queried for another reason.
-
getValue
Returns a registry value.- Type Parameters:
V- The type of registry value to return.- Parameters:
name- The name of the registry value to return.valueType- The type of registry value to return.- Returns:
- The registry value with the given name.
- Throws:
NullPointerException- If the given name or value type isnull.InvalidRegistryHandleException- If this handle is no longer valid.NoSuchRegistryKeyException- If the registry key from which this handle was retrieved no longerexists.NoSuchRegistryValueException- If there is no such registry value.RegistryException- If the value cannot be returned for another reason.ClassCastException- If the registry value with the given name cannot be cast to the given value type.
-
findValue
Tries to return a registry value.- Type Parameters:
V- The type of registry value to return.- Parameters:
name- The name of the registry value to return.valueType- The type of registry value to return.- Returns:
- An
Optionalwith the registry value with the given name, orOptional.empty()if there is no such registry value. - Throws:
NullPointerException- If the given name or value type isnull.InvalidRegistryHandleException- If this handle is no longer valid.NoSuchRegistryKeyException- If the registry key from which this handle was retrieved no longerexists.RegistryException- If the value cannot be returned for another reason.ClassCastException- If the registry value with the given name cannot be cast to the given value type.
-
getStringValue
Returns a registry value as a string. This method is shorthand for callinggetValue(name, StringValue.class).value().- Parameters:
name- The name of the registry value to return.- Returns:
- The registry value with the given name as a string.
- Throws:
NullPointerException- If the given name isnull.InvalidRegistryHandleException- If this handle is no longer valid.NoSuchRegistryKeyException- If this registry key does notexist.NoSuchRegistryValueException- If there is no such registry value.RegistryException- If the value cannot be returned for another reason.ClassCastException- If the registry value with the given name is not a string.- See Also:
-
findStringValue
Tries to return a registry value as a string. This method is shorthand for callinggetValue(name, StringValue.class).map(StringValue::value).- Parameters:
name- The name of the registry value to return.- Returns:
- An
Optionalwith the registry value with the given name as a string, orOptional.empty()if there is no such registry value. - Throws:
NullPointerException- If the given name isnull.InvalidRegistryHandleException- If this handle is no longer valid.NoSuchRegistryKeyException- If this registry key does notexist.RegistryException- If the value cannot be returned for another reason.ClassCastException- If the registry value with the given name is not a string.- See Also:
-
getDWordValue
Returns a registry value as a DWORD. This method is shorthand for callinggetValue(name, DWordValue.class).value().- Parameters:
name- The name of the registry value to return.- Returns:
- The registry value with the given name as a DWORD.
- Throws:
NullPointerException- If the given name isnull.InvalidRegistryHandleException- If this handle is no longer valid.NoSuchRegistryKeyException- If this registry key does notexist.NoSuchRegistryValueException- If there is no such registry value.RegistryException- If the value cannot be returned for another reason.ClassCastException- If the registry value with the given name is not a DWORD.- See Also:
-
findDWordValue
Tries to return a registry value as a DWORD. This method is shorthand for callingfindValue(name, DWordValue.class).mapToInt(DWordValue::value), ifOptionalhad a methodmapToInt.- Parameters:
name- The name of the registry value to return.- Returns:
- An
Optionalwith the registry value with the given name as a DWORD, orOptional.empty()if there is no such registry value. - Throws:
NullPointerException- If the given name isnull.InvalidRegistryHandleException- If this handle is no longer valid.NoSuchRegistryKeyException- If this registry key does notexist.RegistryException- If the value cannot be returned for another reason.ClassCastException- If the registry value with the given name is not a DWORD.- See Also:
-
getQWordValue
Returns a registry value as a QWORD. This method is shorthand for callinggetValue(name, QWordValue.class).value().- Parameters:
name- The name of the registry value to return.- Returns:
- The registry value with the given name as a QWORD.
- Throws:
NullPointerException- If the given name isnull.InvalidRegistryHandleException- If this handle is no longer valid.NoSuchRegistryKeyException- If this registry key does notexist.NoSuchRegistryValueException- If there is no such registry value.RegistryException- If the value cannot be returned for another reason.ClassCastException- If the registry value with the given name is not a QWORD.- See Also:
-
findQWordValue
Tries to return a registry value as a QWORD. This method is shorthand for callingfindValue(name, QWordValue.class).mapToLong(QWordValue::value), ifOptionalhad a methodmapToLong.- Parameters:
name- The name of the registry value to return.- Returns:
- An
Optionalwith the registry value with the given name as a QWORD, orOptional.empty()if there is no such registry value. - Throws:
NullPointerException- If the given name isnull.InvalidRegistryHandleException- If this handle is no longer valid.NoSuchRegistryKeyException- If this registry key does notexist.RegistryException- If the value cannot be returned for another reason.ClassCastException- If the registry value with the given name is not a QWORD.- See Also:
-
setValue
Sets a registry value.- Parameters:
value- The registry value to set.- Throws:
NullPointerException- If the given registry value isnull.InvalidRegistryHandleException- If this handle is no longer valid.NoSuchRegistryKeyException- If the registry key from which this handle was retrieved no longerexists.RegistryException- If the value cannot be set for another reason.
-
deleteValue
Deletes a registry value.- Parameters:
name- The name of the registry value to exist.- Throws:
NullPointerException- If the given name isnull.InvalidRegistryHandleException- If this handle is no longer valid.NoSuchRegistryKeyException- If the registry key from which this handle was retrieved no longerexists.NoSuchRegistryValueException- If the registry value does not exist.RegistryException- If the value cannot be deleted for another reason.
-
deleteValueIfExists
Deletes a registry value if it exists.- Parameters:
name- The name of the registry value to exist.- Returns:
trueif the registry value existed and was deleted, orfalseif it didn't exist.- Throws:
NullPointerException- If the given name isnull.InvalidRegistryHandleException- If this handle is no longer valid.NoSuchRegistryKeyException- If the registry key from which this handle was retrieved no longerexists.RegistryException- If the value cannot be deleted for another reason.
-
close
public abstract void close()Closes this registry handle.- Specified by:
closein interfaceAutoCloseable- Throws:
RegistryException- If the registry handle could not be closed.
-