Package com.volantis.charset

Examples of com.volantis.charset.CharsetEncodingWriter


    * @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();
        assertEquals("Character not encoded", "꫿", result);
        // Now a character than can be represented - 'A'
        testString = "\u0041";
        writer = new StringWriter();
        csew = new CharsetEncodingWriter(writer, encoding);
        csew.write(testString);
        result = writer.toString();
        assertEquals("Character erroneously encoded", "A", result);
    }
View Full Code Here


    * @throws Exception A problem
    */
    public void testWriteNoEncoding() throws Exception {
        Writer writer = new StringWriter();
        Encoding encoding = new NoEncoding("utf8", 106);
        CharsetEncodingWriter csew = new CharsetEncodingWriter(writer, encoding);
        // Test char 43775 - should not be encoded.
        String testString = "\uaaff";
        csew.write(testString);
        String result = writer.toString();
        assertEquals("Character not encoded", "\uaaff", result);
    }
View Full Code Here

    * 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
View Full Code Here

    }

     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);
        String result = writer.toString();
        assertEquals("Characters incorrectly written", expected, result);
     }
View Full Code Here

                // Retrieve the output writer from the page context, convert it
                // to a CharsetEncodingWriter and filter up any errors
                public Writer getRealWriter() {
                    try {
                        return new CharsetEncodingWriter(
                                envContext.getResponseWriter(), encoding);
                    } catch (MarinerContextException mce) {
                        throw new RuntimeException(mce);
                    }
                }
View Full Code Here

                                pageContext.getCharsetEncoding();
                        if (charsetEncoding == null) {
                            throw new RuntimeException(
                                "No charset found, unable to generate page");
                        }
                        return new CharsetEncodingWriter(
                            writer, charsetEncoding);
                    }
                },
                requestContext, bodyContext);
            // This must be done here otherwise the content may not get
View Full Code Here

TOP

Related Classes of com.volantis.charset.CharsetEncodingWriter

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.