On Tue, Dec 28, 2010 at 10:23 PM, Supun Kamburugamuva <[email protected]>
wrote:
> Is it possible to use the ByteBuffer#clear() method?

Since you are trying to read bytes from the new request into the buffer,
clear method should work. See the explanation given in the javadocs of the
Buffer class [1]:

*clear() makes a buffer ready for a new sequence of channel-read or relative
put operations: It sets the limit to the capacity and the position to zero*

Thanks,
Hiranya

[1] - http://download.oracle.com/javase/1.4.2/docs/api/java/nio/Buffer.html

>
> Thanks,
> Supun..
>
> On Tue, Dec 28, 2010 at 7:25 PM, Alexander Vaysberg <[email protected]>
wrote:
>> you can using flip and compact method for this:
>>
>> ByteBuffer buffer = ByteBuffer.allocate(1024*1024);
>>
>>    int end = 0;
>>
>>    while (end >= 0 || buffer.hasRemaining( )) {
>>
>>      if (end != -1) end = inChannel.read(buffer);
>>
>>        buffer.flip( );
>>
>>        ...
>>
>>        buffer.compact( );
>>
>>    }
>>
>>
>>
>> Am 28.12.2010 13:21, schrieb Supun Kamburugamuva:
>>> I would like to reuse the ByteBuffer that is allocated for a request.
>>> Is it possible to clear the buffer after the decoder/encoder completed
>>> and use the same buffer for another request? I'm using HTTPCore-NIO.
>>>
>>> Thanks,
>>> Supun...
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>>
>>
>>
>
>
>
> --
> Technical Lead, WSO2 Inc
> http://wso2.org
> supunk.blogspot.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>



-- 
Hiranya Jayathilaka
Senior Software Engineer;
WSO2 Inc.;  http://wso2.org
E-mail: [email protected];  Mobile: +94 77 633 3491
Blog: http://techfeast-hiranya.blogspot.com

Reply via email to