|
7 | 7 | import java.io.InputStream; |
8 | 8 | import java.net.URL; |
9 | 9 | import java.net.URLDecoder; |
10 | | -import java.nio.charset.Charset; |
| 10 | +import java.nio.charset.StandardCharsets; |
11 | 11 | import java.nio.file.Files; |
12 | 12 | import java.text.SimpleDateFormat; |
13 | 13 | import java.util.ArrayList; |
|
33 | 33 | */ |
34 | 34 | public class ContextProperties extends OrderedProperties { |
35 | 35 |
|
| 36 | + private static final String UTF_8 = "UTF-8"; |
| 37 | + |
36 | 38 | private static final String BASE64_PREFIX = "_b64_"; |
37 | 39 |
|
38 | 40 | private static final String UNABLE_TO_READ_FROM = "Unable to read from %s"; |
@@ -112,7 +114,7 @@ public ContextProperties(URL fileUrl) throws IOException { |
112 | 114 | */ |
113 | 115 | private void load(URL fileUrl) throws IOException { |
114 | 116 | try { |
115 | | - file = new File(URLDecoder.decode(fileUrl.getPath(), "UTF-8")); |
| 117 | + file = new File(URLDecoder.decode(fileUrl.getPath(), UTF_8)); |
116 | 118 | } catch (Exception e) { |
117 | 119 | throw new IOException(String.format(UNABLE_TO_READ_FROM, file.getPath()), e); |
118 | 120 | } |
@@ -270,7 +272,7 @@ public String getString(String property, String defaultValue) { |
270 | 272 | String value = getProperty(property, defaultValue); |
271 | 273 | if (value.startsWith(BASE64_PREFIX)) |
272 | 274 | value = new String(Base64.getDecoder().decode(value.substring(BASE64_PREFIX.length())), |
273 | | - Charset.forName("UTF-8")); |
| 275 | + StandardCharsets.UTF_8); |
274 | 276 | return StrSubstitutor.replaceSystemProperties(value); |
275 | 277 | } |
276 | 278 |
|
@@ -334,7 +336,7 @@ public float getFloat(String property, float defaultValue) { |
334 | 336 | @Override |
335 | 337 | public synchronized Object setProperty(String key, String value) { |
336 | 338 | if (value.contains("\n")) |
337 | | - value = BASE64_PREFIX + Base64.getEncoder().encodeToString(value.getBytes(Charset.forName("UTF-8"))); |
| 339 | + value = BASE64_PREFIX + Base64.getEncoder().encodeToString(value.getBytes(StandardCharsets.UTF_8)); |
338 | 340 | return super.setProperty(key, value); |
339 | 341 | } |
340 | 342 |
|
|
0 commit comments