Skip to content

Commit c2b7691

Browse files
authored
Document the new UriUtils class
1 parent 92d725f commit c2b7691

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* [Assembling a Classpath String](#assembling-a-classpath-string)
2424
* [Finding a JAR File Path](#finding-a-jar-file-path)
2525
* [Extracting the `Premain-Class` Attribute](#extracting-the-premain-class-attribute)
26+
* [UriUtils](#uriutils) provides convenience methods for assembling **URI** objects without having to deal with **URISyntaxException**.
2627

2728
## StackTrace
2829

@@ -384,8 +385,8 @@ This code uses a static import to eliminate redundant references to the **Params
384385

385386
The **JarUtils** class provides methods related to Java JAR files.
386387

387-
* `getClasspath` assemble a classpath string from the specified array of dependencies.
388-
* `findJarPathFor` find the path to the JAR file from which the named class was loaded.
388+
* `getClasspath` assembles a classpath string from the specified array of dependencies.
389+
* `findJarPathFor` finds the path to the JAR file from which the named class was loaded.
389390
* `getJarPremainClass` gets the 'Premain-Class' attribute from the indicated JAR file.
390391

391392
The methods of this class provide critical services for the `Local Grid` feature of [**Selenium Foundation**](https://github.com/sbabcoc/Selenium-Foundation), handling the task of locating the JAR files that declare the classes required by the Java-based servers it launches.
@@ -405,4 +406,13 @@ The **`findJarPathFor`** method will find the absolute path to the JAR file from
405406

406407
The **`getJarPremainClass`** method will extract the `Premain-Class` attribute from the manifest of the indicated JAR file. The value of this attribute specifies the name of a `Java agent` class declared by the JAR.
407408

409+
## UriUtils
410+
411+
As of Java 20, all of the constructors of the **URL** class have been deprecated. The recommended replacement is the **`toURL()`** method of the **URI** class, but all of the constructors of this class throw **URISyntaxtException**. While this isn't a huge ordeal, having to handle this exception in contexts where the constructor arguments have already been validated can degrade code readability with no benefit to code safety. The **UriUtils** class provides two convenience methods that employ the same strategy used by the **`create()`** method of the **URI** class - wrapping the **URISyntaxException** in an **IllegalArgumentException**:
412+
413+
* `makeBasicUri` assembles a basic URI from the specified components - scheme, host, port, and path.
414+
* `uriForPath` assembles a URI for the specified path under the provided context.
415+
416+
Note that the **`toURL()`** method of the **URI** class throws the **MalformedURLException**, but this exception is a subclass of **IOException**, which affected code is almost certain to be handling already.
417+
408418
> Written with [StackEdit](https://stackedit.io/).

0 commit comments

Comments
 (0)