diff --git a/client/src/main/java/hudson/plugins/swarm/Client.java b/client/src/main/java/hudson/plugins/swarm/Client.java index 96fddafc..56ef970e 100644 --- a/client/src/main/java/hudson/plugins/swarm/Client.java +++ b/client/src/main/java/hudson/plugins/swarm/Client.java @@ -102,9 +102,7 @@ private static void validateOptions(Options options) { int oldPid; try { oldPid = - NumberUtils.toInt( - new String(Files.readAllBytes(pidFile), StandardCharsets.UTF_8), - 0); + NumberUtils.toInt(Files.readString(pidFile, StandardCharsets.UTF_8), 0); } catch (IOException e) { throw new UncheckedIOException("Failed to read PID file " + pidFile, e); } @@ -146,9 +144,7 @@ private static void validateOptions(Options options) { if (options.password == null && options.passwordFile != null) { try { options.password = - new String( - Files.readAllBytes(Paths.get(options.passwordFile)), - StandardCharsets.UTF_8) + Files.readString(Paths.get(options.passwordFile), StandardCharsets.UTF_8) .trim(); } catch (IOException e) { throw new UncheckedIOException("Failed to read password from file", e); diff --git a/client/src/main/java/hudson/plugins/swarm/LabelFileWatcher.java b/client/src/main/java/hudson/plugins/swarm/LabelFileWatcher.java index bd76b542..9598e00f 100644 --- a/client/src/main/java/hudson/plugins/swarm/LabelFileWatcher.java +++ b/client/src/main/java/hudson/plugins/swarm/LabelFileWatcher.java @@ -54,9 +54,7 @@ public LabelFileWatcher(URL url, Options options, String name, String... args) this.url = url; this.options = options; this.name = name; - this.labels = - new String( - Files.readAllBytes(Paths.get(options.labelsFile)), StandardCharsets.UTF_8); + this.labels = Files.readString(Paths.get(options.labelsFile), StandardCharsets.UTF_8); this.args = args; logger.config("Labels loaded: " + labels); } @@ -242,9 +240,7 @@ public void run() { } try { sTempLabels = - new String( - Files.readAllBytes(Paths.get(options.labelsFile)), - StandardCharsets.UTF_8); + Files.readString(Paths.get(options.labelsFile), StandardCharsets.UTF_8); if (sTempLabels.equalsIgnoreCase(labels)) { logger.log( Level.FINEST, @@ -255,9 +251,8 @@ public void run() { // through the plugin APIs softLabelUpdate(sTempLabels); labels = - new String( - Files.readAllBytes(Paths.get(options.labelsFile)), - StandardCharsets.UTF_8); + Files.readString( + Paths.get(options.labelsFile), StandardCharsets.UTF_8); } catch (SoftLabelUpdateException e) { // if we're unable to logger.log( diff --git a/client/src/main/java/hudson/plugins/swarm/SwarmClient.java b/client/src/main/java/hudson/plugins/swarm/SwarmClient.java index 082c469f..57a49ea7 100644 --- a/client/src/main/java/hudson/plugins/swarm/SwarmClient.java +++ b/client/src/main/java/hudson/plugins/swarm/SwarmClient.java @@ -112,9 +112,7 @@ public SwarmClient(Options options) { logger.info("Loading labels from " + options.labelsFile + "..."); try { String labels = - new String( - Files.readAllBytes(Paths.get(options.labelsFile)), - StandardCharsets.UTF_8); + Files.readString(Paths.get(options.labelsFile), StandardCharsets.UTF_8); options.labels.addAll(Arrays.asList(labels.trim().split("\\s+"))); logger.info("Labels found in file: " + labels); logger.info( @@ -355,7 +353,8 @@ private static synchronized Crumb getCsrfCrumb( url + "crumbIssuer/api/xml?xpath=" + URLEncoder.encode( - "concat(//crumbRequestField,\":\",//crumb)", "UTF-8")); + "concat(//crumbRequestField,\":\",//crumb)", + StandardCharsets.UTF_8)); try (CloseableHttpResponse response = client.execute(httpGet, context)) { if (response.getCode() != HttpStatus.SC_OK) { logger.log( @@ -589,7 +588,7 @@ static synchronized void postLabelAppend( private static synchronized String encode(String value) throws UnsupportedEncodingException { logger.finer("encode() invoked"); - return URLEncoder.encode(value, "UTF-8"); + return URLEncoder.encode(value, StandardCharsets.UTF_8); } private static synchronized String param(String name, String value)