Package java.nio.charset

Examples of java.nio.charset.CharsetEncoder


    }
    }

    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


    }

    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

        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( '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( '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
                    {
View Full Code Here

    {
        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

    {
        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

        final int linger = this.sconfig.getSoLinger();
        if (linger >= 0) {
            socket.setSoLinger(linger > 0, linger);
        }
        CharsetDecoder chardecoder = null;
        CharsetEncoder charencoder = null;
        final Charset charset = this.cconfig.getCharset();
        final CodingErrorAction malformedInputAction = this.cconfig.getMalformedInputAction() != null ?
                this.cconfig.getMalformedInputAction() : CodingErrorAction.REPORT;
        final CodingErrorAction unmappableInputAction = this.cconfig.getUnmappableInputAction() != null ?
                this.cconfig.getUnmappableInputAction() : CodingErrorAction.REPORT;
        if (charset != null) {
            chardecoder = charset.newDecoder();
            chardecoder.onMalformedInput(malformedInputAction);
            chardecoder.onUnmappableCharacter(unmappableInputAction);
            charencoder = charset.newEncoder();
            charencoder.onMalformedInput(malformedInputAction);
            charencoder.onUnmappableCharacter(unmappableInputAction);
        }
        final DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(
                this.cconfig.getBufferSize(),
                this.cconfig.getFragmentSizeHint(),
                chardecoder, charencoder,
View Full Code Here

    m_delimiter = LineDelimiter.UNIX;
  }

  public void encode(IoSession session, Object message, ProtocolEncoderOutput out)
      throws Exception {
    CharsetEncoder encoder = (CharsetEncoder) session.getAttribute(ENCODER);
        if (encoder == null) {
            encoder = m_charset.newEncoder();
            session.setAttribute(ENCODER, encoder);
        }
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.