Use Path API instead of String concatenation
@@ -20,6 +20,8 @@ import gg.jte.CodeResolver;
import io.vertx.core.Vertx;
import io.vertx.ext.web.common.WebEnvironment;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -28,12 +30,12 @@ import java.util.concurrent.ConcurrentMap;
*/
public class VertxDirectoryCodeResolver implements CodeResolver {
private final Vertx vertx;
- private final String templateRootDirectory;
+ private final Path templateRootDirectory;
private final ConcurrentMap<String, Long> modificationTimes;
public VertxDirectoryCodeResolver(Vertx vertx, String templateRootDirectory) {
this.vertx = vertx;
- this.templateRootDirectory = templateRootDirectory.endsWith("/") ? templateRootDirectory : templateRootDirectory + "/";
+ this.templateRootDirectory = Paths.get(templateRootDirectory);
if (WebEnvironment.development()) {
modificationTimes = new ConcurrentHashMap<>();
@@ -43,7 +45,7 @@ public class VertxDirectoryCodeResolver implements CodeResolver {
}
public String resolve(String name) {
- name = templateRootDirectory + name;
+ name = templateRootDirectory.resolve(name).toString();
String templateCode = vertx.fileSystem().readFileBlocking(name).toString();
if (templateCode == null) {
@@ -62,7 +64,7 @@ public class VertxDirectoryCodeResolver implements CodeResolver {
return false;
}
- name = templateRootDirectory + name;
+ name = templateRootDirectory.resolve(name).toString();
Long lastResolveTime = this.modificationTimes.get(name);
if (lastResolveTime == null) {
