@bokiteam: "Hi All,
          Before optimize the JPG code, here is a branch problem on Sony 
Ericsson's K750i
I don't know why, it seems that very strange, the code will just stop there.
I can't sure which line, but it seems stops! ( stay(stop) in a line until I 
send data from client )
I will find another JSR-82 supported phone, just feel very strange here..
Originally, I want to code as:
polling incoming data, when data stops, I will collect them and decode as 
JPG, but right now, I can't know when it stops... because the code didn't go 
through~~~
 int bytesToRead = in.available();
          if (bytesToRead > 0) {
            // Initialize buffer
            byte[] byteBuffer = new byte[bytesToRead];
            // Read bytes
            nbrOfBytesRead = in.read(byteBuffer);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
the code will not go to next line until I send data from clinet @@
do you have the same experiance ?
Best regards,
Boki. "
    @bokiteam: "Hi Green,
                I want to do polling, I don't know the data length first, I 
want the code can polling data, when there is no more data in a timer time, 
exit and then show that jpg file.
do you mean when I write code as example, and my problem will disappear ?
Best regards,
Boki.
"Roedy Green" <email_address> 
???????:<email_address>
<quote>"
    @bokiteam: "OK, thanks, I will try it :)
Best regards,
Boki.
"Roedy Green" <email_address> 
???????:<email_address>
<quote>"
    @mcpierce: "<quote>
You don't need a delay if you ask for data in discrete packets rather 
than asking for one byte at a time:
byte[] buffer = new byte[4096];
boolean done = false;
while(!done)
{
	int read = istream.read(buffer);
	if(read != -1)
	{/* process the bytes received */}
	else done = true;
}
No blocking, no fiddling with delays between reads, and the thread will 
block on InputStream.read() until data is returned.
Darryl L. Pierce <email_address>
Homepage: <url>
"Bury me next to my wife. Nothing too fancy..." - Ulysses S. Grant"
    @bokiteam: "Very good, it works!
btw, nit-pick, it seems that the max incoming data block/packet is 4096 
bytes, right?
or I have to check that first?
Best regards,
Boki.
"Darryl L. Pierce" <email_address> 
???????:hW28f.10713$<email_address>
<quote>"
    @bokiteam: "I don't know why,
sometimes, it can't work again...
still be blocked again, my final "read " == 22 ( not -1 ), and then be 
blocked.
Does it possible the K750i's problem?
Best regards,
Boki.
"Boki" <email_address> ���g��l��s�D:djru9e$72s$<email_address>
<quote>"
    @bokiteam: "Hi Green,
                I don't know why, it can't work now..
===========================
while ( !done )
{
       gui.repaint();
   bytesToRead = in.available();
   if (bytesToRead > 0  )
   {
        nbrOfBytesRead = in.read(byteBuffer);
        if  ( nbrOfBytesRead == -1 ) done = true ;
      for (count_jpg=0;count_jpg<nbrOfBytesRead;count_jpg++)
      {
       imageData[GUI.ggg+count_jpg]=byteBuffer[count_jpg];
      }
         GUI.ggg+=nbrOfBytesRead;
   }
               else if ( GUI.ggg>0 ) done=true;
         }
========================
The program still be blocked, never exit the while loop even I stop the data 
transfer a while already...
Best regards,
Boki.
"Roedy Green" <email_address> 
???????:<email_address>
<quote>"
    @mcpierce: "<quote>
The code receives at most 4096 bytes *each time* it reads from the input 
stream. There's no limit on the size that it will read, it will just do 
it in discrete packets of 4096 bytes. If there is less than that 
remaining in the input stream, it will read what's remaining and return.
Darryl L. Pierce <email_address>
Homepage: <url>
"Bury me next to my wife. Nothing too fancy..." - Ulysses S. Grant"
    @mcpierce: "<quote>
 >
 > Does it possible the K750i's problem?
The final read() returns 22 because it read 22 bytes from the input 
stream. It seems the handset might not be returning -1 (which it should) 
and is instead blocking waiting for more data when none is available. A 
change to the code like this should get past it, assuming you know the 
total size of the incoming data stream:
int length = connection.getLength();
byte[] buffer = new byte[4096];
boolean done = false;
int totalread = 0;
while(!done && totalread < length)
{
     int read = istream.read(buffer);
     if(read != -1)
     {
	totalread += length;
	/* process the bytes received */
     }
     else done = true;
}
Darryl L. Pierce <email_address>
Homepage: <url>
"Bury me next to my wife. Nothing too fancy..." - Ulysses S. Grant"
    @mcpierce: "<quote>
He's referring to the code I posted in the message to which he was 
replying...
Darryl L. Pierce <email_address>
Homepage: <url>
"Bury me next to my wife. Nothing too fancy..." - Ulysses S. Grant"
    @bokiteam: "Thanks, but I don't know the data length.. because user will send a jpg file 
...
Best regards,
Boki.
"Darryl L. Pierce" <email_address> 
???????:%gn8f.26411$<email_address>
<quote>"
    @bokiteam: "haha....
I suppose that "Got you".equals("Hey, I get your answer") == true. :D
Best regards,
Boki.
"Roedy Green" <email_address> 
???????:<email_address>
<quote>"
{'source': 'USENET', 'other_information': '{"reply_count": 11, "forum_name": "comp.lang.java.programmer.20150110.mbox"}', 'file': 'data/output/usenet-comp.lang.parquet'}