Java 8 PropertyResourceBundle - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 PropertyResourceBundle class.

This code example shows how to use the following methods:
 
	private SafeResourceBundle bundle;
 
	@Before 
	public void setUp() throws Exception {
		PropertyResourceBundle delegate = new PropertyResourceBundle(new ByteArrayInputStream("abc=def".getBytes()));
		bundle = new SafeResourceBundle(delegate);
	} 
 
	@Test
	public void shouldReturnDelegateValueWhenKeyExists() throws Exception {
		String result = bundle.getString("abc");
		assertThat(result, is("def"));
	} 
 
	@Test
	public void shouldReturnKeyBetweenQuestionMarksWhenKeyDoesntExist() throws Exception {
		String result = bundle.getString("any key");
		assertThat(result, is("???any key???"));
	} 
6
CodeRank
This code example shows how to use the following methods:
            stream = loader.getResourceAsStream(resourceName);
        } 
        if (stream != null) {
            try { 
                // Only this line is changed to make it to read properties files as UTF-8. 
                bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8"));
            } finally { 
                stream.close();
            } 
        } 
        return bundle;
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getString, keySet
		assertEquals("one", prb.getString("p1"));
		assertEquals("iso-8859-1", prb.getString("charset"));
 
		propertiesStream = new ByteArrayInputStream("p1=one\ncharset=UTF-8"
				.getBytes("UTF-8"));
		prb = new PropertyResourceBundle(propertiesStream);
		assertEquals(2, prb.keySet().size());
		assertEquals("UTF-8", prb.getString("charset"));
 
		try { 
			new PropertyResourceBundle((InputStream) null);
			fail("Should throw NullPointerException");
		} catch (NullPointerException e) {
			// expected 
		} 
	} 
 
    /** 
	 * @throws IOException 
	 * @tests {@link java.util.PropertyResourceBundle#PropertyResourceBundle(java.io.Reader)} 
5
CodeRank
This code example shows how to use the following methods:
 
		ResourceBundle resourceBundle = resourceBundles.get(languageId);
 
		if (resourceBundle == null) {
			try { 
				resourceBundle = new PropertyResourceBundle(
					new UnsyncByteArrayInputStream(new byte[0])); 
 
				resourceBundles.put(languageId, resourceBundle);
			} 
			catch (IOException ioe) {
				_log.error(ioe);
			} 
		} 
 
		return resourceBundle;
	} 
 
	private ResourceBundle _getResourceBundle(
		String servletContextName, String languageId) {
5
CodeRank
This code example shows how to use the following methods:
 
	private SafeResourceBundle bundle;
 
	@Before 
	public void setUp() throws Exception {
		PropertyResourceBundle delegate = new PropertyResourceBundle(new ByteArrayInputStream("abc=def".getBytes()));
		bundle = new SafeResourceBundle(delegate);
	} 
 
	@Test
	public void shouldReturnDelegateValueWhenKeyExists() throws Exception {
		String result = bundle.getString("abc");
		assertThat(result, is("def"));
	} 
 
	@Test
	public void shouldReturnKeyBetweenQuestionMarksWhenKeyDoesntExist() throws Exception {
		String result = bundle.getString("any key");
		assertThat(result, is("???any key???"));
	} 
5
CodeRank
This code example shows how to use the following methods:getString
    public ResourceBundleWebServerConfig() throws IOException {
 
        File file = new File(System.getProperty("basedir"), "ResourceBundleWebServerConfig.properties");
        // how do you get this working in intellij, maven and eclipse ? 
        if (file.exists()) {
            ResourceBundle bundle = new PropertyResourceBundle(new FileInputStream(file));
            host = bundle.getString("host");
            port = Integer.parseInt(bundle.getString("port"));
        } 
    } 
 
    public String getHost() {
        return host;
    } 
 
    public int getPort() { 
        return port;
    } 
 
} 
5
CodeRank
This code example shows how to use the following methods:getString
         */ 
  
        public static String ConvertedString(String str,String file_properties){ 
		String string_converted=new String();
		try{	 
			PropertyResourceBundle bundle=new PropertyResourceBundle(new FileInputStream(file_properties));
			String mystr=bundle.getString(str);
	                byte[] utf8 = mystr.getBytes("UTF-8");
               	        string_converted = new String(utf8, "UTF-8");
                                                         
		}	 
		catch(Exception e)
		{ 
			string_converted="Error in property file variable not Match with property file :-"+e; 
		} 
		return string_converted;
	} 
	public static String ConvertedMonth(int monthNumber, String propertyFile)
	{ 
			/** 
5
CodeRank
This code example shows how to use the following methods:
        if(is==null) {
            throw new AgoravaException("Property file : " +bundleName+".properties, not found");
        } 
             
            try { 
                return new PropertyResourceBundle(is);
            } catch (IOException e) {
                throw new AgoravaException("Didn't found Agorava properties file",e);
            } 
        } 
     
    /** 
     * {@inheritDoc} <p/> 
     * This implementation will build the {@link OAuthAppSettings} from a {@link ResourceBundle} 
     * <p/> 
     * It'll first try to load all binding (mandatory) fields from the bundle by looking for the key prefix.fieldName (or 
     * fieldName if prefix is empty) 
     * <p/> 
     * In a second time it'll check if optional fields are present in the bundle (with the same key construction) and load 
     * them if they are. 
4
CodeRank
This code example shows how to use the following methods:getString
     */ 
    public static String getMessage(String key,Object[] params){
        String message=null;
 
        if(messages!=null){
            String tmplt = messages.getString(key);
            if(tmplt!=null){
                message = MessageFormat.format(tmplt,params);
            } 
        } 
        return message;
    } 
} 
4
CodeRank
This code example shows how to use the following methods:
	 */ 
	public PropertyResourceBundle getProperties(){
		if (this.properties == null){
			try { 
				this.properties = new PropertyResourceBundle(
						FileLocator.openStream(this.getBundle(),
								new Path(PROPERTIES),false));
			} catch (IOException e) {
				//log error 
				e.getMessage();
			} 
		} 
		return this.properties;
	}	   
	 
	/** 
	 * Get String from the plugin.properties file 
	 *  
	 * @param var Variable name wanted as a String e.g. "ToolName.assembler.llvm" 
	 * @return String e.g. LLVM assembler 
4
CodeRank
See Code Examples for Java 8 PropertyResourceBundle Methods: