j2me: reading long streams of data

D

dutone

when reading from a socket, you could encounter a very long stream
(i.e. an http connection opened to a 1 page GNU manual). How is one to
deal with such conditions in j2me. It seems to me that this could be a
downfall to any program that opens a socket on a handheld device and
reads freely. Aside from imposing a hard limit and catch()'in -and
then possibly freeing- memory, how could you handle this
reasonably??????
 
D

Darryl L. Pierce

dutone said:
when reading from a socket, you could encounter a very long stream
(i.e. an http connection opened to a 1 page GNU manual). How is one to
deal with such conditions in j2me. It seems to me that this could be a
downfall to any program that opens a socket on a handheld device and
reads freely. Aside from imposing a hard limit and catch()'in -and
then possibly freeing- memory, how could you handle this
reasonably??????

You don't know how long the data is that you're receiving? Or are you asking
about the mechanics of just reading a lot of data from a server? If the
latter, just download it in discrete packets like so:

InputStream istream;
byte[] buffer = new byte[4096];
boolean done = false;

while(!done)
{
int read = istrea.read(buffer);

if(read != -1)
{
done = true;
}
else
{
// store the bytes you just read
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top