Search in sources :

Example 51 with PropertyResourceBundle

use of java.util.PropertyResourceBundle in project j2objc by google.

the class PropertyResourceBundleTest method test_ConstructorLjava_io_Reader.

/**
 * @throws IOException
 * {@link java.util.PropertyResourceBundle#PropertyResourceBundle(java.io.Reader)}
 * @since 1.6
 */
@SuppressWarnings("nls")
public void test_ConstructorLjava_io_Reader() throws IOException {
    Charset charset = Charset.forName("ISO-8859-1");
    String content = "p1=one\nfeature=good_feature";
    CharBuffer cbuffer = charset.decode(ByteBuffer.wrap(content.getBytes("ISO-8859-1")));
    char[] chars = new char[cbuffer.limit()];
    cbuffer.get(chars);
    prb = new PropertyResourceBundle(new CharArrayReader(chars));
    assertEquals(2, prb.keySet().size());
    assertEquals("one", prb.getString("p1"));
    assertEquals("good_feature", prb.getString("feature"));
    charset = Charset.forName("UTF-8");
    cbuffer = charset.decode(ByteBuffer.wrap(content.getBytes("UTF-8")));
    chars = new char[cbuffer.limit()];
    cbuffer.get(chars);
    prb = new PropertyResourceBundle(new CharArrayReader(chars));
    assertEquals(2, prb.keySet().size());
    assertEquals("one", prb.getString("p1"));
    assertEquals("good_feature", prb.getString("feature"));
    try {
        new PropertyResourceBundle((Reader) null);
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) CharBuffer(java.nio.CharBuffer) Charset(java.nio.charset.Charset) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 52 with PropertyResourceBundle

use of java.util.PropertyResourceBundle in project CitizensAPI by CitizensDev.

the class Translator method getDefaultResourceBundle.

private static ResourceBundle getDefaultResourceBundle(File resourceDirectory, String fileName) {
    if (Translator.defaultBundle != null)
        return Translator.defaultBundle;
    resourceDirectory.mkdirs();
    File bundleFile = new File(resourceDirectory, fileName);
    if (!bundleFile.exists()) {
        try {
            bundleFile.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    Translator.populateDefaults(bundleFile);
    FileInputStream stream = null;
    try {
        stream = new FileInputStream(bundleFile);
        Translator.defaultBundle = new PropertyResourceBundle(stream);
    } catch (Exception e) {
        e.printStackTrace();
        Translator.defaultBundle = Translator.getFallbackResourceBundle();
    } finally {
        Closeables.closeQuietly(stream);
    }
    return Translator.defaultBundle;
}
Also used : IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) MalformedURLException(java.net.MalformedURLException) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 53 with PropertyResourceBundle

use of java.util.PropertyResourceBundle in project jadx by skylot.

the class NLS method load.

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);
    }
    LANG_LOCALES_MAP.put(locale, bundle);
}
Also used : InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) IOException(java.io.IOException) URL(java.net.URL) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 54 with PropertyResourceBundle

use of java.util.PropertyResourceBundle in project dbeaver by serge-rider.

the class SQLTemplateStore method readIncludedTemplates.

private void readIncludedTemplates(String contributorId, Collection<TemplatePersistenceData> templates, String file, String translations) throws IOException {
    if (file != null) {
        Bundle plugin = Platform.getBundle(contributorId);
        URL url = FileLocator.find(plugin, Path.fromOSString(file), null);
        if (url != null) {
            ResourceBundle bundle = null;
            if (translations != null) {
                URL bundleURL = FileLocator.find(plugin, Path.fromOSString(translations), null);
                if (bundleURL != null) {
                    InputStream bundleStream = bundleURL.openStream();
                    try {
                        bundle = new PropertyResourceBundle(bundleStream);
                    } finally {
                        ContentUtils.close(bundleStream);
                    }
                }
            }
            InputStream stream = new BufferedInputStream(url.openStream());
            try {
                TemplateReaderWriter reader = new TemplateReaderWriter();
                TemplatePersistenceData[] datas = reader.read(stream, bundle);
                for (TemplatePersistenceData data : datas) {
                    if (data.isCustom()) {
                        if (data.getId() == null)
                            log.error("No template id specified");
                        else
                            log.error("Template " + data.getTemplate().getName() + " deleted");
                    } else if (validateTemplate(data.getTemplate())) {
                        templates.add(data);
                    }
                }
            } finally {
                ContentUtils.close(stream);
            }
        }
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) ResourceBundle(java.util.ResourceBundle) Bundle(org.osgi.framework.Bundle) PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle) PropertyResourceBundle(java.util.PropertyResourceBundle) TemplateReaderWriter(org.eclipse.jface.text.templates.persistence.TemplateReaderWriter) URL(java.net.URL) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 55 with PropertyResourceBundle

use of java.util.PropertyResourceBundle in project dbeaver by dbeaver.

the class SQLTemplateStore method readIncludedTemplates.

private void readIncludedTemplates(String contributorId, Collection<TemplatePersistenceData> templates, String file, String translations) throws IOException {
    if (file != null) {
        Bundle plugin = Platform.getBundle(contributorId);
        URL url = FileLocator.find(plugin, Path.fromOSString(file), null);
        if (url != null) {
            ResourceBundle bundle = null;
            if (translations != null) {
                URL bundleURL = FileLocator.find(plugin, Path.fromOSString(translations), null);
                if (bundleURL != null) {
                    InputStream bundleStream = bundleURL.openStream();
                    try {
                        bundle = new PropertyResourceBundle(bundleStream);
                    } finally {
                        ContentUtils.close(bundleStream);
                    }
                }
            }
            InputStream stream = new BufferedInputStream(url.openStream());
            try {
                TemplateReaderWriter reader = new TemplateReaderWriter();
                TemplatePersistenceData[] datas = reader.read(stream, bundle);
                for (TemplatePersistenceData data : datas) {
                    if (data.isCustom()) {
                        if (data.getId() == null)
                            log.error("No template id specified");
                        else
                            log.error("Template " + data.getTemplate().getName() + " deleted");
                    } else if (validateTemplate(data.getTemplate())) {
                        templates.add(data);
                    }
                }
            } finally {
                ContentUtils.close(stream);
            }
        }
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) ResourceBundle(java.util.ResourceBundle) Bundle(org.osgi.framework.Bundle) PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle) PropertyResourceBundle(java.util.PropertyResourceBundle) TemplateReaderWriter(org.eclipse.jface.text.templates.persistence.TemplateReaderWriter) URL(java.net.URL) PropertyResourceBundle(java.util.PropertyResourceBundle)

Aggregations

PropertyResourceBundle (java.util.PropertyResourceBundle)71 InputStream (java.io.InputStream)35 ResourceBundle (java.util.ResourceBundle)33 IOException (java.io.IOException)30 URL (java.net.URL)24 InputStreamReader (java.io.InputStreamReader)23 FileInputStream (java.io.FileInputStream)15 URLConnection (java.net.URLConnection)14 MissingResourceException (java.util.MissingResourceException)13 File (java.io.File)12 FileNotFoundException (java.io.FileNotFoundException)8 Locale (java.util.Locale)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 HashMap (java.util.HashMap)5 MalformedURLException (java.net.MalformedURLException)4 Bundle (org.osgi.framework.Bundle)4 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 TemplatePersistenceData (org.eclipse.jface.text.templates.persistence.TemplatePersistenceData)3 TemplateReaderWriter (org.eclipse.jface.text.templates.persistence.TemplateReaderWriter)3