类java.util.PropertyResourceBundle源码实例Demo

下面列出了怎么用java.util.PropertyResourceBundle的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: collect-earth   文件: Messages.java
/**
 * 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) );
		}
	}
	
}
 
源代码2 项目: jdk1.8-source-analysis   文件: SecuritySupport.java
/**
 * 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, "");
                }
            }
        }
    });
}
 
源代码3 项目: jdk8u-dev-jdk   文件: Bug6204853.java
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);
    }
}
 
源代码4 项目: dragonwell8_jdk   文件: Bug6204853.java
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);
    }
}
 
源代码5 项目: dragonwell8_jdk   文件: Bug6204853.java
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;
}
 
源代码6 项目: es6draft   文件: PropertiesReaderControl.java
@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);
}
 
源代码7 项目: TencentKona-8   文件: Bug6204853.java
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;
}
 
源代码8 项目: TencentKona-8   文件: SecuritySupport.java
/**
 * 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, "");
                }
            }
        }
    });
}
 
源代码9 项目: native-obfuscator   文件: Bug6204853.java
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);
    }
}
 
源代码10 项目: native-obfuscator   文件: Bug6204853.java
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;
}
 
源代码11 项目: jdk8u60   文件: Bug6204853.java
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);
    }
}
 
源代码12 项目: jdk8u60   文件: Bug6204853.java
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;
}
 
源代码13 项目: jdk8u60   文件: SecuritySupport.java
/**
 * 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, "");
                }
            }
        }
    });
}
 
源代码14 项目: JDKSourceCode1.8   文件: SecuritySupport.java
/**
 * 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, "");
                }
            }
        }
    });
}
 
@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();
}
 
@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();
}
 
源代码17 项目: eclipse-cs   文件: ConfigurationType.java
/**
 * 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;
}
 
源代码18 项目: openjdk-jdk8u   文件: Bug6204853.java
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);
    }
}
 
源代码19 项目: openjdk-jdk8u   文件: Bug6204853.java
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;
}
 
源代码20 项目: openjdk-jdk8u   文件: SecuritySupport.java
/**
 * 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, "");
                }
            }
        }
    });
}
 
源代码21 项目: netbeans   文件: ExeLauncher.java
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
        
    }
}
 
源代码22 项目: openjdk-jdk8u-backup   文件: Bug6204853.java
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);
    }
}
 
源代码23 项目: openjdk-jdk8u-backup   文件: SecuritySupport.java
/**
 * 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, "");
                }
            }
        }
    });
}
 
源代码24 项目: VirtualChest   文件: VirtualChestTranslation.java
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);
    }
}
 
源代码25 项目: openjdk-jdk9   文件: Bug6204853.java
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);
    }
}
 
源代码26 项目: openjdk-jdk9   文件: Bug6204853.java
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;
}
 
源代码27 项目: jdk8u-jdk   文件: Bug6204853.java
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);
    }
}
 
源代码28 项目: jdk8u-jdk   文件: Bug6204853.java
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;
}
 
源代码29 项目: openvisualtraceroute   文件: Resources.java
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);
	}
}
 
源代码30 项目: hottub   文件: Bug6204853.java
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);
    }
}
 
 类所在包
 同包方法