Class RegistryKey

    • Field Detail

      • HKEY_CLASSES_ROOT

        public static final RegistryKey HKEY_CLASSES_ROOT
        The HKEY_CLASSES_ROOT root key.
      • HKEY_CURRENT_USER

        public static final RegistryKey HKEY_CURRENT_USER
        The HKEY_CURRENT_USER root key.
      • HKEY_LOCAL_MACHINE

        public static final RegistryKey HKEY_LOCAL_MACHINE
        The HKEY_LOCAL_MACHINE root key.
      • HKEY_USERS

        public static final RegistryKey HKEY_USERS
        The HKEY_USERS root key.
      • HKEY_CURRENT_CONFIG

        public static final RegistryKey HKEY_CURRENT_CONFIG
        The HKEY_CURRENT_CONFIG root key.
    • Method Detail

      • name

        public abstract String name()
        Returns the name of the registry key.
        Returns:
        The name of the registry key.
      • path

        public abstract String path()
        Returns the full path to the registry key.
        Returns:
        The full path to the registry key.
      • lastWriteTime

        public Instant lastWriteTime()
        Returns the instant when this registry key was last written to.
        Returns:
        The instant when this registry key was last written to.
        Since:
        1.1
      • attributes

        public RegistryKey.Attributes attributes()
        Returns attributes for this registry key.
        Returns:
        Attributes for this registry key.
        Since:
        1.1
      • resolve

        public abstract RegistryKey resolve​(String relativePath)
        Returns a registry key relative to this registry key. If the relative path is empty or a single ., this registry key is returned.

        Note that this method will never leave the root key.

        Parameters:
        relativePath - The path for the new registry key, relative to this registry key. Since registry keys can contain forward slashes, registry keys must be separated using backslashes (\).
        Returns:
        The resulting registry key.
        Throws:
        NullPointerException - If the given relative path is null.
      • subKeys

        public Stream<RegistryKey> subKeys()
        Returns all direct sub keys of this registry key. This stream should 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 this registry key.
        Throws:
        NoSuchRegistryKeyException - If this registry key does not exist.
        RegistryException - If the sub keys cannot be queried for another reason.
      • traverse

        public Stream<RegistryKey> traverse​(RegistryKey.TraverseOption... options)
        Returns a Stream that traverses through this registry keys and all of its nested keys. This stream should be closed afterwards.

        Note that nothing can be said about the order of registry keys in the stream. It's also unspecified what happens if registry keys are removed while consuming the stream.

        Parameters:
        options - The options to configure the traversal.
        Returns:
        A Stream that traverses through this registry keys and all of its nested keys
      • traverse

        public Stream<RegistryKey> traverse​(int maxDepth,
                                            RegistryKey.TraverseOption... options)
        Returns a Stream that traverses through this registry keys and all of its nested keys. This stream should be closed afterwards.

        Note that nothing can be said about the order of registry keys in the stream. It's also unspecified what happens if registry keys are removed while consuming the stream.

        Parameters:
        maxDepth - The maximum number of registry key levels to visit. A value of 0 indicates that only this registry key should be returned; a value of 1 indicates that only this registry key and its direct sub keys should be returned.
        options - The options to configure the traversal.
        Returns:
        A Stream that traverses through this registry keys and all of its nested keys
        Throws:
        IllegalArgumentException - If the given maximum depth is negative.
      • values

        public Stream<RegistryValue> values()
        Returns all values of this registry key. This stream should 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 this registry key.
        Throws:
        NoSuchRegistryKeyException - If this registry key does not exist.
        RegistryException - If the values cannot be queried for another reason.
      • values

        public Stream<RegistryValue> values​(RegistryValue.Filter filter)
        Returns all values of this registry key. This stream should 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 this registry key.
        Throws:
        NoSuchRegistryKeyException - If this registry key does not exist.
        RegistryException - If the values cannot be queried for another reason.
      • getValue

        public <V extends RegistryValue> V getValue​(String name,
                                                    Class<V> valueType)
        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 is null.
        NoSuchRegistryKeyException - If this registry key does not exist.
        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

        public <V extends RegistryValueOptional<V> findValue​(String name,
                                                               Class<V> valueType)
        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 Optional with the registry value with the given name, or Optional.empty() if there is no such registry value.
        Throws:
        NullPointerException - If the given name or value type is null.
        NoSuchRegistryKeyException - If this registry key does not exist.
        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.
      • deleteValueIfExists

        public boolean deleteValueIfExists​(String name)
        Deletes a registry value if it exists.
        Parameters:
        name - The name of the registry value to exist.
        Returns:
        true if the registry value existed and was deleted, or false if it didn't exist.
        Throws:
        NullPointerException - If the given name is null.
        NoSuchRegistryKeyException - If this registry key does not exist.
        RegistryException - If the value cannot be deleted for another reason.
      • exists

        public abstract boolean exists()
        Tests whether or not this registry key exists.
        Returns:
        true if this registry key exists, or false otherwise.
        Throws:
        RegistryException - If the existence of this registry cannot be determined.
      • isAccessible

        public abstract boolean isAccessible()
        Tests whether or not this registry key is accessible. Accessible means that accessing it will not throw a RegistryAccessDeniedException.

        The following are the relations between this method and exists():

        • If isAccessible() returns true then exists() will return true.
        • If exists() returns false then isAccessible() will return false.
        • If isAccessible() returns false then exists() will not necessarily return false; existing keys may not be accessible.
        • If exists() returns true then isAccessible() will not necessarily return true; existing keys may not be accessible.
        Returns:
        true if this registry key is accessible, or false otherwise.
        Throws:
        RegistryException - If the accessibility of this registry cannot be determined.
        Since:
        1.1
      • createIfNotExists

        public abstract boolean createIfNotExists()
        Creates this registry key if it does not exist already. It will also create any missing parent registry keys that are missing.
        Returns:
        true if the registry key was created, or false if it already existed.
        Throws:
        RegistryException - If this registry key cannot be created.
      • deleteIfExists

        public abstract boolean deleteIfExists()
        Deletes this registry key and all of its values if it exists.
        Returns:
        true if this registry key existed and has been removed, or false if it didn't exist.
        Throws:
        UnsupportedOperationException - If trying to delete one of the root keys.
        RegistryException - If the registry key cannot be deleted for another reason.
      • handle

        public RegistryKey.Handle handle()
        Creates a handle to this registry key. This allows multiple operations on this registry key to be performed without creating a new link to the Windows registry for each operation. The returned handle should be closed when it is no longer needed.

        This method will be like calling handle(HandleOption...) without any options. As a result, it will not be possible to set or delete registry values using the returned handle.

        Returns:
        The created handle.
        Throws:
        NoSuchRegistryKeyException - If this registry key does not exist.
        RegistryException - If the handle could not be created for another reason.
      • handle

        public RegistryKey.Handle handle​(RegistryKey.HandleOption... options)
        Creates a handle to this registry key. This allows multiple operations on this registry key to be performed without creating a new link to the Windows registry for each operation. The returned handle should be closed when it is no longer needed.
        Parameters:
        options - The options that define how the handle is created.
        Returns:
        The created handle.
        Throws:
        NoSuchRegistryKeyException - If this registry key does not exist, and RegistryKey.HandleOption.CREATE is not one of the given options.
        RegistryException - If the handle could not be created for another reason.
      • equals

        public abstract boolean equals​(Object o)
        Overrides:
        equals in class Object
      • hashCode

        public abstract int hashCode()
        Overrides:
        hashCode in class Object