Package java.nio.charset

Examples of java.nio.charset.CharsetEncoder


        Assert.assertEquals(0, buf.get(1));
    }

    public void testGetPrefixedString() throws Exception {
        ByteBuffer buf = ByteBuffer.allocate(16);
        CharsetEncoder encoder;
        CharsetDecoder decoder;
        encoder = Charset.forName("ISO-8859-1").newEncoder();
        decoder = Charset.forName("ISO-8859-1").newDecoder();

        buf.putShort((short) 3);
View Full Code Here


        buf.clear();
        Assert.assertEquals("ABC", buf.getPrefixedString(decoder));
    }

    public void testPutPrefixedString() throws Exception {
        CharsetEncoder encoder;
        ByteBuffer buf = ByteBuffer.allocate(16);
        buf.fillAndReset(buf.remaining());
        encoder = Charset.forName("ISO-8859-1").newEncoder();

        // Without autoExpand
View Full Code Here

        Assert.assertEquals('4', buf.get(15));
        Assert.assertEquals('5', buf.get(16));
    }

    public void testPutPrefixedStringWithPrefixLength() throws Exception {
        CharsetEncoder encoder = Charset.forName("ISO-8859-1").newEncoder();
        ByteBuffer buf = ByteBuffer.allocate(16).sweep().setAutoExpand(true);

        buf.putPrefixedString("A", 1, encoder);
        Assert.assertEquals(2, buf.position());
        Assert.assertEquals(1, buf.get(0));
View Full Code Here

        Assert.assertEquals(1, buf.get(3));
        Assert.assertEquals('A', buf.get(4));
    }

    public void testPutPrefixedStringWithPadding() throws Exception {
        CharsetEncoder encoder = Charset.forName("ISO-8859-1").newEncoder();
        ByteBuffer buf = ByteBuffer.allocate(16).sweep().setAutoExpand(true);

        buf.putPrefixedString("A", 1, 2, (byte) 32, encoder);
        Assert.assertEquals(3, buf.position());
        Assert.assertEquals(2, buf.get(0));
View Full Code Here

                ByteBuffer buffer = ByteBuffer.allocate(1);
                buffer.setAutoExpand(true);

                Charset charset = Charset.forName("UTF-8");

                CharsetEncoder encoder = charset.newEncoder();

                for (int i = 0; i < 5; i++) {
                    try {
                        buffer.putString("\u89d2", encoder);
                    } catch (CharacterCodingException e) {
View Full Code Here

    public void testNormalDecode() throws Exception {
        TextLineDecoder decoder = new TextLineDecoder(Charset.forName("UTF-8"),
                LineDelimiter.WINDOWS);

        CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
        IoSession session = new DummySession();
        TestDecoderOutput out = new TestDecoderOutput();
        ByteBuffer in = ByteBuffer.allocate(16);

        // Test one decode and one output
View Full Code Here

    public void testAutoDecode() throws Exception {
        TextLineDecoder decoder = new TextLineDecoder(Charset.forName("UTF-8"),
                LineDelimiter.AUTO);

        CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
        IoSession session = new DummySession();
        TestDecoderOutput out = new TestDecoderOutput();
        ByteBuffer in = ByteBuffer.allocate(16);

        // Test one decode and one output
View Full Code Here

                } else if (message instanceof Exception) {
                    // we cant handle exceptions
                    throw (Exception) message;
                }

                CharsetEncoder encoder = (CharsetEncoder)session.getAttribute(CHARSET_ENCODER);
                if (encoder == null) {
                    encoder = charset.newEncoder();
                    session.setAttribute(CHARSET_ENCODER, encoder);
                }
View Full Code Here

        Assert.assertEquals( 4, buf.limit() );
    }
   
    public void testPutString() throws Exception
    {
        CharsetEncoder encoder;
        ByteBuffer buf = ByteBuffer.allocate( 16 );
        encoder = Charset.forName( "ISO-8859-1" ).newEncoder();
       
        buf.putString( "ABC", encoder );
        Assert.assertEquals( 3, buf.position() );
View Full Code Here

   * Class under test for void OutputStreamWriter(OutputStream, String)
   */
  public void testOutputStreamWriterOutputStreamCharsetEncoder()
      throws IOException {
    Charset cs = Charset.forName("ascii");
    CharsetEncoder enc = cs.newEncoder();
    try {
      writer = new OutputStreamWriter(null, enc);
      fail();
    } catch (NullPointerException e) {
    }
View Full Code Here

TOP

Related Classes of java.nio.charset.CharsetEncoder

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.