no message
This commit is contained in:
@@ -6,6 +6,9 @@ import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
public class CommonUtils {
|
||||
//JSON
|
||||
//--
|
||||
@@ -243,6 +246,16 @@ public class CommonUtils {
|
||||
}
|
||||
return (cc == 0);
|
||||
}
|
||||
public static String removeRedundantSpaces(String s_in) {
|
||||
return String.join(" ",
|
||||
Arrays.stream(s_in.split(" ")).filter(d -> !d.isEmpty()).collect(Collectors.toCollection(Vector::new)));
|
||||
}
|
||||
public static String removeCharacters(String string, String... to_remove) {
|
||||
String res = string;
|
||||
for (String c : to_remove)
|
||||
res = res.replace(c, "");
|
||||
return res;
|
||||
}
|
||||
//ФАЙЛЫ
|
||||
public static String getExtension(File file) {
|
||||
String fn = file.getName();
|
||||
|
||||
49
src/Common/Utils/Loggable.java
Normal file
49
src/Common/Utils/Loggable.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package Common.Utils;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common_old.Current;
|
||||
import Common_old.UI.DebugPrintLevel;
|
||||
import Common_old.UI.UI;
|
||||
import Common_old.Utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Date;
|
||||
public interface Loggable {
|
||||
String getLogHomePath();
|
||||
String getLogName();
|
||||
default File getLogFile() {
|
||||
return Paths.get(getLogHomePath(), (getLogName() + "_log.txt")).toFile();
|
||||
}
|
||||
default void ClearLog() {
|
||||
try {
|
||||
Utils.forceDeleteWithCheck(getLogFile());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
default void Print(String message) {
|
||||
try {
|
||||
FileWriter Log = new FileWriter(getLogFile(), true);
|
||||
String datedMessage = CommonUtils.Brackets(new Date()) + " " + message;
|
||||
Log.write(datedMessage + "\n");
|
||||
Log.close();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
default void Print(DebugPrintLevel level, String message) {
|
||||
if (level.isEnabled())
|
||||
Print(CommonUtils.Brackets(level.getDescription()) + " " + message);
|
||||
}
|
||||
default void PrintException(Exception ex) {
|
||||
StringWriter out = new StringWriter();
|
||||
PrintWriter writer = new PrintWriter(out);
|
||||
ex.printStackTrace(writer);
|
||||
writer.flush();
|
||||
Print(out.toString());
|
||||
if (Current.hasUI())
|
||||
UI.Error("Возникло исключение. Подробности в файле журнала\n" +
|
||||
CommonUtils.Brackets(getLogFile().getAbsolutePath()));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
package Common.Utils;
|
||||
import Common_old.Utils.Utils;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
public class StringTemplate {
|
||||
@@ -13,8 +11,8 @@ public class StringTemplate {
|
||||
public String pattern = "";
|
||||
//------------------------------------------------------------------
|
||||
public StringTemplate(String p, String s) {
|
||||
prefix = Utils.pack(p);
|
||||
suffix = Utils.pack(s);
|
||||
prefix = CommonUtils.removeRedundantSpaces(p);
|
||||
suffix = CommonUtils.removeRedundantSpaces(s);
|
||||
String[] prefix_words = prefix.split(" ");
|
||||
String[] suffix_words = suffix.split(" ");
|
||||
//настраиваем регулярное выражение----------
|
||||
|
||||
Reference in New Issue
Block a user