Code example for CharBuffer

Methods: get, limit

0
    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"));