Is there a reliable way to read from a tcp/ip stream that will identify when there is nothing left on the stream to read?
 
We have been using the following code
 
public int readData(StringBuffer buf) throws IOException
{
   byte[] InBuf = new byte[2048];
   int totBytes = 0;
   int bytesRead = 0;
 
   //
   // Sanity check
   if ( buf != null ) {
      buf.delete(0, buf.length());
 
      Arrays.fill(InBuf, (byte)0);
      bytesRead = m_In.read(InBuf, 0, 2048);
 
      while ( bytesRead != -1 ) {
         totBytes += bytesRead;
         buf.append(new String(InBuf, 0, bytesRead));
         Arrays.fill(InBuf, (byte)0);
         bytesRead = m_In.read(InBuf, 0, 2048);
      }
   }
 
   return totBytes;
}
 
This has worked great until recently.  We have been sending over larger xml documents than we had before and now this code does not work.  Specifically, read does not return -1 even though there is nothing left on the stream to read.  This causes the code to block.  If we use m_In.available(), that returns a bogus 0 and we only get a partial document.  Besides, the available() function is not reliable based on the java documentation.
 
There seems to be some size threshold here where these fail.
 
I've checked on the web, but almost exclusivly I've seen code similar to the above.  Does anyone have any suggestions?
 
Thanks
 
Jeff Fisher
---
You are currently subscribed to jdjlist as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
http://www.sys-con.com/fusetalk To unsubscribe from all mailing lists, click:
http://sys-con.com/[EMAIL PROTECTED]

Reply via email to