Record Class ConnectionString

java.lang.Object
java.lang.Record
io.micronaut.core.util.ConnectionString
Record Components:
rawValue - The original unparsed connection string
parseMode - The parse mode used when parsing
prefix - Optional prefix (e.g. optional)
protocol - The protocol component
username - Optional username from authority
password - Optional password from authority
hosts - Parsed list of host/port pairs
path - The path component
options - Parsed query options
canonicalForm - Normalized canonical representation

public record ConnectionString(String rawValue, ConnectionString.ParseMode parseMode, @Nullable String prefix, String protocol, @Nullable String username, @Nullable String password, List<ConnectionString.HostPort> hosts, String path, Map<String,String> options, String canonicalForm) extends Record
Parsed representation of protocol-based connection strings.

Supported syntax:

[optional:]<protocol>://[username[:password]@][host[:port][,host[:port]...]/]<path>[?key=value[&key=value...]]

Examples:

  • file:///etc/app/config.yml
  • optional:file://config/extra
  • consul://user:pass@localhost:8500/app/config?dc=local
  • env://APP_IMPORT.properties
Since:
5.0
  • Constructor Details

  • Method Details

    • parse

      public static ConnectionString parse(String value)
      Parse a connection string.
      Parameters:
      value - The value
      Returns:
      The parsed connection string
    • parse

      public static ConnectionString parse(String value, ConnectionString.ParseMode parseMode)
      Parse a connection string with the provided mode.
      Parameters:
      value - The raw value
      parseMode - The parse mode that defines required components
      Returns:
      The parsed connection string
    • getRawValue

      public String getRawValue()
    • getParseMode

      public ConnectionString.ParseMode getParseMode()
      Returns:
      Returns the parse mode used to parse this value
    • getPrefix

      public Optional<String> getPrefix()
      Returns:
      Returns optional prefix, for example optional
    • isOptional

      public boolean isOptional()
      Returns:
      Returns whether the connection string starts with optional:
    • getProtocol

      public String getProtocol()
      Returns:
      Returns the normalized lower-case protocol
    • getUsername

      public Optional<String> getUsername()
      Returns:
      Returns optional username from the authority section
    • getPassword

      public Optional<String> getPassword()
      Returns:
      Returns optional password from the authority section
    • getHosts

      public List<ConnectionString.HostPort> getHosts()
      Returns:
      Returns immutable list of host/port entries from the authority section
    • getPath

      public String getPath()
      Returns:
      Returns parsed path component (may be empty depending on parse mode)
    • getCanonicalPath

      public String getCanonicalPath()
      Returns:
      Returns normalized path with duplicate separators and dot segments removed
    • getResourcePath

      public String getResourcePath()
      Returns:
      Returns resource path for file/classpath-like use cases
    • getExtension

      public Optional<String> getExtension()
      Returns:
      Returns optional file extension derived from getPath()
    • getOptions

      public Map<String,String> getOptions()
      Returns:
      Returns immutable parsed query/options map
    • getCanonicalForm

      public String getCanonicalForm()
      Returns:
      Returns canonical representation preserving semantic components
    • equals

      public boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • rawValue

      public String rawValue()
      Returns the value of the rawValue record component.
      Returns:
      the value of the rawValue record component
    • parseMode

      public ConnectionString.ParseMode parseMode()
      Returns the value of the parseMode record component.
      Returns:
      the value of the parseMode record component
    • prefix

      public @Nullable String prefix()
      Returns the value of the prefix record component.
      Returns:
      the value of the prefix record component
    • protocol

      public String protocol()
      Returns the value of the protocol record component.
      Returns:
      the value of the protocol record component
    • username

      public @Nullable String username()
      Returns the value of the username record component.
      Returns:
      the value of the username record component
    • password

      public @Nullable String password()
      Returns the value of the password record component.
      Returns:
      the value of the password record component
    • hosts

      Returns the value of the hosts record component.
      Returns:
      the value of the hosts record component
    • path

      public String path()
      Returns the value of the path record component.
      Returns:
      the value of the path record component
    • options

      public Map<String,String> options()
      Returns the value of the options record component.
      Returns:
      the value of the options record component
    • canonicalForm

      public String canonicalForm()
      Returns the value of the canonicalForm record component.
      Returns:
      the value of the canonicalForm record component