* @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