diff --git a/java/src/org/openqa/selenium/grid/jmx/MBean.java b/java/src/org/openqa/selenium/grid/jmx/MBean.java index 3bdd3111dc21f..501cd254d27d5 100644 --- a/java/src/org/openqa/selenium/grid/jmx/MBean.java +++ b/java/src/org/openqa/selenium/grid/jmx/MBean.java @@ -248,9 +248,9 @@ public AttributeList getAttributes(String[] attributes) { // if attributeNames is empty, return an empty result list if (attributes == null || attributes.length == 0) return resultList; - for (int i = 0; i < attributes.length; i++) { - Object value = getAttribute(attributes[i]); - resultList.add(new Attribute(attributes[i], value)); + for (String attribute : attributes) { + Object value = getAttribute(attribute); + resultList.add(new Attribute(attribute, value)); } return resultList; diff --git a/java/src/org/openqa/selenium/grid/node/docker/DockerSessionFactory.java b/java/src/org/openqa/selenium/grid/node/docker/DockerSessionFactory.java index 48f567f576268..3cc1d4ab68911 100644 --- a/java/src/org/openqa/selenium/grid/node/docker/DockerSessionFactory.java +++ b/java/src/org/openqa/selenium/grid/node/docker/DockerSessionFactory.java @@ -454,9 +454,8 @@ private void saveSessionCapabilities(Capabilities sessionRequestCapabilities, St String capsToJson = new Json().toJson(sessionRequestCapabilities); try { Files.createDirectories(Paths.get(path)); - Files.write( - Paths.get(path, "sessionCapabilities.json"), - capsToJson.getBytes(Charset.defaultCharset())); + Files.writeString( + Paths.get(path, "sessionCapabilities.json"), capsToJson, Charset.defaultCharset()); } catch (IOException e) { LOG.log(Level.WARNING, "Failed to save session capabilities", e); } diff --git a/java/test/org/openqa/selenium/UploadTest.java b/java/test/org/openqa/selenium/UploadTest.java index ae67b01aa3613..308ca7a4d1e96 100644 --- a/java/test/org/openqa/selenium/UploadTest.java +++ b/java/test/org/openqa/selenium/UploadTest.java @@ -29,7 +29,6 @@ import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Arrays; import java.util.List; @@ -179,7 +178,7 @@ private File createTmpFile(String content) { try { File f = File.createTempFile("webdriver", "tmp"); f.deleteOnExit(); - Files.write(f.toPath(), content.getBytes(StandardCharsets.UTF_8)); + Files.writeString(f.toPath(), content); return f; } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/java/test/org/openqa/selenium/edge/EdgeOptionsTest.java b/java/test/org/openqa/selenium/edge/EdgeOptionsTest.java index b0e552108c604..158eee1180a3d 100644 --- a/java/test/org/openqa/selenium/edge/EdgeOptionsTest.java +++ b/java/test/org/openqa/selenium/edge/EdgeOptionsTest.java @@ -242,7 +242,7 @@ private void checkCommonStructure(EdgeOptions options) { private File createTempFile(Path tmpDir, String content) { try { Path file = Files.createTempFile(tmpDir, "tmp", "ext"); - Files.write(file, content.getBytes(Charset.defaultCharset())); + Files.writeString(file, content, Charset.defaultCharset()); return file.toFile(); } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/java/test/org/openqa/selenium/environment/webserver/AppServerTestBase.java b/java/test/org/openqa/selenium/environment/webserver/AppServerTestBase.java index 8244ff07c94b2..b174fa2b95700 100644 --- a/java/test/org/openqa/selenium/environment/webserver/AppServerTestBase.java +++ b/java/test/org/openqa/selenium/environment/webserver/AppServerTestBase.java @@ -17,7 +17,6 @@ package org.openqa.selenium.environment.webserver; -import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.openqa.selenium.remote.http.Contents.string; @@ -135,7 +134,7 @@ void uploadsFile() throws Throwable { String FILE_CONTENTS = "Uploaded file"; File testFile = File.createTempFile("webdriver", "tmp"); testFile.deleteOnExit(); - Files.write(testFile.toPath(), FILE_CONTENTS.getBytes(UTF_8)); + Files.writeString(testFile.toPath(), FILE_CONTENTS); driver.get(server.whereIs("upload.html")); driver.findElement(By.id("upload")).sendKeys(testFile.getAbsolutePath()); diff --git a/java/test/org/openqa/selenium/grid/node/NodeTest.java b/java/test/org/openqa/selenium/grid/node/NodeTest.java index b9e8fcc7399de..4ce9e7e019ff6 100644 --- a/java/test/org/openqa/selenium/grid/node/NodeTest.java +++ b/java/test/org/openqa/selenium/grid/node/NodeTest.java @@ -36,7 +36,6 @@ import java.io.UncheckedIOException; import java.net.URI; import java.net.URISyntaxException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.time.Clock; @@ -917,7 +916,7 @@ private File createFile(String content, File directory) { try { File f = new File(directory.getAbsolutePath(), UUID.randomUUID().toString()); f.deleteOnExit(); - Files.write(directory.toPath(), content.getBytes(StandardCharsets.UTF_8)); + Files.writeString(directory.toPath(), content); return f; } catch (IOException e) { throw new RuntimeException(e); @@ -928,7 +927,7 @@ private File createTmpFile(String content) { try { File f = File.createTempFile("webdriver", "tmp"); f.deleteOnExit(); - Files.write(f.toPath(), content.getBytes(StandardCharsets.UTF_8)); + Files.writeString(f.toPath(), content); return f; } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/java/test/org/openqa/selenium/grid/web/ResourceHandlerTest.java b/java/test/org/openqa/selenium/grid/web/ResourceHandlerTest.java index 32ce041aa7435..8c76ac80cf4dc 100644 --- a/java/test/org/openqa/selenium/grid/web/ResourceHandlerTest.java +++ b/java/test/org/openqa/selenium/grid/web/ResourceHandlerTest.java @@ -19,7 +19,6 @@ import static java.net.HttpURLConnection.HTTP_MOVED_TEMP; import static java.net.HttpURLConnection.HTTP_OK; -import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; import static org.openqa.selenium.remote.http.HttpMethod.GET; @@ -48,7 +47,7 @@ public void getPath() throws IOException { @Test void shouldLoadContent() throws IOException { - Files.write(base.resolve("content.txt"), "I like cheese".getBytes(UTF_8)); + Files.writeString(base.resolve("content.txt"), "I like cheese"); HttpHandler handler = new ResourceHandler(new PathResource(base)); HttpResponse res = handler.execute(new HttpRequest(GET, "/content.txt")); @@ -90,7 +89,7 @@ void canBeNestedWithinARoute() throws IOException { Path contents = base.resolve("cheese").resolve("cake.txt"); Files.createDirectories(contents.getParent()); - Files.write(contents, "delicious".getBytes(UTF_8)); + Files.writeString(contents, "delicious"); HttpHandler handler = Route.prefix("/peas").to(Route.combine(new ResourceHandler(new PathResource(base)))); @@ -109,7 +108,7 @@ void canBeNestedWithinARoute() throws IOException { @Test void shouldRedirectToIndexPageIfOneExists() throws IOException { Path index = base.resolve("index.html"); - Files.write(index, "Cheese".getBytes(UTF_8)); + Files.writeString(index, "Cheese"); ResourceHandler handler = new ResourceHandler(new PathResource(base)); HttpResponse res = handler.execute(new HttpRequest(GET, "/")); diff --git a/java/test/org/openqa/selenium/testing/TestUtilities.java b/java/test/org/openqa/selenium/testing/TestUtilities.java index 3cbe9971a7526..21abfa50b8e77 100644 --- a/java/test/org/openqa/selenium/testing/TestUtilities.java +++ b/java/test/org/openqa/selenium/testing/TestUtilities.java @@ -20,7 +20,6 @@ import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Map; import java.util.regex.Matcher; @@ -175,7 +174,7 @@ public static File createTmpFile(String content) { try { File f = File.createTempFile("webdriver", "tmp"); f.deleteOnExit(); - Files.write(f.toPath(), content.getBytes(StandardCharsets.UTF_8)); + Files.writeString(f.toPath(), content); return f; } catch (IOException e) { throw new UncheckedIOException(e);