22
22
23
23
import java .io .InputStream ;
24
24
import java .io .InputStreamReader ;
25
+ import java .util .HashMap ;
25
26
import java .util .Locale ;
26
27
import java .util .Map ;
27
28
import java .util .Properties ;
@@ -95,7 +96,7 @@ public static void removeCodeSpace(SpaceId spaceId) {
95
96
}
96
97
97
98
private String logFormat ;
98
- private Properties properties ;
99
+ private Map < String , String > codeMap = new ConcurrentHashMap <>() ;
99
100
100
101
private LogCode2Description (SpaceId spaceId ) {
101
102
logFormat = spaceId .getSpaceName ().toUpperCase () + "-%s: %s" ;
@@ -110,25 +111,30 @@ private LogCode2Description(SpaceId spaceId) {
110
111
}
111
112
112
113
try (InputStream in = this .getClass ().getClassLoader ().getResourceAsStream (fileName )) {
113
- properties = new Properties ();
114
+ Properties properties = new Properties ();
114
115
115
116
if (in == null ) {
116
117
ReportUtil .reportError (String .format ("Code file for CodeSpace \" %s\" doesn't exist!" , spaceId .getSpaceName ()));
117
118
} else {
118
119
InputStreamReader reader = new InputStreamReader (in );
119
120
properties .load (reader );
120
121
}
122
+ for (Map .Entry <?, ?> entry : properties .entrySet ()) {
123
+ String key = (String ) entry .getKey ();
124
+ codeMap .put (key , String .format (logFormat , key , entry .getValue ()));
125
+ }
121
126
} catch (Throwable e ) {
122
127
ReportUtil .reportError (String .format ("Code space \" %s\" initializing failed!" , spaceId .getSpaceName ()), e );
123
128
}
124
129
}
125
130
126
131
public String convert (String code ) {
127
- Object description = properties .get (code );
132
+ String description = codeMap .get (code );
128
133
if (description == null ) {
129
- description = "Unknown Code" ;
134
+ description = String .format (logFormat , code , "Unknown Code" );
135
+ codeMap .put (code , description );
136
+ return description ;
130
137
}
131
-
132
- return String .format (logFormat , code , description );
138
+ return description ;
133
139
}
134
140
}
0 commit comments