====================
while ( !done )
{
gui.repaint()
int count_jpg=0;
int bytesToRead = in.available();
if (bytesToRead > 0)
{
nbrOfBytesRead = in.read(byteBuffer);
if (nbrOfBytesRead!=-1)
{
for (count_jpg=0;count_jpg<nbrOfBytesRead;count_jpg++)
{
imageData[GUI.ggg+count_jpg]=byteBuffer[count_jpg];
}
GUI.ggg+=nbrOfBytesRead;
}
else
done=true;
}
}
=================
It seems that the program can't exit the while loop even my file already
send completely.
I see the nbrOfBytesRead is 22 ( not -1 ), and the screen didn't be refresh
again.
It seems that the program be blocked, am I right?
Is that a K750i's bug or my wrong implementation?
Thank you very much for your help/support.
Best regards,
Boki.
Rogan Dawes - 28 Oct 2005 08:35 GMT
> ====================
> while ( !done )
[quoted text clipped - 34 lines]
> Best regards,
> Boki.
int got;
int buff=new byte[1024];
while ((got=in.read(buff))>0) {
// do whatever you want with the bytes [0..got-1]
}
is the standard paradigm for reading from an inputstream.
The reason your program in not exiting is that once it has read all the
bytes in the stream, in.available() returns 0, which means that it will
never get to in.read() returning -1, and your logic will never set done=true
Polling in.available() is pretty much useless in this case. Don't do it ;-)
You might also want to look at System.arrayCopy()
Rogan
bokiteam@ms21.hinet.net - 31 Oct 2005 15:15 GMT
thanks, I will back when I got the result : )
Best regards,
Boki.