|
12 | 12 | import java.io.File; |
13 | 13 | import java.io.IOException; |
14 | 14 | import java.io.InputStream; |
| 15 | +import java.io.InputStreamReader; |
15 | 16 | import java.net.URI; |
16 | 17 | import java.net.URL; |
17 | 18 | import java.nio.ByteBuffer; |
|
25 | 26 | import java.util.Map; |
26 | 27 | import java.util.Objects; |
27 | 28 | import java.util.Properties; |
28 | | -import java.util.PropertyResourceBundle; |
29 | 29 | import java.util.jar.JarEntry; |
30 | 30 | import java.util.jar.JarFile; |
31 | 31 | import java.util.stream.Stream; |
@@ -176,21 +176,21 @@ public synchronized Object put(Object key, Object value) { |
176 | 176 | } |
177 | 177 | }; |
178 | 178 |
|
| 179 | + boolean isUtf8; |
179 | 180 | try (InputStream is = resource.openStream()) { |
180 | 181 | byte[] contents = is.readAllBytes(); |
181 | | - if (!isEncoded(contents, StandardCharsets.US_ASCII)) { |
182 | | - boolean isUtf8 = isEncoded(contents, StandardCharsets.UTF_8); |
| 182 | + if (isEncoded(contents, StandardCharsets.US_ASCII)) { |
| 183 | + isUtf8 = false; |
| 184 | + } else { |
| 185 | + isUtf8 = isEncoded(contents, StandardCharsets.UTF_8); |
183 | 186 | boolean isIso88591 = isEncoded(contents, StandardCharsets.ISO_8859_1); |
184 | 187 | assertTrue(isUtf8 || isIso88591, resource + " must be either valid UTF-8 or valid ISO-8859-1."); |
185 | 188 | } |
186 | 189 | } |
187 | 190 |
|
188 | | - try (InputStream is = resource.openStream()) { |
189 | | - PropertyResourceBundle propertyResourceBundle = new PropertyResourceBundle(is); |
190 | | - propertyResourceBundle |
191 | | - .getKeys() |
192 | | - .asIterator() |
193 | | - .forEachRemaining(key -> props.setProperty(key, propertyResourceBundle.getString(key))); |
| 191 | + try (var is = resource.openStream(); |
| 192 | + var r = new InputStreamReader(is, isUtf8 ? StandardCharsets.UTF_8 : StandardCharsets.ISO_8859_1)) { |
| 193 | + props.load(r); |
194 | 194 | } |
195 | 195 | } |
196 | 196 |
|
|
0 commit comments