java.util.PropertyResourceBundle Java Examples

The following examples show how to use java.util.PropertyResourceBundle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExeLauncher.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void addData(FileOutputStream fos, PropertyResourceBundle bundle, PropertyResourceBundle backupBundle, String localeName, List <String> propertiesNames) throws IOException {
    String propertyName;
    String localizedString;
    addData(fos, localeName, true);
    Enumeration <String> en = bundle.getKeys();
    for(int i=0;i<propertiesNames.size();i++) {
        String str = null;
        try {
            str = bundle.getString(propertiesNames.get(i));
        } catch (MissingResourceException e) {
            if(backupBundle!=null) {
                str = backupBundle.getString(propertiesNames.get(i));
            }
        }
        str = changeJavaPropertyCounter(str);
        addData(fos, str, true); // localized string as UNICODE
        
    }
}
 
Example #2
Source File: SecuritySupport.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets a resource bundle using the specified base name and locale, and the caller's class loader.
 * @param bundle the base name of the resource bundle, a fully qualified class name
 * @param locale the locale for which a resource bundle is desired
 * @return a resource bundle for the given base name and locale
 */
public static ResourceBundle getResourceBundle(final String bundle, final Locale locale) {
    return AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() {
        public ResourceBundle run() {
            try {
                return PropertyResourceBundle.getBundle(bundle, locale);
            } catch (MissingResourceException e) {
                try {
                    return PropertyResourceBundle.getBundle(bundle, new Locale("en", "US"));
                } catch (MissingResourceException e2) {
                    throw new MissingResourceException(
                            "Could not load any resource bundle by " + bundle, bundle, "");
                }
            }
        }
    });
}
 
Example #3
Source File: SecuritySupport.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets a resource bundle using the specified base name and locale, and the caller's class loader.
 * @param bundle the base name of the resource bundle, a fully qualified class name
 * @param locale the locale for which a resource bundle is desired
 * @return a resource bundle for the given base name and locale
 */
public static ResourceBundle getResourceBundle(final String bundle, final Locale locale) {
    return AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() {
        public ResourceBundle run() {
            try {
                return PropertyResourceBundle.getBundle(bundle, locale);
            } catch (MissingResourceException e) {
                try {
                    return PropertyResourceBundle.getBundle(bundle, new Locale("en", "US"));
                } catch (MissingResourceException e2) {
                    throw new MissingResourceException(
                            "Could not load any resource bundle by " + bundle, bundle, "");
                }
            }
        }
    });
}
 
Example #4
Source File: Bug6204853.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public Bug6204853() {
    String srcDir = System.getProperty("test.src", ".");
    try (FileInputStream fis8859_1 =
             new FileInputStream(new File(srcDir, "Bug6204853.properties"));
         FileInputStream fisUtf8 =
             new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
         InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8"))
    {
        PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);
        PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);

        String[] arrayUtf8 = createKeyValueArray(bundleUtf8);
        String[] array = createKeyValueArray(bundle);

        if (!Arrays.equals(arrayUtf8, array)) {
            throw new RuntimeException("PropertyResourceBundle constructed from a UTF-8 encoded property file is not equal to the one constructed from ISO-8859-1 encoded property file.");
        }
    } catch (FileNotFoundException fnfe) {
        throw new RuntimeException(fnfe);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
 
Example #5
Source File: PropertiesReaderControl.java    From es6draft with MIT License 6 votes vote down vote up
@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload)
        throws IOException {
    if ("java.properties".equals(format)) {
        String bundleName = toBundleName(baseName, locale);
        String resourceName = toResourceName(bundleName, "properties");
        InputStream stream = getInputStream(loader, resourceName, reload);
        if (stream == null) {
            return null;
        }
        try (Reader reader = new InputStreamReader(stream, charset)) {
            return new PropertyResourceBundle(reader);
        }
    }
    throw new IllegalArgumentException("unknown format: " + format);
}
 
Example #6
Source File: Bug6204853.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private final String[] createKeyValueArray(PropertyResourceBundle b) {
    List<String> keyValueList = new ArrayList<String>();
    StringBuilder sb = new StringBuilder();

    for (String key : b.keySet()) {
        sb.setLength(0);
        sb.append(key);
        sb.append(" = ");
        sb.append(b.getString(key));
        keyValueList.add(sb.toString());
    }

    String[] keyValueArray = keyValueList.toArray(new String[0]);
    Arrays.sort(keyValueArray);
    return keyValueArray;
}
 
Example #7
Source File: Bug6204853.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private final String[] createKeyValueArray(PropertyResourceBundle b) {
    List<String> keyValueList = new ArrayList<String>();
    StringBuilder sb = new StringBuilder();

    for (String key : b.keySet()) {
        sb.setLength(0);
        sb.append(key);
        sb.append(" = ");
        sb.append(b.getString(key));
        keyValueList.add(sb.toString());
    }

    String[] keyValueArray = keyValueList.toArray(new String[0]);
    Arrays.sort(keyValueArray);
    return keyValueArray;
}
 
Example #8
Source File: Bug6204853.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private final String[] createKeyValueArray(PropertyResourceBundle b) {
    List<String> keyValueList = new ArrayList<String>();
    StringBuilder sb = new StringBuilder();

    for (String key : b.keySet()) {
        sb.setLength(0);
        sb.append(key);
        sb.append(" = ");
        sb.append(b.getString(key));
        keyValueList.add(sb.toString());
    }

    String[] keyValueArray = keyValueList.toArray(new String[0]);
    Arrays.sort(keyValueArray);
    return keyValueArray;
}
 
Example #9
Source File: AttributesParserFeatureXml.java    From nexus-repository-p2 with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public P2Attributes getAttributesFromBlob(final TempBlob tempBlob, final String extension)
    throws IOException, AttributeParsingException
{
  Builder p2AttributesBuilder = P2Attributes.builder();
  Optional<Document> featureXmlOpt = documentJarExtractor.getSpecificEntity(tempBlob, extension, XML_FILE_NAME);
  Optional<PropertyResourceBundle> propertiesOpt =
      propertyParser.getBundleProperties(tempBlob, extension, FEATURE_PROPERTIES);

  if (featureXmlOpt.isPresent()) {
    Document document = featureXmlOpt.get();
    String pluginId = extractValueFromDocument(XML_PLUGIN_NAME_PATH, document);
    if (pluginId == null) {
      pluginId = extractValueFromDocument(XML_PLUGIN_ID_PATH, document);
    }

    String componentName = normalizeComponentName(propertyParser.extractValueFromProperty(pluginId, propertiesOpt));
    p2AttributesBuilder
        .componentName(componentName)
        .pluginName(
            propertyParser.extractValueFromProperty(extractValueFromDocument(XML_NAME_PATH, document), propertiesOpt))
        .componentVersion(extractValueFromDocument(XML_VERSION_PATH, document));
  }

  return p2AttributesBuilder.build();
}
 
Example #10
Source File: ConfigurationType.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Gets the property resolver for this configuration type used to expand property values within
 * the checkstyle configuration.
 *
 * @param checkConfiguration
 *          the actual check configuration
 * @return the property resolver
 * @throws IOException
 *           error creating the property resolver
 * @throws URISyntaxException
 *           if configuration file URL cannot be resolved
 */
protected PropertyResolver getPropertyResolver(ICheckConfiguration config,
        CheckstyleConfigurationFile configFile) throws IOException, URISyntaxException {

  MultiPropertyResolver multiResolver = new MultiPropertyResolver();
  multiResolver.addPropertyResolver(new ResolvablePropertyResolver(config));

  File f = URIUtil.toFile(configFile.getResolvedConfigFileURL().toURI());
  if (f != null) {
    multiResolver.addPropertyResolver(new StandardPropertyResolver(f.toString()));
  } else {
    multiResolver.addPropertyResolver(
            new StandardPropertyResolver(configFile.getResolvedConfigFileURL().toString()));
  }

  multiResolver.addPropertyResolver(new ClasspathVariableResolver());
  multiResolver.addPropertyResolver(new SystemPropertyResolver());

  if (configFile.getAdditionalPropertiesBundleStream() != null) {
    ResourceBundle bundle = new PropertyResourceBundle(
            configFile.getAdditionalPropertiesBundleStream());
    multiResolver.addPropertyResolver(new ResourceBundlePropertyResolver(bundle));
  }

  return multiResolver;
}
 
Example #11
Source File: Bug6204853.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public Bug6204853() {
    String srcDir = System.getProperty("test.src", ".");
    try (FileInputStream fis8859_1 =
             new FileInputStream(new File(srcDir, "Bug6204853.properties"));
         FileInputStream fisUtf8 =
             new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
         InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8"))
    {
        PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);
        PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);

        String[] arrayUtf8 = createKeyValueArray(bundleUtf8);
        String[] array = createKeyValueArray(bundle);

        if (!Arrays.equals(arrayUtf8, array)) {
            throw new RuntimeException("PropertyResourceBundle constructed from a UTF-8 encoded property file is not equal to the one constructed from ISO-8859-1 encoded property file.");
        }
    } catch (FileNotFoundException fnfe) {
        throw new RuntimeException(fnfe);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
 
Example #12
Source File: Bug6204853.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private final String[] createKeyValueArray(PropertyResourceBundle b) {
    List<String> keyValueList = new ArrayList<String>();
    StringBuilder sb = new StringBuilder();

    for (String key : b.keySet()) {
        sb.setLength(0);
        sb.append(key);
        sb.append(" = ");
        sb.append(b.getString(key));
        keyValueList.add(sb.toString());
    }

    String[] keyValueArray = keyValueList.toArray(new String[0]);
    Arrays.sort(keyValueArray);
    return keyValueArray;
}
 
Example #13
Source File: SecuritySupport.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets a resource bundle using the specified base name and locale, and the caller's class loader.
 * @param bundle the base name of the resource bundle, a fully qualified class name
 * @param locale the locale for which a resource bundle is desired
 * @return a resource bundle for the given base name and locale
 */
public static ResourceBundle getResourceBundle(final String bundle, final Locale locale) {
    return AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() {
        public ResourceBundle run() {
            try {
                return PropertyResourceBundle.getBundle(bundle, locale);
            } catch (MissingResourceException e) {
                try {
                    return PropertyResourceBundle.getBundle(bundle, new Locale("en", "US"));
                } catch (MissingResourceException e2) {
                    throw new MissingResourceException(
                            "Could not load any resource bundle by " + bundle, bundle, "");
                }
            }
        }
    });
}
 
Example #14
Source File: Bug6204853.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public Bug6204853() {
    String srcDir = System.getProperty("test.src", ".");
    try (FileInputStream fis8859_1 =
             new FileInputStream(new File(srcDir, "Bug6204853.properties"));
         FileInputStream fisUtf8 =
             new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
         InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8"))
    {
        PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);
        PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);

        String[] arrayUtf8 = createKeyValueArray(bundleUtf8);
        String[] array = createKeyValueArray(bundle);

        if (!Arrays.equals(arrayUtf8, array)) {
            throw new RuntimeException("PropertyResourceBundle constructed from a UTF-8 encoded property file is not equal to the one constructed from ISO-8859-1 encoded property file.");
        }
    } catch (FileNotFoundException fnfe) {
        throw new RuntimeException(fnfe);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
 
Example #15
Source File: MCRCombinedResourceBundleControl.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload)
    throws IllegalAccessException, InstantiationException, IOException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("New bundle: {}, locale {}", baseName, locale);
    }
    if (locale.equals(Locale.ROOT)) {
        //MCR-1064 fallback should be default language, if property key does not exist
        locale = defaultLocale;
    }
    String bundleName = baseName.substring(baseName.indexOf(':') + 1);
    String filename = CONTROL_HELPER.toBundleName(bundleName, locale) + ".properties";
    try (MCRConfigurationInputStream propertyStream = new MCRConfigurationInputStream(filename)) {
        if (propertyStream.isEmpty()) {
            String className = bundleName + "_" + locale;
            throw new MissingResourceException(
                "Can't find bundle for base name " + baseName + ", locale " + locale, className, "");
        }
        return new PropertyResourceBundle(propertyStream);
    }
}
 
Example #16
Source File: AttributesParserManifest.java    From nexus-repository-p2 with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public P2Attributes getAttributesFromBlob(final TempBlob tempBlob, final String extension)
    throws IOException, AttributeParsingException
{
  Builder p2AttributesBuilder = P2Attributes.builder();
  Optional<Manifest> manifestJarEntity =
      manifestJarExtractor.getSpecificEntity(tempBlob, extension, MANIFEST_FILE_PREFIX);
  if (manifestJarEntity.isPresent()) {
    Attributes mainManifestAttributes = manifestJarEntity.get().getMainAttributes();
    String bundleLocalizationValue = mainManifestAttributes.getValue("Bundle-Localization");
    Optional<PropertyResourceBundle> propertiesOpt =
        propertyParser.getBundleProperties(tempBlob, extension,
            bundleLocalizationValue == null ? BUNDLE_PROPERTIES : bundleLocalizationValue);

    p2AttributesBuilder
        .componentName(normalizeName(propertyParser
            .extractValueFromProperty(mainManifestAttributes.getValue("Bundle-SymbolicName"), propertiesOpt)))
        .pluginName(
            propertyParser.extractValueFromProperty(mainManifestAttributes.getValue("Bundle-Name"), propertiesOpt))
        .componentVersion(
            propertyParser
                .extractValueFromProperty(mainManifestAttributes.getValue("Bundle-Version"), propertiesOpt));
  }

  return p2AttributesBuilder.build();
}
 
Example #17
Source File: Bug6204853.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private final String[] createKeyValueArray(PropertyResourceBundle b) {
    List<String> keyValueList = new ArrayList<String>();
    StringBuilder sb = new StringBuilder();

    for (String key : b.keySet()) {
        sb.setLength(0);
        sb.append(key);
        sb.append(" = ");
        sb.append(b.getString(key));
        keyValueList.add(sb.toString());
    }

    String[] keyValueArray = keyValueList.toArray(new String[0]);
    Arrays.sort(keyValueArray);
    return keyValueArray;
}
 
Example #18
Source File: Bug6204853.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public Bug6204853() {
    String srcDir = System.getProperty("test.src", ".");
    try (FileInputStream fis8859_1 =
             new FileInputStream(new File(srcDir, "Bug6204853.properties"));
         FileInputStream fisUtf8 =
             new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
         InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8"))
    {
        PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);
        PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);

        String[] arrayUtf8 = createKeyValueArray(bundleUtf8);
        String[] array = createKeyValueArray(bundle);

        if (!Arrays.equals(arrayUtf8, array)) {
            throw new RuntimeException("PropertyResourceBundle constructed from a UTF-8 encoded property file is not equal to the one constructed from ISO-8859-1 encoded property file.");
        }
    } catch (FileNotFoundException fnfe) {
        throw new RuntimeException(fnfe);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
 
Example #19
Source File: SecuritySupport.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets a resource bundle using the specified base name and locale, and the caller's class loader.
 * @param bundle the base name of the resource bundle, a fully qualified class name
 * @param locale the locale for which a resource bundle is desired
 * @return a resource bundle for the given base name and locale
 */
public static ResourceBundle getResourceBundle(final String bundle, final Locale locale) {
    return AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() {
        public ResourceBundle run() {
            try {
                return PropertyResourceBundle.getBundle(bundle, locale);
            } catch (MissingResourceException e) {
                try {
                    return PropertyResourceBundle.getBundle(bundle, new Locale("en", "US"));
                } catch (MissingResourceException e2) {
                    throw new MissingResourceException(
                            "Could not load any resource bundle by " + bundle, bundle, "");
                }
            }
        }
    });
}
 
Example #20
Source File: Messages.java    From collect-earth with MIT License 6 votes vote down vote up
/**
 * Utility method to find the labels that have not yet been translated from the English original to another language
 * The output (in the console) are the original english lables that need to be translated and set in the destination language
 * @param toLanguage The language to check against english (so far it can be ES,PT or FR)
 */
private static void printMissingTranslations(String toLanguage){

	PropertyResourceBundle originalEnglishLabels = (PropertyResourceBundle) ResourceBundle.getBundle(Messages.BUNDLE_NAME, Locale.ENGLISH);
	PropertyResourceBundle translatedLabels = (PropertyResourceBundle)  ResourceBundle.getBundle(Messages.BUNDLE_NAME, new Locale(toLanguage));
	
	// Go through the contents of the original English labels and try to find the translation
	// If the translation is not found then print the original to console
	Enumeration<String> keys = originalEnglishLabels.getKeys();
	
	String key = null;
	while( keys.hasMoreElements() ){
		key = keys.nextElement();
		String translatedValue = (String) translatedLabels.handleGetObject(key);
		if( translatedValue == null || translatedValue.length() == 0 ){
			System.out.println( key + "=" + originalEnglishLabels.getString(key) );
		}
	}
	
}
 
Example #21
Source File: Bug6204853.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private final String[] createKeyValueArray(PropertyResourceBundle b) {
    List<String> keyValueList = new ArrayList<String>();
    StringBuilder sb = new StringBuilder();

    for (String key : b.keySet()) {
        sb.setLength(0);
        sb.append(key);
        sb.append(" = ");
        sb.append(b.getString(key));
        keyValueList.add(sb.toString());
    }

    String[] keyValueArray = keyValueList.toArray(new String[0]);
    Arrays.sort(keyValueArray);
    return keyValueArray;
}
 
Example #22
Source File: Bug6204853.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public Bug6204853() {
    String srcDir = System.getProperty("test.src", ".");
    try (FileInputStream fis8859_1 =
             new FileInputStream(new File(srcDir, "Bug6204853.properties"));
         FileInputStream fisUtf8 =
             new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
         InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8"))
    {
        PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);
        PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);

        String[] arrayUtf8 = createKeyValueArray(bundleUtf8);
        String[] array = createKeyValueArray(bundle);

        if (!Arrays.equals(arrayUtf8, array)) {
            throw new RuntimeException("PropertyResourceBundle constructed from a UTF-8 encoded property file is not equal to the one constructed from ISO-8859-1 encoded property file.");
        }
    } catch (FileNotFoundException fnfe) {
        throw new RuntimeException(fnfe);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
 
Example #23
Source File: Bug6204853.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public Bug6204853() {
    String srcDir = System.getProperty("test.src", ".");
    try (FileInputStream fis8859_1 =
             new FileInputStream(new File(srcDir, "Bug6204853.properties"));
         FileInputStream fisUtf8 =
             new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
         InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8"))
    {
        PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);
        PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);

        String[] arrayUtf8 = createKeyValueArray(bundleUtf8);
        String[] array = createKeyValueArray(bundle);

        if (!Arrays.equals(arrayUtf8, array)) {
            throw new RuntimeException("PropertyResourceBundle constructed from a UTF-8 encoded property file is not equal to the one constructed from ISO-8859-1 encoded property file.");
        }
    } catch (FileNotFoundException fnfe) {
        throw new RuntimeException(fnfe);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
 
Example #24
Source File: SecuritySupport.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets a resource bundle using the specified base name and locale, and the caller's class loader.
 * @param bundle the base name of the resource bundle, a fully qualified class name
 * @param locale the locale for which a resource bundle is desired
 * @return a resource bundle for the given base name and locale
 */
public static ResourceBundle getResourceBundle(final String bundle, final Locale locale) {
    return AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() {
        public ResourceBundle run() {
            try {
                return PropertyResourceBundle.getBundle(bundle, locale);
            } catch (MissingResourceException e) {
                try {
                    return PropertyResourceBundle.getBundle(bundle, new Locale("en", "US"));
                } catch (MissingResourceException e2) {
                    throw new MissingResourceException(
                            "Could not load any resource bundle by " + bundle, bundle, "");
                }
            }
        }
    });
}
 
Example #25
Source File: VirtualChestTranslation.java    From VirtualChest with GNU Lesser General Public License v3.0 6 votes vote down vote up
public VirtualChestTranslation(VirtualChestPlugin plugin)
{
    Locale locale = Locale.getDefault();
    AssetManager assets = Sponge.getAssetManager();
    logger = plugin.getLogger();
    try
    {
        Asset asset = assets.getAsset(plugin, "i18n/" + locale.toString() + ".properties").orElse(assets.
                getAsset(plugin, "i18n/en_US.properties").orElseThrow(() -> new IOException(I18N_ERROR)));
        resourceBundle = new PropertyResourceBundle(new InputStreamReader(asset.getUrl().openStream(), Charsets.UTF_8));
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
}
 
Example #26
Source File: Bug6204853.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public Bug6204853() {
    String srcDir = System.getProperty("test.src", ".");
    try (FileInputStream fis8859_1 =
             new FileInputStream(new File(srcDir, "Bug6204853.properties"));
         FileInputStream fisUtf8 =
             new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
         InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8"))
    {
        PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);
        PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);

        String[] arrayUtf8 = createKeyValueArray(bundleUtf8);
        String[] array = createKeyValueArray(bundle);

        if (!Arrays.equals(arrayUtf8, array)) {
            throw new RuntimeException("PropertyResourceBundle constructed from a UTF-8 encoded property file is not equal to the one constructed from ISO-8859-1 encoded property file.");
        }
    } catch (FileNotFoundException fnfe) {
        throw new RuntimeException(fnfe);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
 
Example #27
Source File: Bug6204853.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private final String[] createKeyValueArray(PropertyResourceBundle b) {
    List<String> keyValueList = new ArrayList<String>();
    StringBuilder sb = new StringBuilder();

    for (String key : b.keySet()) {
        sb.setLength(0);
        sb.append(key);
        sb.append(" = ");
        sb.append(b.getString(key));
        keyValueList.add(sb.toString());
    }

    String[] keyValueArray = keyValueList.toArray(new String[0]);
    Arrays.sort(keyValueArray);
    return keyValueArray;
}
 
Example #28
Source File: Resources.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void initLabels() {
	// custom bundle to be able to read the UTF-8 Japanese property file
	String name = "Labels";
	if (Env.INSTANCE.getAppliLanguage() != null) {
		switch (Env.INSTANCE.getAppliLanguage()) {
		case JAPANESE:
			name += "_ja_JP";
			break;
		case FRENCH:
			name += "_fr_FR";
			break;
		case GERMAN:
			name += "_de_DE";
			break;
		default:
			break;
		}
	}
	name += ".properties";
	final InputStream stream = Resources.class.getResourceAsStream(name);
	try {
		LABEL_BUNDLE = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8"));
	} catch (final Exception e) {
		LOGGER.error("Failed to load resource bundle", e);
	}
}
 
Example #29
Source File: Bug6204853.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private final String[] createKeyValueArray(PropertyResourceBundle b) {
    List<String> keyValueList = new ArrayList<String>();
    StringBuilder sb = new StringBuilder();

    for (String key : b.keySet()) {
        sb.setLength(0);
        sb.append(key);
        sb.append(" = ");
        sb.append(b.getString(key));
        keyValueList.add(sb.toString());
    }

    String[] keyValueArray = keyValueList.toArray(new String[0]);
    Arrays.sort(keyValueArray);
    return keyValueArray;
}
 
Example #30
Source File: Bug6204853.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public Bug6204853() {
    String srcDir = System.getProperty("test.src", ".");
    try (FileInputStream fis8859_1 =
             new FileInputStream(new File(srcDir, "Bug6204853.properties"));
         FileInputStream fisUtf8 =
             new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
         InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8"))
    {
        PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);
        PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);

        String[] arrayUtf8 = createKeyValueArray(bundleUtf8);
        String[] array = createKeyValueArray(bundle);

        if (!Arrays.equals(arrayUtf8, array)) {
            throw new RuntimeException("PropertyResourceBundle constructed from a UTF-8 encoded property file is not equal to the one constructed from ISO-8859-1 encoded property file.");
        }
    } catch (FileNotFoundException fnfe) {
        throw new RuntimeException(fnfe);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}