/** * Load a property-based resource bundle from the given reader. * <p>This will be called in case of a {@link #setDefaultEncoding "defaultEncoding"}, * including {@link ResourceBundleMessageSource}'s default ISO-8859-1 encoding. * Note that this method can only be called with a {@code ResourceBundle.Control}: * When running on the JDK 9+ module path where such control handles are not * supported, any overrides in custom subclasses will effectively get ignored. * <p>The default implementation returns a {@link PropertyResourceBundle}. * @param reader the reader for the target resource * @return the fully loaded bundle * @throws IOException in case of I/O failure * @since 4.2 * @see #loadBundle(InputStream) * @see PropertyResourceBundle#PropertyResourceBundle(Reader) */ protected ResourceBundle loadBundle(Reader reader) throws IOException { return new PropertyResourceBundle(reader); }
/** * Load a property-based resource bundle from the given input stream, * picking up the default properties encoding on JDK 9+. * <p>This will only be called with {@link #setDefaultEncoding "defaultEncoding"} * set to {@code null}, explicitly enforcing the platform default encoding * (which is UTF-8 with a ISO-8859-1 fallback on JDK 9+ but configurable * through the "java.util.PropertyResourceBundle.encoding" system property). * Note that this method can only be called with a {@code ResourceBundle.Control}: * When running on the JDK 9+ module path where such control handles are not * supported, any overrides in custom subclasses will effectively get ignored. * <p>The default implementation returns a {@link PropertyResourceBundle}. * @param inputStream the input stream for the target resource * @return the fully loaded bundle * @throws IOException in case of I/O failure * @since 5.1 * @see #loadBundle(Reader) * @see PropertyResourceBundle#PropertyResourceBundle(InputStream) */ protected ResourceBundle loadBundle(InputStream inputStream) throws IOException { return new PropertyResourceBundle(inputStream); }
/** * Load a property-based resource bundle from the given reader. * <p>This will be called in case of a {@link #setDefaultEncoding "defaultEncoding"}, * including {@link ResourceBundleMessageSource}'s default ISO-8859-1 encoding. * Note that this method can only be called with a {@code ResourceBundle.Control}: * When running on the JDK 9+ module path where such control handles are not * supported, any overrides in custom subclasses will effectively get ignored. * <p>The default implementation returns a {@link PropertyResourceBundle}. * @param reader the reader for the target resource * @return the fully loaded bundle * @throws IOException in case of I/O failure * @since 4.2 * @see #loadBundle(InputStream) * @see PropertyResourceBundle#PropertyResourceBundle(Reader) */ protected ResourceBundle loadBundle(Reader reader) throws IOException { return new PropertyResourceBundle(reader); }
/** * Load a property-based resource bundle from the given input stream, * picking up the default properties encoding on JDK 9+. * <p>This will only be called with {@link #setDefaultEncoding "defaultEncoding"} * set to {@code null}, explicitly enforcing the platform default encoding * (which is UTF-8 with a ISO-8859-1 fallback on JDK 9+ but configurable * through the "java.util.PropertyResourceBundle.encoding" system property). * Note that this method can only be called with a {@code ResourceBundle.Control}: * When running on the JDK 9+ module path where such control handles are not * supported, any overrides in custom subclasses will effectively get ignored. * <p>The default implementation returns a {@link PropertyResourceBundle}. * @param inputStream the input stream for the target resource * @return the fully loaded bundle * @throws IOException in case of I/O failure * @since 5.1 * @see #loadBundle(Reader) * @see PropertyResourceBundle#PropertyResourceBundle(InputStream) */ protected ResourceBundle loadBundle(InputStream inputStream) throws IOException { return new PropertyResourceBundle(inputStream); }
try (FileInputStream fis = new FileInputStream("c:/temp/mybundle.txt")) { return new PropertyResourceBundle(fis); }
private static void load(LangLocale locale) { ResourceBundle bundle; ClassLoader classLoader = ClassLoader.getSystemClassLoader(); String resName = String.format("i18n/Messages_%s.properties", locale.get()); URL bundleUrl = classLoader.getResource(resName); if (bundleUrl == null) { throw new JadxRuntimeException("Locale resource not found: " + resName); } try (Reader reader = new InputStreamReader(bundleUrl.openStream(), StandardCharsets.UTF_8)) { bundle = new PropertyResourceBundle(reader); } catch (IOException e) { throw new JadxRuntimeException("Failed to load " + resName, e); } i18nMessagesMap.put(locale, bundle); }
try { bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8")); } finally { stream.close();
@Override public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IOException { // The below is a copy of the default implementation. final String bundleName = toBundleName(baseName, locale); final String resourceName = toResourceName(bundleName, "properties"); final URL url = loader.getResource(resourceName); ResourceBundle resourceBundle = null; if (url != null) { final URLConnection connection = url.openConnection(); if (connection != null) { connection.setUseCaches(!reload); try (Reader streamReader = new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8.name())) { // Only this line is changed to make it read property files as UTF-8. resourceBundle = new PropertyResourceBundle(streamReader); } } } return resourceBundle; }
/** * Tries to load resource bundle via OSGi means. No caching involved here, * as localization properties are being cached in Localizer class already. * * @param bundleName name of the resource bundle to load * @return resource bundle instance if found, null otherwise */ public ResourceBundle getResourceBundle(final String bundleName) { final int lastDotIndex = bundleName.lastIndexOf('.'); final String path = bundleName.substring(0, lastDotIndex).replace('.', '/'); final String propertiesName = bundleName.substring(lastDotIndex + 1, bundleName.length()) + ".properties"; for (final Bundle bundle : bundleContext.getBundles()) { final Enumeration<URL> entries = findEntries(bundle, path, propertiesName, false); if (entries != null && entries.hasMoreElements()) { final URL entryUrl = entries.nextElement(); try { return new PropertyResourceBundle(entryUrl.openStream()); } catch (final IOException ex) { if (LOGGER.isLoggable(Level.FINE)) { // does not make sense to localize this LOGGER.fine("Exception caught when tried to load resource bundle in OSGi"); } return null; } } } return null; }
/** * Tries to load resource bundle via OSGi means. No caching involved here, * as localization properties are being cached in Localizer class already. * * @param bundleName name of the resource bundle to load * @return resource bundle instance if found, null otherwise */ public ResourceBundle getResourceBundle(final String bundleName) { final int lastDotIndex = bundleName.lastIndexOf('.'); final String path = bundleName.substring(0, lastDotIndex).replace('.', '/'); final String propertiesName = bundleName.substring(lastDotIndex + 1, bundleName.length()) + ".properties"; for (final Bundle bundle : bundleContext.getBundles()) { final Enumeration<URL> entries = findEntries(bundle, path, propertiesName, false); if (entries != null && entries.hasMoreElements()) { final URL entryUrl = entries.nextElement(); try { return new PropertyResourceBundle(entryUrl.openStream()); } catch (final IOException ex) { if (LOGGER.isLoggable(Level.FINE)) { // does not make sense to localize this LOGGER.fine("Exception caught when tried to load resource bundle in OSGi"); } return null; } } } return null; }
try { bundle = new PropertyResourceBundle( new InputStreamReader( stream, StandardCharsets.UTF_8.name() ) ); } finally { stream.close();
try { bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8")); } finally { stream.close();
try { bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8")); } finally { stream.close();
void method6() throws Exception { String srcDir = System.getProperty("test.src", "."); try (FileInputStream fis8859_1 = new FileInputStream(new File(srcDir, "Bug.properties")); FileInputStream fisUTF8 = new FileInputStream(new File(srcDir, "Bug_Utf8.properties")); InputStreamReader isrutf8 = new InputStreamReader(fisUTF8, "UTF-8")) { PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrutf8); PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1); String[] arrayUtf8 = {"1", "2", "3"}; String[] array = {"key1", "key2"}; if (!Arrays.equals(arrayUtf8, array)) { throw new RuntimeException("Error message"); } } catch (IOException ioe) { throw new RuntimeException(ioe); } } }
private ResourceBundle getBundle(final Locale locale) throws IOException, URISyntaxException { final String propertiesFileNameWithCountry = "org/killbill/billing/util/template/translation/CatalogTranslation" + "_" + locale.getLanguage() + "_" + locale.getCountry() + ".properties"; final InputStream inputStream = UriAccessor.accessUri(propertiesFileNameWithCountry); if (inputStream == null) { return null; } else { return new PropertyResourceBundle(inputStream); } }
resourceBundle = new PropertyResourceBundle(stream); propertiesSource = propertiesFile.getAbsolutePath(); LOGGER.finest("FileSystemWithoutExtension"); resourceBundle = new PropertyResourceBundle(stream); propertiesSource = propertiesFile.getAbsolutePath(); LOGGER.finest("FileSystemWithExtension");
bundle = new PropertyResourceBundle(new InputStreamReader(stream, CHARSET)); } finally { stream.close();
if (stream != null) { try { bundle = new PropertyResourceBundle(new InputStreamReader(stream, StandardCharsets.UTF_8)); bundle.setLocale(locale); } catch (IOException ignored) {
if (bundleUrl != null) { try { bundle = new PropertyResourceBundle(bundleUrl.openStream()); } catch (IOException ex) {
if (bundleUrl != null) { try { bundle = new PropertyResourceBundle(bundleUrl.openStream()); } catch (IOException ex) {