diff --git a/src/main/java/kiss/Storable.java b/src/main/java/kiss/Storable.java index 2a3c20e2b..cc81bbfa7 100644 --- a/src/main/java/kiss/Storable.java +++ b/src/main/java/kiss/Storable.java @@ -33,7 +33,7 @@ public interface Storable { default Self restore() { synchronized (getClass()) { try { - I.json(Files.newBufferedReader(Path.of(locate()))).as(this); + I.json(Files.newBufferedReader(locate())).as(this); } catch (Throwable e) { // ignore error } @@ -49,7 +49,7 @@ default Self restore() { default Self store() { synchronized (getClass()) { try { - Path file = Path.of(locate()); + Path file = locate(); Path tmp = Files.createTempFile(Files.createDirectories(file.getParent()), file.getFileName().toString(), null); try (FileChannel c = FileChannel.open(file.resolveSibling(file.getFileName() + ".lock"), CREATE, WRITE, DELETE_ON_CLOSE)) { @@ -119,7 +119,7 @@ private Signal auto(Model model, Object object) { * * @return An identifier of persistence location. */ - default String locate() { - return I.env("PreferenceDirectory", ".preferences") + "/" + Model.of(this).type.getName() + ".json"; + default Path locate() { + return Path.of(I.env("PreferenceDirectory", ".preferences") + "/" + Model.of(this).type.getName() + ".json"); } } \ No newline at end of file diff --git a/src/main/java/kiss/Subscriber.java b/src/main/java/kiss/Subscriber.java index f9ed4ea6f..53b6699cb 100644 --- a/src/main/java/kiss/Subscriber.java +++ b/src/main/java/kiss/Subscriber.java @@ -11,11 +11,11 @@ import java.io.ByteArrayInputStream; import java.io.InputStreamReader; -import java.lang.reflect.Type; import java.net.http.WebSocket; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; import java.util.List; import java.util.Map; import java.util.WeakHashMap; @@ -261,8 +261,8 @@ public void onError(WebSocket web, Throwable e) { * {@inheritDoc} */ @Override - public String locate() { - return I.env("LangDirectory", "lang") + "/" + text + ".json"; + public Path locate() { + return Path.of(I.env("LangDirectory", "lang") + "/" + text + ".json"); } // ====================================================================== diff --git a/src/test/java/kiss/StorableTest.java b/src/test/java/kiss/StorableTest.java index 28e68ec55..33180feb4 100644 --- a/src/test/java/kiss/StorableTest.java +++ b/src/test/java/kiss/StorableTest.java @@ -9,11 +9,10 @@ */ package kiss; -import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static java.util.concurrent.TimeUnit.*; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -34,7 +33,7 @@ class StorableTest { @Test void readFromNotExist() throws Exception { Some instance = new Some(); - Path path = Paths.get(instance.locate()); + Path path = instance.locate(); assert Files.notExists(path); instance.restore(); @@ -46,7 +45,7 @@ void readFromNotExist() throws Exception { @Test void readFromSizeZero() throws Exception { Some instance = new Some(); - Path path = Paths.get(instance.locate()); + Path path = instance.locate(); Files.createDirectories(path.getParent()); Files.createFile(path); assert Files.exists(path); @@ -62,7 +61,7 @@ void readFromSizeZero() throws Exception { @Test void writeToNotExist() throws Exception { Some instance = new Some(); - Path path = Paths.get(instance.locate()); + Path path = instance.locate(); assert Files.notExists(path); instance.store(); @@ -72,7 +71,7 @@ void writeToNotExist() throws Exception { @Test void writeToSizeZero() throws Exception { Some instance = new Some(); - Path path = Paths.get(instance.locate()); + Path path = instance.locate(); assert Files.notExists(path); Files.createDirectories(path.getParent()); @@ -98,8 +97,8 @@ private class Some implements Storable { * {@inheritDoc} */ @Override - public String locate() { - return room.locate(Some.class.getSimpleName()).toString(); + public Path locate() { + return room.locate(Some.class.getSimpleName()); } } @@ -165,8 +164,8 @@ private Auto() { * {@inheritDoc} */ @Override - public String locate() { - return room.locate(Auto.class.getSimpleName()).toString(); + public Path locate() { + return room.locate(Auto.class.getSimpleName()); } } @@ -249,8 +248,8 @@ public Disposable auto() { * {@inheritDoc} */ @Override - public String locate() { - return room.locate(AutoRoot.class.getSimpleName()).toString(); + public Path locate() { + return room.locate(AutoRoot.class.getSimpleName()); } } } \ No newline at end of file