-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathCMN.java
More file actions
168 lines (151 loc) · 5.49 KB
/
CMN.java
File metadata and controls
168 lines (151 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package test;
import com.knziha.plod.dictionaryBuilder.ArrayListTree;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
//common
public class CMN{
public static void show(String val){System.out.println(val);}
public final static String replaceReg = " |:|\\.|,|-|\'";
public final static String emptyStr = "";
public static void Log(Object... o) {
StringBuilder msg= new StringBuilder();
if(o!=null)
for (Object o1 : o) {
//android.util.Log.d("fatal",o[i].getClass().getName());
if (o1 != null) {
if (o1 instanceof Exception) {
ByteArrayOutputStream s = new ByteArrayOutputStream();
PrintStream p = new PrintStream(s);
((Exception) o1).printStackTrace(p);
msg.append(s.toString());
continue;
}
List oi = null;
String classname = o1.getClass().getName();
switch (classname) {
case "[I": {
int[] arr = (int[]) o1;
for (int os : arr) {
msg.append(os);
msg.append(", ");
}
continue;
}
case "[Ljava.lang.String;": {
String[] arr = (String[]) o1;
for (String os : arr) {
msg.append(os);
msg.append(", ");
}
continue;
}
case "[S": {
short[] arr = (short[]) o1;
for (short os : arr) {
msg.append(os);
msg.append(", ");
}
continue;
}
case "[B": {
byte[] arr = (byte[]) o1;
for (byte os : arr) {
msg.append(Integer.toHexString(os));
msg.append(", ");
}
continue;
}
}
}
msg.append(o1).append(o.length>1?" ":"");
}
if(fout!=null) {
try {
fout.write((msg+"\r\n").getBytes(StandardCharsets.UTF_8));
} catch (IOException ignored) { }
}
System.out.println(msg.toString());
}
static FileOutputStream fout;
public static void ConfigLogFile(String path, boolean...a) {
try {
if(fout!=null){
fout.flush();
fout.close();
fout=null;
}
if(path!=null)
fout=new FileOutputStream(path, a[0]);
} catch (Exception e) {
e.printStackTrace();
}
}
static volatile long stst;
public static void rt() {
stst = System.currentTimeMillis();
}
public static void pt(String...args) {
CMN.Log(args,(System.currentTimeMillis()-stst));
}
public static void pt_mins(String...args) {
CMN.Log(args,((System.currentTimeMillis()-stst)/1000.f/60)+"m");
}
public static HashSet<String> AdaptivelyGetAllLines(String path, HashSet<String> proessed) {
if(proessed==null) proessed=new HashSet<>();
try {
BufferedReader br = new BufferedReader(new FileReader(path));
String line;
while((line=br.readLine())!=null){
line=line.trim();
if(line.length()>0)
proessed.add(line);
}
} catch (Exception e) { }
return proessed;
}
public static ArrayList<String> AdaptivelyGetAllLines(ArrayList<String> proessed, String path) {
if(proessed==null) proessed=new ArrayList<>();
try {
BufferedReader br = new BufferedReader(new FileReader(path));
String line;
while((line=br.readLine())!=null){
line=line.trim();
if(line.length()>0)
proessed.add(line);
}
} catch (Exception e) {
e.printStackTrace();
}
return proessed;
}
public static void AdaptivelyLogFiles(HashMap<String, FileOutputStream> cache, boolean append, String path, String msg) {
try {
FileOutputStream fin = cache.get(path);
if(fin==null){
fin = new FileOutputStream(path, append);
cache.put(path, fin);
}
fin.write((msg+"\r\n").getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
e.printStackTrace();
}
}
public static void AdaptivelyLogFiles(HashMap<String, FileOutputStream> cache) {
try {
for(String key:cache.keySet()){
cache.get(key).flush();
cache.get(key).close();
}
cache.clear();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void inline(Object val) {
System.out.print(val+", ");
}
}