

package gov.va.med.cds.socket.server.handler;


import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;

import java.nio.ByteBuffer;


public class MinaMllpProtocolEncoder
    extends
        ProtocolEncoderAdapter
{
    public void encode( IoSession session, Object message, ProtocolEncoderOutput out )
        throws Exception
    {

        IoBuffer ioBuffer = IoBuffer.allocate( ( ( ByteBuffer )message ).limit() );

        ioBuffer.setAutoExpand( true );

        ioBuffer.put( ( ( ByteBuffer )message ).array() );

        ioBuffer.position( ( ( ByteBuffer )message ).limit() );

        ioBuffer.slice();

        ioBuffer.flip();

        out.write( ioBuffer );

    }
}
