Package de.netseeker.ejoe.io

Examples of de.netseeker.ejoe.io.ByteBufferInputStream


     * @throws IOException
     * @throws UnsupportedOperationException
     */
    private Object read( SerializeAdapter adapter ) throws IOException
    {
        ByteBufferInputStream in = null;
        ByteBuffer dataBuf = null;
        Object result = null;
        DataChannel dataChannel = DataChannel.getInstance( this._senderInfo );

        try
        {
            if ( !this._senderInfo.hasWaitingBuffer() )
            {
                int length = dataChannel.readHeader( this._senderInfo, EJConstants.EJOE_CONNECTION_TIMEOUT );

                // maybe the DataChannel signals that it has already read
                // partial data
                if ( this._senderInfo.hasWaitingBuffer() )
                {
                    dataBuf = this._senderInfo.getWaitingBuffer();
                }
                else
                {
                    dataBuf = ByteBufferAllocator.allocate( length );
                }

                log.log( Level.FINE, "Going to read client request with length: " + length );
            }
            else
            {
                dataBuf = this._senderInfo.getWaitingBuffer();
            }

            if ( dataBuf.hasRemaining() )
            {
                DataChannel.nonBlockingRead( this._senderInfo.getChannel(), dataBuf );
            }

            dataBuf.flip();

            if ( log.isLoggable( Level.FINE ) )
            {
                byte[] tmp = new byte[dataBuf.remaining()];
                dataBuf.get( tmp );
                dataBuf.position( 0 );
                log.log( Level.FINE, "Client request read:\n" + new String( tmp, EJConstants.EJOE_DEFAULT_CHARSET ) );
            }

            if ( dataBuf.hasRemaining() )
            {
                try
                {
                    // usual way: deserialize using a adapter
                    if ( !this._senderInfo.isDirect() )
                    {
                        dataBuf = dataChannel.decode( dataBuf );
                        in = new ByteBufferInputStream( dataBuf );
                        result = deserialize( adapter, in );
                    }
                    // direct mode: don't deserialize, just copy and return the read
                    // ByteBuffer
                    else
View Full Code Here


    private Object receive( ConnectionHeader clientInfo ) throws IOException
    {
        Object result = null;
        DataChannel dataChannel = DataChannel.getInstance( _serverInfo );
        ByteBuffer dataBuf = clientInfo.getWaitingBuffer();
        ByteBufferInputStream in = null;

        try
        {
            if ( dataBuf == null )
            {
                int length = dataChannel.readHeader( _serverInfo, this._connectionTimeout );
                // server signals a null result?
                if ( length == 0 )
                {
                    return null;
                }

                // maybe the DataChannel signals that it has already read
                // partial data
                if ( _serverInfo.hasWaitingBuffer() )
                {
                    dataBuf = _serverInfo.getWaitingBuffer();
                }
                else
                {
                    dataBuf = ByteBufferAllocator.allocate( length );
                }

                log.log( Level.FINE, "Going to read server response with length: " + length );
            }

            if ( dataBuf.hasRemaining() )
            {
                DataChannel.nonBlockingRead( _channel, dataBuf );
            }

            dataBuf.flip();

            log
                    .log( Level.FINE,
                          "Response read. Now calling (de)serialize adapter to convert response back to object." );

            if ( dataBuf.hasRemaining() )
            {
                try
                {
                    // usual way: deserialize using a adapter
                    if ( !clientInfo.isDirect() && !clientInfo.isMixed() )
                    {
                        in = new ByteBufferInputStream( dataBuf );
                        result = deserialize( in, clientInfo );
                    }
                    // direct or mixed mode: don't deserialize, just copy and return
                    // the read ByteBuffer
                    else
View Full Code Here

TOP

Related Classes of de.netseeker.ejoe.io.ByteBufferInputStream

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.