@@ -26,6 +26,7 @@ public final class FileController {
26
26
private static final ObjectMapper mapper = new ObjectMapper ();
27
27
28
28
private String dataFolder ;
29
+ private boolean printErrorsFlag ;
29
30
30
31
private FileController () {
31
32
}
@@ -34,8 +35,9 @@ public static FileController getInstance() {
34
35
return INSTANCE ;
35
36
}
36
37
37
- public FileController configure (String path ) {
38
+ public FileController configure (String path , boolean printErrorsFlag ) {
38
39
this .dataFolder = path ;
40
+ this .printErrorsFlag = printErrorsFlag ;
39
41
File dirFile = new File (path );
40
42
if (!dirFile .exists () || !dirFile .isDirectory ()) {
41
43
dirFile .mkdirs ();
@@ -74,7 +76,9 @@ public <T> void writeToDir(String path, String fileName, T obj) {
74
76
try {
75
77
mapper .writeValue (new File (path ), obj );
76
78
} catch (IOException e ) {
77
- // e.printStackTrace();
79
+ if (printErrorsFlag ) {
80
+ e .printStackTrace ();
81
+ }
78
82
}
79
83
}
80
84
@@ -90,7 +94,9 @@ public <T extends Object> List<T> readAsList(String path, String file, Class<T>
90
94
list .add (mapper .readValue (value , classReference ));
91
95
}
92
96
} catch (Exception e ) {
93
- e .printStackTrace ();
97
+ if (printErrorsFlag ) {
98
+ e .printStackTrace ();
99
+ }
94
100
}
95
101
return list ;
96
102
}
@@ -113,7 +119,9 @@ public <K extends Object, V extends Object> Map<K, V> readAsMap(String path, Str
113
119
map .put ((K ) entry .getKey (), mapper .readValue (value , valueClass ));
114
120
}
115
121
} catch (Exception e ) {
116
- e .printStackTrace ();
122
+ if (printErrorsFlag ) {
123
+ e .printStackTrace ();
124
+ }
117
125
}
118
126
return map ;
119
127
}
@@ -134,9 +142,13 @@ public <T> T readFromDir(String path, String fileName, String internalPath, Clas
134
142
}
135
143
result = mapper .readValue (mapper .writeValueAsString (data ), typeReference );
136
144
} catch (JsonProcessingException e ) {
137
- e .printStackTrace ();
145
+ if (printErrorsFlag ) {
146
+ e .printStackTrace ();
147
+ }
138
148
} catch (IOException e ) {
139
- e .printStackTrace ();
149
+ if (printErrorsFlag ) {
150
+ e .printStackTrace ();
151
+ }
140
152
}
141
153
return result ;
142
154
}
@@ -150,7 +162,9 @@ public JsonNode loadAsJSON(String path, String file) {
150
162
try {
151
163
obj = mapper .readTree (new File (path , file ));
152
164
} catch (IOException e ) {
153
- // System.out.println("FileController - Could not load " + file + " inside " + path + "as a JSON object.");
165
+ if (printErrorsFlag ) {
166
+ e .printStackTrace ();
167
+ }
154
168
}
155
169
return obj ;
156
170
}
0 commit comments