Example usage for java.util PropertyResourceBundle PropertyResourceBundle

List of usage examples for java.util PropertyResourceBundle PropertyResourceBundle

Introduction

In this page you can find the example usage for java.util PropertyResourceBundle PropertyResourceBundle.

Prototype

@SuppressWarnings({ "unchecked", "rawtypes" })
public PropertyResourceBundle(Reader reader) throws IOException 

Source Link

Document

Creates a property resource bundle from a java.io.Reader Reader .

Usage

From source file:com.discovery.darchrow.util.ResourceBundleUtil.java

/**
 * ResourceBundle({@link PropertyResourceBundle}),????(file).
 *
 * @param inputStream/*from   ww  w.  j a  va  2 s . c  o m*/
 *            the input stream
 * @return the resource bundle,may be null
 * @see java.util.PropertyResourceBundle#PropertyResourceBundle(InputStream)
 * @since 1.0.9
 */
public static ResourceBundle getResourceBundle(InputStream inputStream) {
    if (Validator.isNullOrEmpty(inputStream)) {
        throw new IllegalArgumentException("inputStream can't be null/empty!");
    }
    try {
        ResourceBundle resourceBundle = new PropertyResourceBundle(inputStream);
        return resourceBundle;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:com.sunchenbin.store.feilong.core.util.ResourceBundleUtil.java

/**
 * ResourceBundle({@link PropertyResourceBundle}),????(file).
 *
 * @param inputStream//w  w  w.ja va  2  s. c o m
 *            the input stream
 * @return the resource bundle,may be null
 * @see java.util.PropertyResourceBundle#PropertyResourceBundle(InputStream)
 * @since 1.0.9
 */
public static ResourceBundle getResourceBundle(InputStream inputStream) {
    if (Validator.isNullOrEmpty(inputStream)) {
        throw new IllegalArgumentException("inputStream can't be null/empty!");
    }
    try {
        return new PropertyResourceBundle(inputStream);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.acmsl.commons.BundleI14able.java

/**
 * Third attempt to retrieve the bundle.
 * @param bundleName the bundle name./*from w  w  w.j ava 2  s.  com*/
 * @param locale the locale.
 * @return the bundle.
 * @throws MissingResourceException if the resource is missing.
 */
@Nullable
protected final ResourceBundle thirdTry(@NotNull final String bundleName, @NotNull final Locale locale)
        throws MissingResourceException {
    @Nullable
    ResourceBundle result = null;

    Throwable exceptionThrown = null;

    MissingResourceException exceptionToThrow = null;

    try {
        // treating bundle name as the first part of the file.
        result = new PropertyResourceBundle(new FileInputStream(bundleName + "_" + locale.getLanguage() + "_"
                + locale.getCountry() + "_" + locale.getVariant() + Literals.PROPERTIES));
    } catch (final FileNotFoundException firstFileNotFoundException) {
        exceptionThrown = firstFileNotFoundException;
    } catch (final IOException firstIOException) {
        exceptionThrown = firstIOException;
    } finally {
        if (exceptionThrown != null) {
            try {
                result = fourthTry(bundleName, locale);
            } catch (final MissingResourceException missingResource) {
                exceptionToThrow = missingResource;
            }
        }
    }

    if (exceptionToThrow != null) {
        throw exceptionToThrow;
    }

    return result;
}

From source file:com.discovery.darchrow.util.ResourceBundleUtil.java

/**
 *  resource bundle({@link PropertyResourceBundle}),????(file).
 *
 * @param reader//from  ww  w .  ja  va  2s  .  c  om
 *            the reader
 * @return the resource bundle
 * @see java.util.PropertyResourceBundle#PropertyResourceBundle(Reader)
 * @since 1.0.9
 */
public static ResourceBundle getResourceBundle(Reader reader) {
    if (Validator.isNullOrEmpty(reader)) {
        throw new IllegalArgumentException("reader can't be null/empty!");
    }
    try {
        ResourceBundle resourceBundle = new PropertyResourceBundle(reader);
        return resourceBundle;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:com.sunchenbin.store.feilong.core.util.ResourceBundleUtil.java

/**
 *  resource bundle({@link PropertyResourceBundle}),????(file).
 *
 * @param reader/*from ww w  .  j  a  va2 s. com*/
 *            the reader
 * @return the resource bundle
 * @see java.util.PropertyResourceBundle#PropertyResourceBundle(Reader)
 * @since 1.0.9
 */
public static ResourceBundle getResourceBundle(Reader reader) {
    if (Validator.isNullOrEmpty(reader)) {
        throw new IllegalArgumentException("reader can't be null/empty!");
    }
    try {
        return new PropertyResourceBundle(reader);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.acmsl.commons.BundleI14able.java

/**
 * Fourth attempt to retrieve the bundle.
 * @param bundleName the bundle name./*from w ww.ja v a 2 s .c  om*/
 * @param locale the locale.
 * @return the bundle.
 * @throws MissingResourceException if the resource is missing.
 */
@Nullable
protected final ResourceBundle fourthTry(@NotNull final String bundleName, @NotNull final Locale locale)
        throws MissingResourceException {
    @Nullable
    ResourceBundle result = null;

    Throwable exceptionThrown = null;

    MissingResourceException exceptionToThrow = null;

    try {
        result = new PropertyResourceBundle(new FileInputStream(
                bundleName + "_" + locale.getLanguage() + "_ " + locale.getCountry() + Literals.PROPERTIES));
    } catch (final FileNotFoundException secondFileNotFoundException) {
        exceptionThrown = secondFileNotFoundException;
    } catch (final IOException secondIOException) {
        exceptionThrown = secondIOException;
    } finally {
        if (exceptionThrown != null) {
            try {
                result = fifthTry(bundleName, locale);
            } catch (final MissingResourceException missingResource) {
                exceptionToThrow = missingResource;
            }
        }
    }

    if (exceptionToThrow != null) {
        throw exceptionToThrow;
    }

    return result;
}

From source file:org.acmsl.commons.BundleI14able.java

/**
 * Fifth attempt to retrieve the bundle.
 * @param bundleName the bundle name.//from w  ww .j  a  va2 s .  c  om
 * @param locale the locale.
 * @return the bundle.
 * @throws MissingResourceException if the resource is missing.
 */
@Nullable
protected final ResourceBundle fifthTry(@NotNull final String bundleName, @NotNull final Locale locale)
        throws MissingResourceException {
    @Nullable
    ResourceBundle result = null;

    Throwable exceptionThrown = null;

    MissingResourceException exceptionToThrow = null;

    try {
        result = new PropertyResourceBundle(
                new FileInputStream(bundleName + "_" + locale.getLanguage() + Literals.PROPERTIES));
    } catch (final FileNotFoundException thirdFileNotFoundException) {
        exceptionThrown = thirdFileNotFoundException;
    } catch (final IOException thirdIOException) {
        exceptionThrown = thirdIOException;
    } finally {
        if (exceptionThrown != null) {
            try {
                result = sixthTry(bundleName);
            } catch (final MissingResourceException missingResource) {
                exceptionToThrow = missingResource;
            }
        }
    }

    if (exceptionToThrow != null) {
        throw exceptionToThrow;
    }

    return result;
}

From source file:org.acmsl.commons.BundleI14able.java

/**
 * Sixth attempt to retrieve the bundle.
 * @param bundleName the bundle name.// www.  j  av  a  2 s  . c  o  m
 * @return the bundle.
 * @throws MissingResourceException if the resource is missing.
 */
@Nullable
protected final ResourceBundle sixthTry(@NotNull final String bundleName) throws MissingResourceException {
    @Nullable
    ResourceBundle result = null;

    Throwable exceptionThrown = null;

    MissingResourceException exceptionToThrow = null;

    try {
        result = new PropertyResourceBundle(new FileInputStream(bundleName + Literals.PROPERTIES));
    } catch (final FileNotFoundException thirdFileNotFoundException) {
        exceptionThrown = thirdFileNotFoundException;
    } catch (final IOException thirdIOException) {
        exceptionThrown = thirdIOException;
    } finally {
        if (exceptionThrown != null) {
            try {
                result = seventhTry(bundleName);
            } catch (final MissingResourceException missingResource) {
                exceptionToThrow = missingResource;
            }
        }
    }

    if (exceptionToThrow != null) {
        throw exceptionToThrow;
    }

    return result;
}

From source file:org.acmsl.commons.BundleI14able.java

/**
 * Seventh attempt to retrieve the bundle.
 * @param bundleName the bundle name./* w  ww .j  a  v a 2  s.  c o m*/
 * @return the bundle.
 * @throws MissingResourceException if the resource is missing.
 */
@Nullable
protected final ResourceBundle seventhTry(@NotNull final String bundleName) throws MissingResourceException {
    @Nullable
    ResourceBundle result = null;

    Throwable exceptionThrown = null;

    MissingResourceException exceptionToThrow = null;

    try {
        // last attempt.
        result = new PropertyResourceBundle(new FileInputStream(bundleName));
    } catch (final FileNotFoundException thirdFileNotFoundException) {
        exceptionThrown = thirdFileNotFoundException;
    } catch (final IOException thirdIOException) {
        exceptionThrown = thirdIOException;
    } finally {
        if (exceptionThrown != null) {
            exceptionToThrow = new MissingResourceException(exceptionThrown.getLocalizedMessage(),
                    exceptionThrown.getClass().getName(), "(none)");
        }
    }

    if (exceptionToThrow != null) {
        throw exceptionToThrow;
    }

    return result;
}

From source file:com.feilong.core.util.ResourceBundleUtil.java

/**
 * ResourceBundle({@link PropertyResourceBundle}),????(file).
 *
 * @param inputStream//from  www . j  a  v  a 2 s  . c  o  m
 *            the input stream
 * @return  <code>inputStream</code> null, {@link NullPointerException}<br>
 *         ? {@link java.util.PropertyResourceBundle#PropertyResourceBundle(InputStream)}
 * @see java.util.PropertyResourceBundle#PropertyResourceBundle(InputStream)
 * @since 1.0.9
 */
public static ResourceBundle getResourceBundle(InputStream inputStream) {
    Validate.notNull(inputStream, "inputStream can't be null!");
    try {
        return new PropertyResourceBundle(inputStream);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}