Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

my program be blocked by inputstream ><~~

Thread view: 
Boki - 28 Oct 2005 03:48 GMT
====================
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.