Package com.volantis.charset

Examples of com.volantis.charset.BitSetEncoding


    * encoded.
    * @throws Exception A problem
    */
    public void testWriteBitSetEncoding() throws Exception {
        Writer writer = new StringWriter();
        Encoding encoding = new BitSetEncoding("iso-8859-1", 4);
        CharsetEncodingWriter csew =
            new CharsetEncodingWriter(writer, encoding);
        String testString = "\uaaff";
        csew.write(testString);
        String result = writer.toString();
View Full Code Here


    0-128 and supports multibyte characters (>128) which represent chinese
    * symbols.
    */
    public void testWriteChinese() throws Exception {
        Writer writer = new StringWriter();
        Encoding encoding = new BitSetEncoding("GB18030", 2025);
        CharsetEncodingWriter csew =
            new CharsetEncodingWriter(writer, encoding);

        // All of these are valid chinese characters
        char[] chars = new char[] {
            'a','c','c','d','e','f','g','h','i','j','k',
            'A','B','C','D','E','F','G','H','I','J','K',
            '0','1','2','3','4','5','6','7','8','9',
            0xd6b2, 0xbfc3, 0xd6ea, 0xcda9, 0xe9ab,
            0xbcd2, 0xabc7, 0xbec0, 0xd6b7, 0xa9d0};
        csew.write(chars);
        String result = writer.toString();
        char[] out = result.toCharArray();
        assertEquals( chars.length, out.length );
        for( int i = 0; i < chars.length; i++ ){
            if( chars[i] != out[i] ) {
                fail( "Invalid character " + out[i] + " at index " + i );
            }
        }

        // These are not valid chinese characters
        char[] invalidChars = new char[] {
            195,'a', 185,'z', 210,'c', 188,'d', 208,'y', 208,'q'
        };
        writer = new StringWriter();
        csew = new CharsetEncodingWriter(writer, encoding);
        csew.write(invalidChars);
        result = writer.toString();
        assertEquals("Output not as expected.",
            "&#195;a&#185;z&#210;c&#188;d&#208;y&#208;q", result );

        // Finally test some specific characters
        CharacterRepresentable rep;
        rep = encoding.checkCharacter(32654);
        assertEquals( "Character should be representable",
                      true, rep.isRepresentable());

        rep = encoding.checkCharacter(22269);
        assertEquals( "Character should be representable",
                      true, rep.isRepresentable());

        rep = encoding.checkCharacter(19968);
        assertEquals( "Character should be representable",
                      true, rep.isRepresentable());

        rep = encoding.checkCharacter(214);
        assertEquals( "Character should not be representable",
                      true, rep.notRepresentable());

        rep = encoding.checkCharacter(188);
        assertEquals( "Character should not be representable",
                      true, rep.notRepresentable());
    }
View Full Code Here

                      true, rep.notRepresentable());
    }

     public void testWriteCharArrayWithOffset() throws Exception {
        Writer writer = new StringWriter();
        Encoding encoding = new BitSetEncoding("iso-8859-1", 4);
        CharsetEncodingWriter csew =
            new CharsetEncodingWriter(writer, encoding);
        char[] testArr = new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
        String expected = "de";
        csew.write(testArr, 3, 2);
View Full Code Here

TOP

Related Classes of com.volantis.charset.BitSetEncoding

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.