For Programmers: Free Programming Magazines  


Home > Archive > Java Help > November 2005 > how to erase data from bytebuffer?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to erase data from bytebuffer?
Gerben

2005-11-23, 9:57 pm

Dear all,

I'm writing a program in which I'm using a bytebuffer which I want to
reuse in stead of recreating it several times. The buffer has to be
empty before I'm using it again. The Java API doesn't provide a method
(at least I couldn't find it) for erasing data from the buffer. Can
anyone give me some suggestions about how I can make this work?

Thankxx

Gerben
NullBock

2005-11-23, 9:57 pm

What's wrong with ByteBuffer#clear() ??

Walter Gildersleeve
________________________________________
____________
http://linkfrog.net
URL Shortening
Free and easy, small and green.

Thomas Hawtin

2005-11-23, 9:57 pm

Gerben wrote:
>
> I'm writing a program in which I'm using a bytebuffer which I want to
> reuse in stead of recreating it several times. The buffer has to be
> empty before I'm using it again. The Java API doesn't provide a method
> (at least I couldn't find it) for erasing data from the buffer. Can
> anyone give me some suggestions about how I can make this work?


Buffer.clear is the method. See "Clearing, flipping, and rewinding" in
the java.nio.Buffer class description. I'm sure there is a better
description of the magic sequences you need for common operations somewhere.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
Knute Johnson

2005-11-23, 9:57 pm

Gerben wrote:
> Dear all,
>
> I'm writing a program in which I'm using a bytebuffer which I want to
> reuse in stead of recreating it several times. The buffer has to be
> empty before I'm using it again. The Java API doesn't provide a method
> (at least I couldn't find it) for erasing data from the buffer. Can
> anyone give me some suggestions about how I can make this work?
>
> Thankxx
>
> Gerben


Look at Buffer.clear().

--

Knute Johnson
email s/nospam/knute/
Roedy Green

2005-11-23, 9:57 pm

On Wed, 23 Nov 2005 21:30:04 +0100, Gerben <invalid_mail@yahoo.com>
wrote, quoted or indirectly quoted someone who said :

>I'm writing a program in which I'm using a bytebuffer which I want to
>reuse in stead of recreating it several times. The buffer has to be
>empty before I'm using it again. The Java API doesn't provide a method
>(at least I couldn't find it) for erasing data from the buffer. Can
>anyone give me some suggestions about how I can make this work?


presumably you meant java.nio.ByteBuffer.

You could use put(int index, byte b) in a loop.

if hasArray() returns true you can zap
array()[i] in a loop
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com