hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Supun Kamburugamuva <supu...@gmail.com>
Subject Re: Clearing the ByteBuffer
Date Wed, 29 Dec 2010 03:47:59 GMT
Thank you all for your quick responses. Now it is working.
ByteBuffer#clear() works.

Thanks,
Supun..

On Tue, Dec 28, 2010 at 11:10 PM, Hiranya Jayathilaka
<hiranya911@gmail.com> wrote:
> On Tue, Dec 28, 2010 at 10:23 PM, Supun Kamburugamuva <supun06@gmail.com>
> 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 <work@vaisberg.de>
> 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: dev-unsubscribe@hc.apache.org
>>>> For additional commands, e-mail: dev-help@hc.apache.org
>>>>
>>>
>>>
>>
>>
>>
>> --
>> Technical Lead, WSO2 Inc
>> http://wso2.org
>> supunk.blogspot.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
>> For additional commands, e-mail: dev-help@hc.apache.org
>>
>>
>
>
>
> --
> Hiranya Jayathilaka
> Senior Software Engineer;
> WSO2 Inc.;  http://wso2.org
> E-mail: hiranya@wso2.com;  Mobile: +94 77 633 3491
> Blog: http://techfeast-hiranya.blogspot.com
>



-- 
Technical Lead, WSO2 Inc
http://wso2.org
supunk.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message