Switched from String to Path.
authorMarco Zanon <info@marcozanon.com>
Wed, 9 Aug 2023 16:12:43 +0000 (16:12 +0000)
committerMarco Zanon <info@marcozanon.com>
Wed, 9 Aug 2023 16:12:43 +0000 (16:12 +0000)
src/main/java/com/marcozanon/macaco/logging/MLogPlainTextFile.java
src/main/java/com/marcozanon/macaco/text/MTranslator.java

index eb6a1f9579e620b7c2a8ebaab0a98c7758dcef05..38756c245e725668131275cbf71077d58f6529f8 100644 (file)
@@ -14,27 +14,28 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
+import java.nio.file.Path;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
 public class MLogPlainTextFile extends MLogTarget {
 
-    protected String file = null;
+    protected Path file = null;
 
     protected BufferedWriter buffer = null;
 
     /* */
 
-    public MLogPlainTextFile(String file) throws MLoggingException {
+    public MLogPlainTextFile(Path file) throws MLoggingException {
         super();
         //
-        if (MText.isBlank(file)) {
-            throw new IllegalArgumentException("Invalid 'file': null or empty.");
+        if (null == file) {
+            throw new IllegalArgumentException("Invalid 'file': null.");
         }
         //
         this.file = file;
         try {
-            this.buffer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(this.getFile(), true), MConstants.TEXT_ENCODING));
+            this.buffer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(this.getFile().toFile(), true), MConstants.TEXT_ENCODING));
         }
         catch (FileNotFoundException exception) {
             throw new MLoggingException("Could not open file.", exception);
@@ -55,7 +56,7 @@ public class MLogPlainTextFile extends MLogTarget {
 
     /* File. */
 
-    protected String getFile() {
+    protected Path getFile() {
         return this.file;
     }
 
index 7e67d8ade2a08ba33c521369d0c81ef5921e7e25..114da265c9452224c1a722ba820039d55612a211 100644 (file)
@@ -14,6 +14,7 @@ import java.io.InputStreamReader;
 import java.io.IOException;
 import java.io.LineNumberReader;
 import java.io.UnsupportedEncodingException;
+import java.nio.file.Path;
 import java.util.LinkedHashMap;
 import java.util.Locale;
 
@@ -41,7 +42,7 @@ public class MTranslator extends MObject {
         this.messages = messages;
     }
 
-    public MTranslator(Locale basicLocale, String file) throws MTranslationFileParsingException {
+    public MTranslator(Locale basicLocale, Path file) throws MTranslationFileParsingException {
         this(basicLocale);
         //
         this.parseFile(file);
@@ -64,13 +65,13 @@ public class MTranslator extends MObject {
         return this.messages;
     }
 
-    public void parseFile(String file) throws MTranslationFileParsingException {
-        if (MText.isBlank(file)) {
-            throw new IllegalArgumentException("Invalid 'file': null or empty.");
+    public void parseFile(Path file) throws MTranslationFileParsingException {
+        if (null == file) {
+            throw new IllegalArgumentException("Invalid 'file': null.");
         }
         //
         try (
-            LineNumberReader buffer = new LineNumberReader(new InputStreamReader(new FileInputStream(file), MConstants.TEXT_ENCODING));
+            LineNumberReader buffer = new LineNumberReader(new InputStreamReader(new FileInputStream(file.toFile()), MConstants.TEXT_ENCODING));
         ) {
             String message = null;
             String line = null;